🚀 Functionary-small-v2.2 模型卡片
Functionary 是一个能够解释和执行函数/插件的语言模型。它可以决定何时执行函数,是并行执行还是串行执行,并能理解函数的输出,仅在需要时触发函数。函数定义以 JSON Schema 对象的形式给出,类似于 OpenAI GPT 的函数调用。
https://github.com/MeetKai/functionary

🚀 快速开始
Functionary 是一款强大的语言模型,可解释和执行函数/插件。它能智能决定函数执行时机与方式,仅在必要时触发函数,函数定义类似 OpenAI GPT 函数调用。
✨ 主要特性
- 智能并行工具使用:能够智能地并行使用工具,提高处理效率。
- 基于输出的相关响应:可以分析函数/工具的输出,并根据输出提供相关的响应。
- 灵活决策是否使用工具:能够决定何时不使用工具/调用函数,并提供正常的聊天响应。
- 优秀的开源替代方案:是 GPT - 4 优秀的开源替代方案之一。
📊 性能表现
我们的模型在内部数据集的函数调用准确率方面达到了当前的先进水平。准确率指标衡量了预测函数调用的整体正确性,包括函数名预测和参数提取。

数据集 |
模型名称 |
函数调用准确率(名称与参数) |
内部数据 |
MeetKai - functionary - small - v2.2 |
0.546 |
内部数据 |
MeetKai - functionary - medium - v2.2 |
0.664 |
内部数据 |
OpenAI - gpt - 3.5 - turbo - 1106 |
0.531 |
内部数据 |
OpenAI - gpt - 4 - 1106 - preview |
0.737 |
📄 提示模板
我们使用了一个专门设计的提示模板,称为“v2PromptTemplate”,它将每一轮对话分解为发送者、接收者和内容部分。
我们将函数定义转换为类似于 TypeScript 定义的文本,然后将这些定义作为系统提示注入。之后,注入默认的系统提示,最后开始对话消息。
通过我们的 vLLM 服务器也可以使用这种格式,我们将函数处理成封装在系统消息中的 TypeScript 定义,并使用预定义的 Transformers 聊天模板。这意味着可以使用 apply_chat_template()
方法为您格式化消息列表。
💻 使用示例
基础用法
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="functionary")
client.chat.completions.create(
model="path/to/functionary/model/",
messages=[{"role": "user",
"content": "What is the weather for Istanbul?"}
],
tools=[{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
}
},
"required": ["location"]
}
}
}],
tool_choice="auto"
)
上述代码运行后将产生如下格式化内容:
<|from|>system
<|recipient|>all
<|content|>// Supported function definitions that should be called when necessary.
namespace functions {
// Get the current weather
type get_current_weather = (_: {
// The city and state, e.g. San Francisco, CA
location: string,
}) => any;
} // namespace functions
<|from|>system
<|recipient|>all
<|content|>A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. The assistant calls functions with appropriate input when necessary
<|from|>user
<|recipient|>all
<|content|>What is the weather for Istanbul?
更详细的示例请参考 此处。
🏃♂️ 运行模型
我们建议用户使用我们兼容 OpenAI 的 vLLM 服务器来运行我们的模型,详情请见 此处。
👥 MeetKai 团队
