openclaw配置本地模型(ollama)

29 阅读3分钟

wins10 使用ollama工具下载本地模型qwen3:1.7b ,在wsl(ubuntu)中安装 openclaw,在配置openclaw模型时找不到ollama下载的qwen3:1.7b的模型,应该怎么解决使得在配置openclaw时能够选中本地下载的模型,请从专业角度给出详细的解决方案和步骤

问题分析: Ollama 在 Windows 10 上安装的模型存储在 Windows 文件系统中,而 WSL (Ubuntu) 默认无法直接访问这些模型文件。要解决这个问题,需要让 WSL 能够访问 Windows 文件系统中的 Ollama 模型目录。

解决方案和步骤:

  1. 确定 Ollama 模型在 Windows 中的存储位置:

    • Ollama 在 Windows 上默认将模型存储在:C:\Users[你的用户名].ollama\models

    • 可以通过以下命令确认:

      bash
       复制 插入 运行
      # 在 PowerShell 或 CMD 中执行
      echo %USERPROFILE%.ollama\models
      
  2. 在 WSL 中访问 Windows 文件系统:

    • WSL 可以通过 /mnt/c/ 路径访问 Windows 的 C 盘
    • Ollama 模型在 WSL 中的路径应该是:/mnt/c/Users/[你的用户名]/.ollama/models
  3. 在 WSL 中创建符号链接,将 Ollama 模型目录链接到 OpenClaw 可以访问的位置:

    bash
     复制 插入 运行
    # 在 WSL Ubuntu 中执行
    # 创建 OpenClaw 模型目录(如果不存在)
    mkdir -p ~/.openclaw/models
    
    # 创建符号链接
    ln -s /mnt/c/Users/[你的用户名]/.ollama/models ~/.openclaw/models/ollama
    
  4. 配置 OpenClaw 使用 Ollama 模型:

    • 打开 OpenClaw 配置文件(通常在 ~/.openclaw/config.yaml 或类似位置)

    • 添加或修改模型路径配置:

      yaml
       复制 插入 新文件
      models:
        - name: qwen3:1.7b
          path: ~/.openclaw/models/ollama/qwen3:1.7b
          provider: ollama
      
  5. 验证配置是否正确:

    bash
     复制 插入 运行
    # 在 WSL 中执行
    ls -la ~/.openclaw/models/ollama
    # 应该能看到 qwen3:1.7b 模型文件
    
    # 测试 OpenClaw 是否能识别模型
    openclaw list models
    
  6. 如果上述方法不工作,可以尝试以下替代方案:

    方案 A:直接在 WSL 中安装 Ollama

    bash
     复制 插入 运行
    # 在 WSL Ubuntu 中执行
    curl -fsSL https://ollama.com/install.sh | sh
    # 然后下载模型
    ollama pull qwen3:1.7b
    

    方案 B:将 Windows 上的 Ollama 模型复制到 WSL

    bash
     复制 插入 运行
    # 在 WSL Ubuntu 中执行
    mkdir -p ~/.ollama/models
    cp -r /mnt/c/Users/[你的用户名]/.ollama/models/* ~/.ollama/models/
    
  7. 确保 OpenClaw 有足够的权限访问模型文件:

    bash
     复制 插入 运行
    # 在 WSL 中执行
    chmod -R 755 ~/.openclaw/models/ollama
    
  8. 如果使用的是 WSL 2,可能需要配置 WSL 访问 Windows 文件系统的性能优化:

    • 在 Windows 用户目录下创建 .wslconfig 文件(如果不存在)

    • 添加以下内容:

      ini
       复制 插入 新文件
      [wsl2]
      # 启用 WSL 2 的性能优化
      memory=4GB
      processors=2
      swap=2GB
      localhostForwarding=true
      
  9. 重启 WSL 以应用更改:

    bash
     复制 插入 运行
    # 在 Windows PowerShell 或 CMD 中执行
    wsl --shutdown
    # 然后重新打开 WSL Ubuntu
    
  10. 最后,重新启动 OpenClaw 并检查是否能识别模型:

    bash
     复制 插入 运行
    # 在 WSL 中执行
    openclaw restart
    openclaw list models
    

通过以上步骤,应该能够解决 OpenClaw 无法识别 Windows 上 Ollama 下载的模型的问题。关键在于正确建立 WSL 和 Windows 文件系统之间的连接,并确保 OpenClaw 能够访问到模型文件。