🚀 FireFunction V2:Fireworks函数调用模型
FireFunction是一款先进的函数调用模型,拥有商业可行的许可证。它能够在多种函数调用场景中表现出色,为用户提供高效、准确的服务。
在Fireworks上试用 | API文档 | 演示应用 | Discord社区
✨ 主要特性
与其他模型对比
- 函数调用能力:在函数调用方面可与GPT - 4o相媲美,在一系列公开评估中得分0.81,而GPT - 4o为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个函数规范
- 结构化信息提取
该模型与Llama 3一样,具有8k的上下文窗口。
不适用的用例
该模型未针对以下用例进行优化:
性能指标
基准测试 |
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": "Get the current stock price",
"parameters": {
"type": "object",
"properties": {
"symbol": {
"type": "string",
"description": "The stock symbol, e.g. AAPL, GOOG"
}
},
"required": [
"symbol"
]
}
},
{
"name": "check_word_anagram",
"description": "Check if two words are anagrams of each other",
"parameters": {
"type": "object",
"properties": {
"word1": {
"type": "string",
"description": "The first word"
},
"word2": {
"type": "string",
"description": "The second word"
}
},
"required": [
"word1",
"word2"
]
}
}
]
functions = json.dumps(function_spec, indent=4)
messages = [
{'role': 'system', 'content': 'You are a helpful assistant with access to functions. Use them if required.'},
{'role': 'user', 'content': 'Hi, can you tell me the current stock price of google and netflix?'}
]
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])
📄 许可证
本项目使用Llama 3许可证。
📦 资源链接