该模型是基于google/gemma-2-9b-it针对函数调用任务进行微调的版本,训练数据完全由人工标注,使用了俄语版本的DiTy/function-calling数据集。
下载量 509
发布时间 : 4/25/2025
模型介绍
内容详情
替代品
模型简介
该模型是一个针对函数调用任务优化的俄语语言模型,能够理解和生成函数调用请求,并处理函数响应。
模型特点
函数调用优化
专门针对函数调用任务进行微调,能够生成准确的函数调用请求和处理响应。
俄语支持
支持俄语,适用于俄语环境下的函数调用任务。
高效推理
基于Gemma-2-9b-it架构,推理速度快,适合实时应用。
模型能力
函数调用生成
俄语文本生成
函数响应处理
使用案例
智能助手
天气查询
用户询问天气时,模型生成函数调用请求并返回天气信息。
提供准确的天气信息
日出日落时间查询
用户询问日出日落时间时,模型生成函数调用请求并返回时间信息。
提供准确的日出日落时间
base_model: google/gemma-2-9b-it
datasets:
- DiTy/function-calling
language: - ru
library_name: transformers
license: apache-2.0
pipeline_tag: text-generation
tags: - conversational
- gemma2
- function-calling
- trl
DiTy/gemma-2-9b-it-russian-function-calling-GGUF
该模型是基于google/gemma-2-9b-it针对函数调用任务进行微调的版本,训练数据完全由人工标注,使用了俄语版本的DiTy/function-calling数据集。
除了safetensors格式外,模型还提供GGUF格式(这种情况下只需下载单个文件,如何推理GGUF模型):
文件名 | 量化类型 | 文件大小 | 描述 |
---|---|---|---|
gemma-2-9B-it-russian-function-calling-F16.gguf | F16 | 18.5GB | 基础模型,使用float16精度 |
模型卡片章节
使用(HuggingFace Transformers)
以下是一些快速启动模型的代码片段。首先安装Transformers库:
pip install -U transformers
如何为函数调用准备你的功能(tools)
你需要用Python代码编写模型使用的功能(工具),并务必添加Python文档字符串,如下例所示:
def get_weather(city: str):
"""
返回指定城市的天气。
Args:
city: 需要查询天气的城市。
"""
import random
return "晴天" if random.random() > 0.5 else "雨天"
def get_sunrise_sunset_times(city: str):
"""
返回指定城市当前日期的日出和日落时间(无需用户提供日期),格式为列表:[sunrise_time, sunset_time]。
Args:
city: 需要查询日出日落时间的城市。
"""
return ["6:00", "18:00"]
直接使用聊天模板生成
接下来加载模型和分词器:
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained(
"DiTy/gemma-2-9b-it-russian-function-calling-GGUF",
device_map="auto",
torch_dtype=torch.bfloat16, # 如果不支持bfloat16,可以使用float16或float32。
cache_dir=PATH_TO_MODEL_DIR, # 可选
)
tokenizer = AutoTokenizer.from_pretrained(
"DiTy/gemma-2-9b-it-russian-function-calling-GGUF",
cache_dir=PATH_TO_MODEL_DIR, # 可选
)
要生成结果,只需使用apply_chat_template
。为了包含我们编写的功能(工具),需要通过tools
属性传递它们,并使用add_prompt_generation=True
。
history_messages = [
{"role": "system", "content": "你是一个有用的助手,可以访问以下功能。必要时请使用它们——"},
{"role": "user", "content": "你好,能告诉我克拉斯诺达尔的日出时间吗?"}
]
inputs = tokenizer.apply_chat_template(
history_messages,
tokenize=False,
add_generation_prompt=True, # 添加生成提示
tools=[get_weather, get_sunrise_sunset_times], # 我们的功能(工具)
)
print(inputs)
此时inputs
将如下所示:
<bos><start_of_turn>user
你是一个有用的助手,可以访问以下功能。必要时请使用它们—— {
"name": "get_weather",
"description": "返回指定城市的天气。",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "需要查询天气的城市。"
}
},
"required": [
"city"
]
}
},
{
"name": "get_sunrise_sunset_times",
"description": "返回指定城市当前日期的日出和日落时间(无需用户提供日期),格式为列表:[sunrise_time, sunset_time]。",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "需要查询日出日落时间的城市。"
}
},
"required": [
"city"
]
}
}
你好,能告诉我克拉斯诺达尔的日出时间吗?<end_of_turn>
<start_of_turn>model
现在可以生成模型的响应。注意,使用apply_chat_template
后,在分词时无需添加特殊标记,因此使用add_special_tokens=False
:
terminator_ids = [
tokenizer.eos_token_id,
tokenizer.convert_tokens_to_ids("<end_of_turn>"),
]
prompt_ids = tokenizer.encode(inputs, add_special_tokens=False, return_tensors='pt').to(model.device)
generated_ids = model.generate(
prompt_ids,
max_new_tokens=512,
eos_token_id=terminator_ids,
bos_token_id=tokenizer.bos_token_id,
)
generated_response = tokenizer.decode(generated_ids[0][prompt_ids.shape[-1]:], skip_special_tokens=False) # `skip_special_tokens=False`用于调试
print(generated_response)
生成的响应为函数调用:
调用函数: {"name": "get_sunrise_sunset_times", "arguments": {"city": "克拉斯诺达尔"}}<end_of_turn>
接下来,我们可以通过调用函数获取和处理结果,然后将函数的响应提供给模型:
history_messages = [
{"role": "system", "content": "你是一个有用的助手,可以访问以下功能。必要时请使用它们——"},
{"role": "user", "content": "你好,能告诉我克拉斯诺达尔的日出时间吗?"},
{"role": "function-call", "content": '{"name": "get_sunrise_sunset_times", "arguments": {"city": "克拉斯诺达尔"}}'},
{"role": "function-response", "content": '{"times_list": ["6:00", "18:00"]}'}, # 假设的函数响应
]
inputs = tokenizer.apply_chat_template(
history_messages,
tokenize=False,
add_generation_prompt=True, # 添加生成提示
tools=[get_weather, get_sunrise_sunset_times], # 我们的功能(工具)
)
print(inputs)
确认inputs
正确:
<bos><start_of_turn>user
你是一个有用的助手,可以访问以下功能。必要时请使用它们—— {
"name": "get_weather",
"description": "返回指定城市的天气。",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "需要查询天气的城市。"
}
},
"required": [
"city"
]
}
},
{
"name": "get_sunrise_sunset_times",
"description": "返回指定城市当前日期的日出和日落时间(无需用户提供日期),格式为列表:[sunrise_time, sunset_time]。",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "需要查询日出日落时间的城市。"
}
},
"required": [
"city"
]
}
}
你好,能告诉我克拉斯诺达尔的日出时间吗?<end_of_turn>
<start_of_turn>model
调用函数: {"name": "get_sunrise_sunset_times", "arguments": {"city": "克拉斯诺达尔"}}<end_of_turn>
<start_of_turn>user
函数响应: {"times_list": ["6:00", "18:00"]}<end_of_turn>
<start_of_turn>model
同样生成模型响应:
prompt_ids = tokenizer.encode(inputs, add_special_tokens=False, return_tensors='pt').to(model.device)
generated_ids = model.generate(
prompt_ids,
max_new_tokens=512,
eos_token_id=terminator_ids,
bos_token_id=tokenizer.bos_token_id,
)
generated_response = tokenizer.decode(generated_ids[0][prompt_ids.shape[-1]:], skip_special_tokens=False)
print(generated_response)
模型最终响应:
在克拉斯诺达尔,太阳早上6:00升起,晚上18:00落下。<end_of_turn>
通过transformers的pipeline
使用
通过pipeline生成
from transformers import pipeline
generation_pipeline = pipeline(
"text-generation",
model="DiTy/gemma-2-9b-it-russian-function-calling-GGUF",
model_kwargs={
"torch_dtype": torch.bfloat16, # 如果不支持bfloat16,可以使用float16或float32。
"cache_dir": PATH_TO_MODEL_DIR, # 可选
},
device_map="auto",
)
history_messages = [
{"role": "system", "content": "你是一个有用的助手,可以访问以下功能。必要时请使用它们——"},
{"role": "user", "content": "你好,能告诉我克拉斯诺达尔的日出时间吗?"},
{"role": "function-call", "content": '{"name": "get_sunrise_sunset_times", "arguments": {"city": "克拉斯诺达尔"}}'},
{"role": "function-response", "content": '{"times_list": ["6:00", "18:00"]}'}
]
inputs = generation_pipeline.tokenizer.apply_chat_template(
history_messages,
tokenize=False,
add_generation_prompt=True,
tools=[get_weather, get_sunrise_sunset_times],
)
terminator_ids = [
generation_pipeline.tokenizer.eos_token_id,
generation_pipeline.tokenizer.convert_tokens_to_ids("<end_of_turn>")
]
outputs = generation_pipeline(
inputs,
max_new_tokens=512,
eos_token_id=terminator_ids,
)
print(outputs[0]["generated_text"][len(inputs):])
提示结构和预期内容
为了确保模型正常工作,建议使用apply_chat_template
。需要以特定格式传递历史消息。
history_messages = [
{"role": "...", "content": "..."},
...
]
可用角色包括:
system
- 可选角色,其内容始终位于开头,并在列出模型可用功能(工具)之前。
可以使用训练时使用的标准内容:"你是一个有用的助手,可以访问以下功能。必要时请使用它们——"user
- 用户请求通过此角色传递。function-call
- 函数调用的主体通过此角色传递。
尽管模型训练为生成***"调用函数: {...}<end_of_turn>"格式,但你只需在"content"字段中传递主体"{...}"***,
因为使用apply_chat_template
时,指令的后缀会自动添加。function-response
- 通过此角色传递函数响应,"content"字段应为字典格式*'{"name_returnable_value": value}'***。model
- 此角色的内容被视为模型生成的文本。
函数调用的聊天历史结构
[
Phi 2 GGUF
其他
Phi-2是微软开发的一个小型但强大的语言模型,具有27亿参数,专注于高效推理和高质量文本生成。
大型语言模型
支持多种语言
P
TheBloke
41.5M
205
Roberta Large
MIT
基于掩码语言建模目标预训练的大型英语语言模型,采用改进的BERT训练方法
大型语言模型
英语
R
FacebookAI
19.4M
212
Distilbert Base Uncased
Apache-2.0
DistilBERT是BERT基础模型的蒸馏版本,在保持相近性能的同时更轻量高效,适用于序列分类、标记分类等自然语言处理任务。
大型语言模型
英语
D
distilbert
11.1M
669
Llama 3.1 8B Instruct GGUF
Meta Llama 3.1 8B Instruct 是一个多语言大语言模型,针对多语言对话用例进行了优化,在常见的行业基准测试中表现优异。
大型语言模型
英语
L
modularai
9.7M
4
Xlm Roberta Base
MIT
XLM-RoBERTa是基于100种语言的2.5TB过滤CommonCrawl数据预训练的多语言模型,采用掩码语言建模目标进行训练。
大型语言模型
支持多种语言
X
FacebookAI
9.6M
664
Roberta Base
MIT
基于Transformer架构的英语预训练模型,通过掩码语言建模目标在海量文本上训练,支持文本特征提取和下游任务微调
大型语言模型
英语
R
FacebookAI
9.3M
488
Opt 125m
其他
OPT是由Meta AI发布的开放预训练Transformer语言模型套件,参数量从1.25亿到1750亿,旨在对标GPT-3系列性能,同时促进大规模语言模型的开放研究。
大型语言模型
英语
O
facebook
6.3M
198
Llama 3.1 8B Instruct
Llama 3.1是Meta推出的多语言大语言模型系列,包含8B、70B和405B参数规模,支持8种语言和代码生成,优化了多语言对话场景。
大型语言模型
Transformers

支持多种语言
L
meta-llama
5.7M
3,898
T5 Base
Apache-2.0
T5基础版是由Google开发的文本到文本转换Transformer模型,参数规模2.2亿,支持多语言NLP任务。
大型语言模型
支持多种语言
T
google-t5
5.4M
702
Xlm Roberta Large
MIT
XLM-RoBERTa是基于100种语言的2.5TB过滤CommonCrawl数据预训练的多语言模型,采用掩码语言建模目标进行训练。
大型语言模型
支持多种语言
X
FacebookAI
5.3M
431
精选推荐AI模型
Llama 3 Typhoon V1.5x 8b Instruct
专为泰语设计的80亿参数指令模型,性能媲美GPT-3.5-turbo,优化了应用场景、检索增强生成、受限生成和推理任务
大型语言模型
Transformers

支持多种语言
L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一个基于SODA数据集训练的超小型对话模型,专为边缘设备推理设计,体积仅为Cosmo-3B模型的2%左右。
对话系统
Transformers

英语
C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基于RoBERTa架构的中文抽取式问答模型,适用于从给定文本中提取答案的任务。
问答系统
中文
R
uer
2,694
98
AIbase是一个专注于MCP服务的平台,为AI开发者提供高质量的模型上下文协议服务,助力AI应用开发。
简体中文