🚀 Functionary-medium-v2.2 語言模型介紹
Functionary 是一款能夠解釋並執行函數/插件的語言模型。它可以決定何時執行函數,能並行或串行執行,並理解函數輸出,且僅在必要時觸發函數。函數定義以 JSON Schema 對象形式給出,類似於 OpenAI GPT 的函數調用。
🚀 快速開始
你可以通過我們兼容 OpenAI 的 vLLM 服務器來運行該模型,具體請參考 此處。
✨ 主要特性
- 智能並行工具使用:具備智能的並行工具使用能力。
- 基於輸出提供響應:能夠分析函數/工具的輸出,並根據輸出提供相關響應。
- 靈活決策工具使用:可以決定何時不使用工具/調用函數,並提供正常的聊天回覆。
- 優秀的開源替代方案:是 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",它將每一輪對話分解為發送者、接收者和內容部分。以下是一個使用示例:
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?
更詳細的示例請參考 此處。
提示信息
我們使用的提示模板會將函數定義轉換為類似於 TypeScript 定義的文本,並將這些定義作為系統提示注入。之後注入默認的系統提示,然後開始對話消息。這種格式化方式也可以通過我們的 vLLM 服務器實現,服務器會將函數處理為封裝在系統消息中的 TypeScript 定義,並使用預定義的 Transformers 聊天模板。也就是說,你可以使用 apply_chat_template()
方法對消息列表進行格式化。
項目鏈接:https://github.com/MeetKai/functionary

