Chat UI 文件
工具
加入 Hugging Face 社群
並獲得增強的文件體驗
開始使用
工具
工具呼叫 (Tool calling) 指示模型生成與使用者定義模式匹配的輸出,該模式可以被解析以呼叫外部工具。模型僅選擇工具及其引數。目前,僅支援 TGI
和帶有 Command R+
的 Cohere
。


TGI 配置
提示模型生成工具呼叫以及使用結果進行提示時,需要一個自定義的分詞器。這些工具的預期格式和生成的工具呼叫對於 TGI 是硬編碼的,所以很可能只有以下配置才有效。
MODELS=`[
{
"name" : "CohereForAI/c4ai-command-r-plus",
"displayName": "Command R+",
"description": "Command R+ is Cohere's latest LLM and is the first open weight model to beat GPT4 in the Chatbot Arena!",
"tools": true,
"tokenizer": "Xenova/c4ai-command-r-v01-tokenizer",
"modelUrl": "https://huggingface.co/CohereForAI/c4ai-command-r-plus",
"websiteUrl": "https://docs.cohere.com/docs/command-r-plus",
"logoUrl": "https://huggingface.co/datasets/huggingchat/models-logo/resolve/main/cohere-logo.png",
"parameters": {
"stop": ["<|END_OF_TURN_TOKEN|>"],
"truncate" : 28672,
"max_new_tokens" : 4096,
"temperature" : 0.3
}
}
]`
Cohere 配置
Cohere 提供程式支援端點的原生工具呼叫方法。有關實現細節,請參閱 endpoints/cohere
。
MODELS=`[
{
"name": "command-r-plus",
"displayName": "Command R+",
"description": "Command R+ is Cohere's latest LLM and is the first open weight model to beat GPT4 in the Chatbot Arena!",
"tools": true,
"websiteUrl": "https://docs.cohere.com/docs/command-r-plus",
"logoUrl": "https://huggingface.co/datasets/huggingchat/models-logo/resolve/main/cohere-logo.png",
"endpoints": [{
"type": "cohere",
"apiKey": "YOUR_API_KEY"
}]
}
]`
新增工具
工具的實現在 src/lib/server/tools
中,並提供了輔助工具以便與 HuggingFace Zero GPU Spaces 輕鬆整合。未來可能會有一個 OpenAPI 介面用於新增工具。
為其他模型新增支援
TGI 的實現使用了一個自定義的分詞器和硬編碼的模式來支援工具。而 Cohere 的實現則使用 SDK 中的原生支援來發出工具呼叫。這是為更多模型新增支援的推薦方法。有關實現細節,請參閱程式碼的 endpoints/cohere
部分。