首页 > 其他分享 >ollama llama3.1 8b openbuddy 模型

ollama llama3.1 8b openbuddy 模型

时间:2024-07-27 14:51:38浏览次数:8  
标签:function end description 8b llama3.1 openbuddy add type ollama

openbuddy 对于 llama3.1 8b 模型进行了少量的中文训练实现了不错的中文理解处理,以下是使用社区提供的gguf 格式,制作一个ollama 新模型

模型制作

  • 下载模型
    下载gguf 文件,推荐使用加速工具
  • Modelfile
    参考了llama3.1 的
FROM /home/models/openbuddy-llama3.1-8b-v22.1-131k-q4_k_m.gguf
 
TEMPLATE """{{ if .Messages }}
{{- if or .System .Tools }}<|start_header_id|>system<|end_header_id|>
{{- if .System }}
 
{{ .System }}
{{- end }}
{{- if .Tools }}
 
You are a helpful assistant with tool calling capabilities. When you receive a tool call response, use the output to format an answer to the orginal use question.
{{- end }}<|eot_id|>
{{- end }}
{{- range $i, $_ := .Messages }}
{{- $last := eq (len (slice $.Messages $i)) 1 }}
{{- if eq .Role "user" }}<|start_header_id|>user<|end_header_id|>
{{- if and $.Tools $last }}
 
Given the following functions, please respond with a JSON for a function call with its proper arguments that best answers the given prompt.
 
Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}. Do not use variables.
 
{{ $.Tools }}
{{- end }}
 
{{ .Content }}<|eot_id|>{{ if $last }}<|start_header_id|>assistant<|end_header_id|>
 
{{ end }}
{{- else if eq .Role "assistant" }}<|start_header_id|>assistant<|end_header_id|>
{{- if .ToolCalls }}
 
{{- range .ToolCalls }}{"name": "{{ .Function.Name }}", "parameters": {{ .Function.Arguments }}}{{ end }}
{{- else }}
 
{{ .Content }}{{ if not $last }}<|eot_id|>{{ end }}
{{- end }}
{{- else if eq .Role "tool" }}<|start_header_id|>ipython<|end_header_id|>
 
{{ .Content }}<|eot_id|>{{ if $last }}<|start_header_id|>assistant<|end_header_id|>
 
{{ end }}
{{- end }}
{{- end }}
{{- else }}
{{- if .System }}<|start_header_id|>system<|end_header_id|>
 
{{ .System }}<|eot_id|>{{ end }}{{ if .Prompt }}<|start_header_id|>user<|end_header_id|>
 
{{ .Prompt }}<|eot_id|>{{ end }}<|start_header_id|>assistant<|end_header_id|>
 
{{ end }}{{ .Response }}{{ if .Response }}<|eot_id|>{{ end }}"""
PARAMETER stop "<|start_header_id|>"
PARAMETER stop "<|end_header_id|>"
PARAMETER stop "<|eot_id|>"
  • 构建
ollama create openbuddy-llama3.1 -f Modelfile

使用

测试的函数调用

  • appv3.py
import openai
import json
   
def add(a, b):
    return a + b
   
def sub(a, b):
    return a - b
   
def send_email(userid, mailContent):
    return f"send email to {userid} with content: {mailContent}"
     
def add_role(userid, roleid):
    return f"add role {roleid} to user {userid}"
 
openai.api_key = "demo"
openai.base_url = "http://localhost:11434/v1/"
 
funcs = {
    "add": add,
    "sub": sub,
    "send_email":send_email,
    "add_role":add_role
}
 
tools = [{
    "type": "function",
            "function": {
                "name": "add",
                "description": "Add two numbers together",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "a": {"type": "number", "description": "First number"},
                        "b": {"type": "number", "description": "Second number"}
                    },
                    "required": ["a", "b"]
                }
            }
},
    {
    "type": "function",
            "function": {
                "name": "sub",
                "description": "计算两个数的差",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "a": {"type": "number", "description": "First number"},
                        "b": {"type": "number", "description": "Second number"}
                    },
                    "required": ["a", "b"]
                }
            }
},
 {
    "type": "function",
            "function": {
                "name": "add_role",
                "description": "给用户添加权限",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "userid": {"type": "string", "description": "用户id"},
                        "roleid": {"type": "string", "description": "角色id"}
                    },
                    "required": ["userid", "roleid"]
                }
            }
},
 {
    "type": "function",
            "function": {
                "name": "send_email",
                "description": "给用户发送邮件",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "userid": {"type": "string", "description": "用户id"},
                        "mailContent": {"type": "string", "description": "邮件内容"}
                    },
                    "required": ["userid", "mailContent"]
                }
            }
}
]
response = openai.chat.completions.create(
    stream=False,
    model="rongfengliang/openbuddy-llama3.1",
    messages=[
        {"role": "system", "content": "你是一个人工智能助手,你可以帮助用户处理数据,发送邮件等,但是你必须使用中文"},
        {"role": "user", "content": "给用户001发送数据处理已经完成的邮件通知同时添加角色0002"},
    ],
    tools=tools,
    tool_choice="auto",
)
message = response.choices[0].message
print(message)
if message.tool_calls:
    result = response.choices[0].message.tool_calls[0].function
    print(result)
    func = funcs.get(result.name)
    params = json.loads(result.arguments)
    print(func(**params))
else:
    print(message.content)
 
  • 效果

说明

目前基于openbuddy支持中文的进行函数调用比原生的是好一些,原生的有时有出现莫名其妙的中文信息

参考资料

https://openbuddy.ai/
https://github.com/OpenBuddy/OpenBuddy
https://huggingface.co/OpenBuddy/openbuddy-llama3.1-8b-v22.1-131k
https://huggingface.co/sunnyyy/openbuddy-llama3.1-8b-v22.1-131k-Q4_K_M-GGUF

标签:function,end,description,8b,llama3.1,openbuddy,add,type,ollama
From: https://www.cnblogs.com/rongfengliang/p/18326936

相关文章

  • OpenCompass 评测 InternLM-1.8B 实践
    1.进入https://opencompass.org.cn/home,点击在线测评,创建在线测评2.选择internlm2-chat-1.8b模型,与MMLU数据集,开始测评3.查看测评结果......
  • LLAMA3.1数据处理
    4.2.3数据处理和质量控制鉴于我们的大部分训练数据都是模型生成的,因此需要仔细清理和质量控制。数据清理。在早期阶段,我们观察到数据中常见的一些不良模式,例如过度使用表情符号或感叹号。因此,我们实施了一系列基于规则的数据删除和修改策略来过滤或清理有问题的数据。例如,为了减......
  • 使用Ollama
    推荐Ollama本地运行大模型(LLM)完全指南Ollama中文学习应用查看可支持的模型:https://ollama.com/library查看运行中的模型ollamaps停止模型方法1:kill-9端口号方法2:关闭ollama的窗口API调用模型启动模型单次调用模型fromollamaimportClienti......
  • 只需3步:教你如何在本地环境运行llama3.1
    今天,跟大家分享一下,如何在自己电脑上使用到最新的llama3.1大模型。直接上教程:1,访问这个地址:https://ollama.com/点击“Download”,进入下载页面。此时,你会看到下面这个页面,根据实际情况选择下载版本,我这里是选择的windows版本。安装包下载好之后,进行安装。2,下载安装......
  • 教你轻松本地电脑部署最新Llama3.1,搭建免费本地大模型助手
    ......
  • Llama3.1以405B参数领先GPT-4o
    Llama3.1以405B参数规模领先GPT-4o,并在多项基准测试中展现出强大的性能,尤其是在通用常识、可操纵性、数学、工具使用和多语言翻译等方面。Llama3.1的参数规模和性能参数规模Llama3.1系列模型包括8B、70B和405B三种参数规模,其中405B模型包含4050亿个参数,是近年来规模最大LLM......
  • 搭建Ollama环境
    Ollama环境搭建参考链接:https://baijiahao.baidu.com/s?id=1798741366479996086&wfr=spider&for=pc下载Ollama下载地址:https://ollama.com/download双击直接安装安装成功,默认模型的位置是C:\Users.ollama\models,可在powershell修改模型位置setxOLLAMA_MODELS"D:\others\O......
  • 在安卓手机上用 ollama 运行开源大模型
    License:CCBY-NC-SA4.0前言一种不刷机,不用root的解决方案。如果有条件可以root后装LinuxDeploy或者干脆刷成linux.正文先要装上termux.加速proot-distro下载以ArchLinux为例。vi/data/data/com.termux/files/usr/etc/proot-distro/archlinux.sh把里面......
  • 使用Ollama部署非官方仓库模型(Windows)
    一、从GitHub拉去llama.cpp项目gitclonehttps://github.com/ggerganov/llama.cpp下载完成后在当前目录的路径输入cmd,进入命令行二、安装python执行的相关依赖执行pipinstall-rrequirements.txt三、下载模型文件依赖安装成功后开始转换模型这里以魔塔上的C......
  • 如何立即取消使用 Ollama Python 库生成答案的 Asyncio 任务?
    我正在使用Ollama通过OllamaPythonAPI从大型语言模型(LLM)生成答案。我想通过单击停止按钮取消响应生成。问题在于,只有当响应生成已经开始打印时,任务取消才会起作用。如果任务仍在处理并准备打印,则取消不起作用,并且无论如何都会打印响应。更具体地说,即使单击按钮后,此函数......