本地ollama运行openclaw教程
·
安装ollma并配置模型
下载OllamaSetup.exe文件并安装
下载node.js稳定版本并安装
下载git并安装
去魔塔社区下载模型,比如qwen3.5-9b版,链接如下:
https://modelscope.cn/models/unsloth/Qwen3.5-9B-GGUF
下载好模型文件后,在gguf文件同文件夹下创建Modelfile文件,并在里面写:
FROM ./Qwen3.5-9B-IQ4_NL.gguf
# 设置上下文窗口 (根据你的内存调整,27B模型建议不要太大)
# 如果你有 32GB 内存,可以设为 16384 或 32768
# 如果只有 16GB 内存,建议设为 8192 或更低,防止爆内存
PARAMETER num_ctx 16384
TEMPLATE """
{{- $lastUserIdx := -1 -}}
{{- range $idx, $msg := .Messages -}}
{{- if eq $msg.Role "user" }}{{ $lastUserIdx = $idx }}{{ end -}}
{{- end }}
{{- if or .System .Tools }}<|im_start|>system
{{ if .System }}
{{ .System }}
{{- end }}
{{- if .Tools }}
# Tools
You may call one or more functions to assist with the user query.
You are provided with function signatures within <tools></tools> XML tags:
<tools>
{{- range .Tools }}
{"type": "function", "function": {{ .Function }}}
{{- end }}
</tools>
For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
<tool_call>
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call>
{{- end -}}
<|im_end|>
{{ end }}
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 -}}
{{- if eq .Role "user" }}<|im_start|>user
{{ .Content }}
{{- if and $.IsThinkSet (eq $i $lastUserIdx) }}
{{- if $.Think -}}
{{- " "}}/think
{{- else -}}
{{- " "}}/no_think
{{- end -}}
{{- end }}<|im_end|>
{{ else if eq .Role "assistant" }}<|im_start|>assistant
{{ if (and $.IsThinkSet (and .Thinking (or $last (gt $i $lastUserIdx)))) -}}
<think>{{ .Thinking }}</think>
{{ end -}}
{{ if .Content }}{{ .Content }}
{{- else if .ToolCalls }}<tool_call>
{{ range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}
{{ end }}</tool_call>
{{- end }}{{ if not $last }}<|im_end|>
{{ end }}
{{- else if eq .Role "tool" }}<|im_start|>user
<tool_response>
{{ .Content }}
</tool_response><|im_end|>
{{ end }}
{{- if and (ne .Role "assistant") $last }}<|im_start|>assistant
{{ if and $.IsThinkSet (not $.Think) -}}
<think>
</think>
{{ end -}}
{{ end }}
{{- end }}"""
PARAMETER repeat_penalty 1
PARAMETER stop <|im_start|>
PARAMETER stop <|im_end|>
PARAMETER temperature 0.7
PARAMETER top_k 20
PARAMETER top_p 0.95
保存后,运行如下命令创建模型:
ollama create qwen3.5-9b-nl -f ./Modelfile
然后在ollama可视化界面中测试模型,运行起来即可。
安装openclaw
使用ollama一键安装:
ollama launch openclaw
使用本地指定模型启动openclaw命令:
ollama launch openclaw --model qwen3.5-9b-nl
若需要切换模型命令,在对话窗口中输入/model,直接选择切换就行。
关闭openclaw后,如果需要启动,启动命令:
openclaw gateway start
如果需要在cli中对话则执行:
openclaw tui
常见问题
- 如果openclaw报错如下内容,则说明本地ollama模型不支持tool调用
run error: Ollama API error 400: {"error":"registry.ollama.ai/library/qwen3.5-9b-nl:latest does not support tools"}
则重新在ollama中配置模型,修改Modelfile文件内容,加上工具调用的配置:
FROM "D:\model\gguf\qwen3\0.6\Qwen3-0.6B-Q8_0.gguf"
TEMPLATE """
{{- $lastUserIdx := -1 -}}
{{- range $idx, $msg := .Messages -}}
{{- if eq $msg.Role "user" }}{{ $lastUserIdx = $idx }}{{ end -}}
{{- end }}
{{- if or .System .Tools }}<|im_start|>system
{{ if .System }}
{{ .System }}
{{- end }}
{{- if .Tools }}
# Tools
You may call one or more functions to assist with the user query.
You are provided with function signatures within <tools></tools> XML tags:
<tools>
{{- range .Tools }}
{"type": "function", "function": {{ .Function }}}
{{- end }}
</tools>
For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
<tool_call>
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call>
{{- end -}}
<|im_end|>
{{ end }}
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 -}}
{{- if eq .Role "user" }}<|im_start|>user
{{ .Content }}
{{- if and $.IsThinkSet (eq $i $lastUserIdx) }}
{{- if $.Think -}}
{{- " "}}/think
{{- else -}}
{{- " "}}/no_think
{{- end -}}
{{- end }}<|im_end|>
{{ else if eq .Role "assistant" }}<|im_start|>assistant
{{ if (and $.IsThinkSet (and .Thinking (or $last (gt $i $lastUserIdx)))) -}}
<think>{{ .Thinking }}</think>
{{ end -}}
{{ if .Content }}{{ .Content }}
{{- else if .ToolCalls }}<tool_call>
{{ range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}
{{ end }}</tool_call>
{{- end }}{{ if not $last }}<|im_end|>
{{ end }}
{{- else if eq .Role "tool" }}<|im_start|>user
<tool_response>
{{ .Content }}
</tool_response><|im_end|>
{{ end }}
{{- if and (ne .Role "assistant") $last }}<|im_start|>assistant
{{ if and $.IsThinkSet (not $.Think) -}}
<think>
</think>
{{ end -}}
{{ end }}
{{- end }}"""
PARAMETER repeat_penalty 1
PARAMETER stop <|im_start|>
PARAMETER stop <|im_end|>
PARAMETER temperature 0.6
PARAMETER top_k 20
PARAMETER top_p 0.95
然后在模型和Modelfile文件夹下通过命令行执行:
ollama create modename -f modelfilepath
2.如果飞书发消息openclaw没有正常回复,但是网页和终端中可以正常对话,则应该重启openclaw gateway,命令如下:
openclaw gateway restart
3.如果gateway提示:
Gateway service missing
则应该以管理员权限安装gateway,方法如下:
- 按下键盘上的
Win + R组合键,打开“运行”窗口。 - 在“运行”窗口中输入
cmd。 - 按下
Ctrl + Shift + Enter组合键,系统将弹出UAC(用户帐户控制)对话框询问是否允许以管理员身份运行命令提示符。 - 点击“是”按钮,即可以管理员身份打开命令窗口。
4.如果openclaw报错提示:
Embedded agent failed before reply: No API key found for provider "custom-127-0-0-1-11434". Auth store: C:\Users\path\.openclaw\agents\main\agent\auth-profiles.json (agentDir: C:\Users\path\.openclaw\agents\main\agent). Configure auth for this agent (openclaw agents add <id>) or copy auth-profiles.json from the main agentDir.
则应该使用如下命令启动openclaw:
ollama launch openclaw --model qwen3.5-9b-nl
或者重启网关:
openclaw gateway restart
更多推荐
所有评论(0)