当前位置: 首页 > news >正文

Ollama Qwen2 支持 Function Calling

默认 Ollama 中的 Qwen2 模型不支持 Function Calling,使用默认 Qwen2,Ollama 会报错。本文将根据官方模板对 ChatTemplate 进行改进,使得Qwen2 支持 Tools,支持函数调用。
在这里插入图片描述
Ollama 会检查对话模板中是否存在 Tools,如果不存在就会报错,下面的代码是 Ollama 解析模板的代码。
在这里插入图片描述
Ollama 3.1 是支持 Tools 的,可以看到模板中定义了 Tools。
在这里插入图片描述
修改 Qwen2 配置并创建新的模型,首先我们定义一个 Ollama 模型文件,创建文件 qwen_tools。

FROM qwen2:7b# set the temperature to 0.7 [higher is more creative, lower is more coherent]
PARAMETER temperature 0.7
PARAMETER top_p 0.8
PARAMETER repeat_penalty 1.05
TEMPLATE """{{ if .Messages }}
{{- if or .System .Tools }}<|im_start|>system
{{ .System }}
{{- if .Tools }}# ToolsYou are provided with function signatures within <tools></tools> XML tags. You may call one or more functions to assist with the user query. Don't make assumptions about what values to plug into functions. Here are the available tools:
<tools>{{- range .Tools }}{{ .Function }}{{- end }}</tools>For each function call, return a JSON object with function name and arguments within <tool_call></tool_call> XML tags as follows:
<tool_call>
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call>{{- end }}<|im_end|>{{- end }}
{{- range .Messages }}
{{- if eq .Role "user" }}
<|im_start|>{{ .Role }}
{{ .Content }}<|im_end|>
{{- else if eq .Role "assistant" }}
<|im_start|>{{ .Role }}
{{- if .Content }}
{{ .Content }}
{{- end }}
{{- if .ToolCalls }}
<tool_call>
{{ range .ToolCalls }}{"name": "{{ .Function.Name }}", "arguments": {{ .Function.Arguments }}}
{{ end }}</tool_call>
{{- end }}<|im_end|>
{{- else if eq .Role "tool" }}
<|im_start|>user
<tool_response>
{{ .Content }}
</tool_response><|im_end|>
{{- end }}
{{- end }}
<|im_start|>assistant
{{ else }}{{ if .System }}<|im_start|>system
{{ .System }}<|im_end|>
{{ end }}{{ if .Prompt }}<|im_start|>user
{{ .Prompt }}<|im_end|>
{{ end }}<|im_start|>assistant
{{ end }}
"""

构建模型

ollama create qwen2tools --file ./qwen_tools 

测试模型

在这里插入图片描述

总结

现在的模型都是支持 Tools,在 Ollama 中使用我们需要对 Template 配置,配置好 Tools 后,就可以通过 Ollama 直接进行函数调用了。

http://www.lryc.cn/news/432498.html

相关文章:

  • APP测试工程师岗位面试题
  • 如何进行 AWS 云监控
  • 第十六篇:走入计算机网络的传输层--传输层概述
  • 提升效率!ArcGIS中创建脚本工具
  • 无人机之报警器的作用
  • 风格控制水平创新高!南理工InstantX小红书发布CSGO:简单高效的端到端风格迁移框架
  • python文件自动化(4)
  • HTTP 方法
  • 通过redis-operator 来部署 Redis Cluster 集群
  • vue3集成sql语句编辑器
  • Optuna发布 4.0 重大更新:多目标TPESampler自动化超参数优化速度提升显著
  • https和harbor仓库跟k8s
  • 云计算之网络
  • MySQL Workbench 的入门指南
  • 【SpringBoot】使用Nacos服务注册发现与配置管理
  • Leetcode面试经典150题-210.课程表II
  • 视频汇聚平台LntonAIServer视频质量诊断功能--偏色检测与噪声检测
  • Vue 使用接口返回的背景图片和拼图图片进行滑动拼图验证
  • 1-7 掩膜的运用 opencv树莓派4B 入门系列笔记
  • EG边缘计算网关连接华为云物联网平台(MQTT协议)
  • List中常见的方法和五种遍历方式
  • 华为 HCIP-Datacom H12-821 题库 (8)
  • 12. GIS地图制图工程师岗位职责、技术要求和常见面试题
  • ORACLE 统计信息的备份与恢复
  • 2. GIS数据工程师岗位职责、技术要求和常见面试题
  • Spark MLlib模型训练—文本算法 LDA(Latent Dirichlet Allocation)
  • C++ ─── List的模拟实现
  • Spring Boot详解
  • Proxfier+burpsuite抓包配置问题
  • sqli-lab靶场学习(一)——Less1-4