🚀 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 團隊
