diff --git a/README_VSCode_Setup.md b/README_VSCode_Setup.md new file mode 100644 index 0000000..579e59a --- /dev/null +++ b/README_VSCode_Setup.md @@ -0,0 +1,28 @@ +# VS Code 轻量化部署指南(Windows 11 优化) + +目的:在 Windows 11 + VS Code 中以最小改动支持 Mano-P 的快速验证(优先云端模式,支持本地模式预配置)。 + +先决条件: + +- Windows 11 +- 已安装 VS Code +- 推荐安装扩展:在 `extensions.json` 中已列出(Python, Pylance, PowerShell, GitLens)。 +- Python 3.10+ 可执行(推荐通过官方安装器) + +快速步骤: + +1. 在 VS Code 中打开工作区:`C:\Users\aa142\Mano-P` +2. 打开命令面板(Ctrl+Shift+P)→ 选择 `Tasks: Run Task` → 运行 `Setup Python venv (Robust)`。 +3. 安装完成后,运行 `Run Mano-P (cloud mode)` 来尝试云端执行示例任务。 +4. 若要尝试本地模式,请先把量化模型放到 `models\` 下,然后运行 `Run Mano-P (local mode)`。 + +脚本说明: + +- `scripts/setup_venv_robust.ps1`:更可靠地检测 Python 并创建 `.venv`,安装最小依赖。 +- `scripts/run_cloud_mode.ps1`:尝试多种方式调用 `mano-cua`(全局 / venv / python3)并运行云端任务。 +- `scripts/run_local_mode.ps1`:检测模型并尝试以本地模式运行(需模型及本地 CLI 支持)。 + +常见问题: + +- 如果 `mano-cua` 未安装,建议使用仓库或 Homebrew(macOS)提供的安装方式,或在虚拟环境中安装相应 Python 包。 +- 本地模式需要量化模型文件与可能的本地后端(llama.cpp/ggml 或 PyTorch),该部分需按 README 中的本地模型说明处理。 diff --git a/scripts/run_cloud_mode.ps1 b/scripts/run_cloud_mode.ps1 new file mode 100644 index 0000000..cb58b40 --- /dev/null +++ b/scripts/run_cloud_mode.ps1 @@ -0,0 +1,37 @@ +param( + [string]$Prompt = "打开浏览器并搜索 Python", + [string]$ExtraArgs = "" +) + +Write-Host "[mano-p run] 尝试以云端模式运行示例任务(兼容多种环境)..." + +# 激活虚拟环境(优先) +if (Test-Path ".venv\Scripts\Activate.ps1") { + Write-Host "激活本地虚拟环境..." + . .\.venv\Scripts\Activate.ps1 +} + +# 检查 mano-cua 可执行 +$manoCmd = Get-Command mano-cua -ErrorAction SilentlyContinue +if ($manoCmd) { + Write-Host "检测到 'mano-cua' 可用,执行云端示例任务:" + mano-cua run "$Prompt" $ExtraArgs + exit $LASTEXITCODE +} + +# 尝试 Python 模块方式 +if (Test-Path ".venv\Scripts\python.exe") { + Write-Host "尝试使用虚拟环境中的 Python 模块调用 mano_cua..." + & .\.venv\Scripts\python.exe -m mano_cua run "$Prompt" $ExtraArgs + if ($LASTEXITCODE -eq 0) { exit 0 } +} + +# 尝试系统 Python3 +$py3 = Get-Command python3 -ErrorAction SilentlyContinue +if ($py3) { + Write-Host "尝试使用系统 python3 -m mano_cua 调用..." + & python3 -m mano_cua run "$Prompt" $ExtraArgs + if ($LASTEXITCODE -eq 0) { exit 0 } +} + +Write-Warning "未检测到 mano-cua 命令或 mano_cua Python 模块。请先运行 'Setup Python venv (Robust)' 或按 README 指示安装 CLI/依赖。" diff --git a/scripts/run_local_mode.ps1 b/scripts/run_local_mode.ps1 new file mode 100644 index 0000000..0d45f78 --- /dev/null +++ b/scripts/run_local_mode.ps1 @@ -0,0 +1,30 @@ +param( + [string]$ModelPath = "models\\mano-4b-quantized.gguf", + [string]$Prompt = "打开浏览器并搜索 Python" +) + +Write-Host "[mano-p run-local] 本地模式运行准备(Windows)..." + +# 激活 venv +if (Test-Path ".venv\Scripts\Activate.ps1") { . .\.venv\Scripts\Activate.ps1 } + +# 检查模型文件是否存在 +if (-not (Test-Path $ModelPath)) { + Write-Warning "模型文件未找到: $ModelPath 。本地模式需要已下载且量化的模型(GGUF/ggml)。请将模型放在项目的 models 目录下或使用云端模式。" +} + +# 优先尝试检测 mano-cua 本地 CLI +$manoCmd = Get-Command mano-cua -ErrorAction SilentlyContinue +if ($manoCmd) { + Write-Host "使用检测到的 mano-cua 执行本地模式:" + mano-cua run "$Prompt" --local --model $ModelPath + exit $LASTEXITCODE +} + +Write-Host "尝试通过 Python 模块调用本地模式(若已安装)..." +if (Test-Path ".venv\Scripts\python.exe") { + & .\.venv\Scripts\python.exe -m mano_cua run "$Prompt" --local --model $ModelPath + exit $LASTEXITCODE +} + +Write-Warning "未找到可用的 mano-cua。本地模式可能不可用。可使用云端模式或先安装 CLI/模型。" diff --git a/scripts/setup_venv.ps1 b/scripts/setup_venv.ps1 new file mode 100644 index 0000000..853bf46 --- /dev/null +++ b/scripts/setup_venv.ps1 @@ -0,0 +1,31 @@ +param() + +Write-Host "[mano-p setup] 检查 Python 可用性..." +$py = Get-Command python -ErrorAction SilentlyContinue +if (-not $py) { + Write-Error "未找到 'python' 命令,请先在系统安装 Python 并确保已添加到 PATH。" + exit 1 +} + +if (-not (Test-Path -Path ".\.venv")) { + Write-Host "正在创建虚拟环境:.venv" + python -m venv .venv +} else { + Write-Host ".venv 已存在,跳过创建。" +} + +Write-Host "激活虚拟环境并安装最小依赖(若有 requirements.txt)..." +$activate = Join-Path -Path (Get-Location) -ChildPath ".venv\Scripts\Activate.ps1" +if (Test-Path $activate) { + & $activate + if (Test-Path "requirements.txt") { + Write-Host "找到 requirements.txt,开始安装..." + pip install -r requirements.txt + } else { + Write-Host "未找到 requirements.txt,跳过依赖安装。" + } + Write-Host "虚拟环境准备完成。要在当前 PowerShell 会话激活,请运行:`. .\.venv\Scripts\Activate.ps1`" +} else { + Write-Error "无法找到虚拟环境激活脚本:$activate" + exit 1 +} diff --git a/scripts/setup_venv_robust.ps1 b/scripts/setup_venv_robust.ps1 new file mode 100644 index 0000000..85b2ed7 --- /dev/null +++ b/scripts/setup_venv_robust.ps1 @@ -0,0 +1,56 @@ +param( + [string]$PythonExe = "python" +) + +Write-Host "[mano-p setup-robust] Starting environment checks and venv creation..." + +function Find-Python { + param([string]$exe) + $cmd = Get-Command $exe -ErrorAction SilentlyContinue + if ($cmd) { return $cmd.Source } + return $null +} + +$pyPath = Find-Python -exe $PythonExe +if (-not $pyPath) { + Write-Host "尝试查找 'python3'..." + $pyPath = Find-Python -exe "python3" +} +if (-not $pyPath) { + Write-Host "尝试查找 'py' 启动器..." + $pyLauncher = Get-Command py -ErrorAction SilentlyContinue + if ($pyLauncher) { $pyPath = "$($pyLauncher.Source) -3" } +} + +if (-not $pyPath) { + Write-Error "Could not find a usable Python executable. Please install Python 3.10+ and ensure it is on PATH." + exit 1 +} + +Write-Host "Using Python executable: $pyPath" + +if (-not (Test-Path -Path ".\.venv")) { + Write-Host "Creating virtual environment .venv ..." + & $pyPath -m venv .venv + if ($LASTEXITCODE -ne 0) { Write-Error "Failed to create virtual environment (exit $LASTEXITCODE)."; exit 1 } +} else { Write-Host ".venv already exists; skipping creation." } + +$activate = Join-Path -Path (Get-Location) -ChildPath ".venv\Scripts\Activate.ps1" +if (-not (Test-Path $activate)) { + Write-Error "Activation script not found: $activate" + exit 1 +} + +Write-Host "Activating virtual environment and upgrading pip..." +. $activate +python -m pip install --upgrade pip wheel setuptools + +if (Test-Path "requirements.txt") { + Write-Host "Installing dependencies from requirements.txt..." + pip install -r requirements.txt +} else { + Write-Host "No requirements.txt found; installing minimal recommended dependency 'requests'..." + pip install requests +} + +Write-Host 'Environment ready. To activate in current session run: `. .\.venv\Scripts\Activate.ps1`'