license: llama3
tags:
FireFunction V2:Fireworks 函数调用模型
在 Fireworks 上试用 | API 文档 | 演示应用 | Discord
FireFunction 是一款具有商业可行许可的最先进函数调用模型。查看我们的发布博客获取详细信息。关键信息和亮点:
与其他模型的比较:
- 在函数调用方面与 GPT-4o 竞争,在多项公开评估中得分 0.81 对 0.80
- 基于 Llama 3 训练,保留了 Llama 3 的对话和指令遵循能力,在 MT bench 上得分 0.84 对 Llama 3 的 0.89
- 在广泛的指标上相比 FireFunction v1 有显著的质量提升
基本信息:
🐾 FireFunction 模型的继任者
🔆 支持并行函数调用(与 FireFunction v1 不同)和良好的指令遵循
💡 托管在 Fireworks 平台,成本不到 GPT 4o 的 10%,速度是其 2 倍
预期用途与限制
支持的用例
该模型经过调整,在以下用例中表现良好:
- 通用指令遵循
- 混合普通消息与函数调用的多轮对话
- 单次和并行函数调用
- 最多支持 20 个函数规范
- 结构化信息提取
该模型具有 8k 上下文窗口,与 Llama 3 相同
超出范围的用途
该模型未针对以下用例进行优化:
指标
基准测试 |
Firefunction v1 |
Firefunction v2 |
Llama 3 70b Instruct |
Gpt-4o |
Gorilla simple |
0.91 |
0.94 |
0.925 |
0.88 |
Gorilla multiple_function |
0.92 |
0.91 |
0.86 |
0.91 |
Gorilla parallel_function |
0 |
0.9 |
0.86 |
0.89 |
Gorilla parallel_multiple_function |
0 |
0.8 |
0.615 |
0.72 |
Nexus parallel |
0.38 |
0.53 |
0.3 |
0.47 |
Mtbench |
0.73 |
0.84 |
0.89 |
0.93 |
平均 |
0.49 |
0.82 |
0.74 |
0.8 |
示例用法
更多详情请参阅文档。
from transformers import AutoModelForCausalLM, AutoTokenizer
import json
from datetime import datetime
device = "cuda"
model = AutoModelForCausalLM.from_pretrained("fireworks-ai/firefunction-v2", device_map="auto")
tokenizer = AutoTokenizer.from_pretrained("fireworks-ai/firefunction-v2")
function_spec = [
{
"name": "get_stock_price",
"description": "获取当前股票价格",
"parameters": {
"type": "object",
"properties": {
"symbol": {
"type": "string",
"description": "股票代码,例如 AAPL, GOOG"
}
},
"required": [
"symbol"
]
}
},
{
"name": "check_word_anagram",
"description": "检查两个单词是否为变位词",
"parameters": {
"type": "object",
"properties": {
"word1": {
"type": "string",
"description": "第一个单词"
},
"word2": {
"type": "string",
"description": "第二个单词"
}
},
"required": [
"word1",
"word2"
]
}
}
]
functions = json.dumps(function_spec, indent=4)
messages = [
{'role': 'system', 'content': '你是一个有帮助的助手,可以使用函数。如果需要,请使用它们。'},
{'role': 'user', 'content': '嗨,你能告诉我谷歌和网飞的当前股票价格吗?'}
]
now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
model_inputs = tokenizer.apply_chat_template(messages, functions=functions, datetime=now, return_tensors="pt").to(model.device)
generated_ids = model.generate(model_inputs, max_new_tokens=128)
decoded = tokenizer.batch_decode(generated_ids)
print(decoded[0])
资源