# rust_claw **Repository Path**: toptemp/rustclaw ## Basic Information - **Project Name**: rust_claw - **Description**: No description available - **Primary Language**: Rust - **License**: MPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-04-03 - **Last Updated**: 2026-04-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 1. 配置 Ollama 环境变量(Windows PowerShell) ### 1.1. 安装 Rust 工具链 ### 方法 1:使用 rustup(推荐) 1. 访问 https://rustup.rs/ 2. 下载 `rustup-init.exe` 3. 运行安装程序,按照提示完成安装 ```powershell ... 1) Quick install via the Visual Studio Community installer (free for individuals, academic uses, and open source). 2) Manually install the prerequisites (for enterprise and advanced users). 3) Don't install the prerequisites (if you're targeting the GNU ABI). ``` 选择1->直接点安装vc++ ### 1.2. 设置环境变量(当前会话) ```powershell # 设置模型 $env:MODEL = "qwen3:8b" # 设置 Ollama 服务地址 $env:OLLAMA_BASE_URL = "http://localhost:11434/v1" # 验证设置 Write-Host "MODEL: $env:MODEL" Write-Host "OLLAMA_BASE_URL: $env:OLLAMA_BASE_URL" ``` ### 1.3. 永久设置环境变量 ```powershell # 用户级永久环境变量 [System.Environment]::SetEnvironmentVariable("MODEL", "qwen3:8b", "User") [System.Environment]::SetEnvironmentVariable("OLLAMA_BASE_URL", "http://localhost:11434/v1", "User") # 系统级永久环境变量(需要管理员权限) # [System.Environment]::SetEnvironmentVariable("MODEL", "qwen3:8b", "Machine") # [System.Environment]::SetEnvironmentVariable("OLLAMA_BASE_URL", "http://localhost:11434/v1", "Machine") ``` ## 2. 测试 Ollama 服务连接 ### 2.1. 检查 Ollama 服务是否运行 ```powershell # 启动 Ollama 服务(如果未运行) Start-Process ollama serve # 等待几秒钟让服务启动 Start-Sleep -Seconds 5 # 测试连接 Invoke-RestMethod -Uri "http://localhost:11434/api/tags" -Method Get ``` ### 2.2. 验证 qwen3:8b 模型 ```powershell # 查看已安装的模型 ollama list # 预期输出应包含 qwen3:8b # 如果没有,下载模型: ollama pull qwen3:8b ``` ## 3. 编译和测试 Claw Code Rust 项目 ### 3.1. 进入项目目录 ```powershell cd d:/ai-lab/claw-code-rust/rust ``` ### 3.2. 编译所有 crate ```powershell # 清理之前的编译 cargo clean # 编译所有 crate cargo build # 编译特定 crate cargo build --package api cargo build --package tools cargo build --package runtime ``` ### 3.3. 运行测试 ```powershell # 运行所有测试 cargo test # 运行特定 crate 的测试 cargo test --package api ``` ### 3.4. 运行示例程序 ```powershell # 运行 Ollama 测试示例 cargo run --example ollama-test # 注意:需要先设置正确的环境变量 ``` ## 4. 常见问题解决 ### 问题 1:cargo 命令未找到 ```powershell # 解决方案 1:重新安装 Rust winget install --id Rustlang.Rustup # 解决方案 2:手动添加到 PATH $rustPath = "C:\Users\$env:USERNAME\.cargo\bin" if (Test-Path $rustPath) { $env:Path += ";$rustPath" } ``` ### 问题 2:Ollama 连接失败 ```powershell # 检查 Ollama 服务 Get-Process ollama -ErrorAction SilentlyContinue # 如果没有运行,启动它 Start-Process ollama serve Start-Sleep -Seconds 10 # 等待服务完全启动 # 测试连接 try { Invoke-WebRequest -Uri "http://localhost:11434/" -ErrorAction Stop Write-Host "✅ Ollama 服务正常" -ForegroundColor Green } catch { Write-Host "❌ Ollama 服务异常" -ForegroundColor Red } ``` ### 问题 3:编译错误 ```powershell # 清理并重新编译 cargo clean cargo update cargo build --verbose # 如果缺少依赖 cargo build --package api --features "ollama" ``` ### 问题 4:权限不足 ```powershell # 以管理员身份运行 PowerShell Start-Process PowerShell -Verb RunAs # 然后运行命令 cd d:/ai-lab/claw-code-rust/rust cargo build ``` ## 5. 快速开始命令总结 ### 一次性设置命令 ```powershell # 1. 设置环境变量 $env:MODEL = "qwen3:8b" $env:OLLAMA_BASE_URL = "http://localhost:11434/v1" # 2. 进入项目目录 cd d:/ai-lab/claw-code-rust/rust # 3. 编译项目 cargo build # 4. 运行测试 cargo test --package api # 5. 验证配置 Write-Host "配置完成!" -ForegroundColor Green Write-Host "模型: $env:MODEL" -ForegroundColor Cyan Write-Host "服务地址: $env:OLLAMA_BASE_URL" -ForegroundColor Cyan ``` ## 6. 高级配置 ### 6.1. 创建项目配置文件 `.claw.json` ```json { "model": "qwen3:8b", "permissionMode": "readOnly", "env": { "OLLAMA_BASE_URL": "http://localhost:11434/v1" }, "hooks": { "PreToolUse": ["validate-ollama-connection"] } } ``` ### 6.2. 创建用户配置文件 `~/.claw/settings.json` ```json { "model": "qwen3:8b", "defaultWorkspace": "d:/ai-lab/claw-code-rust", "providers": { "ollama": { "baseUrl": "http://localhost:11434/v1", "apiKey": "" } } } ``` 按照以上步骤,您应该能够: 1. ✅ 安装和配置 Rust 工具链 2. ✅ 设置 Ollama 环境变量 3. ✅ 编译 Claw Code Rust 项目 4. ✅ 测试 Ollama 集成