库名称: transformers
标签:
- 文本生成推理
- transformers
- unsloth
- mistral
- trl
许可证: apache-2.0
语言:
- 英语
- 越南语
基础模型: Viet-Mistral/Vistral-7B-Chat
模型描述
该模型是基于Vistral-7B-chat进行微调,用于函数调用功能。
使用方法
您可以在此处找到GGUF模型: https://huggingface.co/hiieu/Vistral-7B-Chat-function-calling-gguf
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained('hiieu/Vistral-7B-Chat-function-calling')
model = AutoModelForCausalLM.from_pretrained(
'hiieu/Vistral-7B-Chat-function-calling',
torch_dtype=torch.bfloat16,
device_map="auto",
use_cache=True,
)
functions_metadata = [
{
"type": "function",
"function": {
"name": "get_temperature",
"description": "获取城市温度",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "城市名称"
}
},
"required": [
"city"
]
}
}
}
]
conversation = [
{"role": "system", "content": f"""你是一个有用的助手,可以访问以下功能。如果需要,请使用它们 -\n{str(functions_metadata)} 要使用这些功能,请回复:\n<functioncall> {{\\"name\\": \\"function_name\\", \\"arguments\\": {{\\"arg_1\\": \\"value_1\\", \\"arg_1\\": \\"value_1\\", ...}} }} </functioncall>\n\n需要特别注意的情况:\n - 如果没有功能匹配用户请求,你需要礼貌地回复无法提供帮助。""" },
{"role": "user", "content": "河内现在的天气是多少度"},
{"role": "assistant", "content": """<functioncall> {"name": "get_temperature", "arguments": '{"city": "河内"}'} </functioncall>"""},
{"role": "user", "content": """<function_response> {"temperature" : "20 C"} </function_response>"""},
]
input_ids = tokenizer.apply_chat_template(conversation, return_tensors="pt").to(model.device)
out_ids = model.generate(
input_ids=input_ids,
max_new_tokens=768,
do_sample=True,
top_p=0.95,
top_k=40,
temperature=0.1,
repetition_penalty=1.05,
)
assistant = tokenizer.batch_decode(out_ids[:, input_ids.size(1): ], skip_special_tokens=True)[0].strip()
print("助手: ", assistant)
上传的模型
- 开发者: hiieu
- 许可证: apache-2.0
- 微调基础模型: Viet-Mistral/Vistral-7B-Chat
该mistral模型使用Unsloth和Huggingface的TRL库训练,速度提升了2倍。
