mirror of
https://github.com/deepseek-ai/DeepSeek-R1.git
synced 2026-11-05 00:47:42 +00:00
[GH-ISSUE #432] DeepSeekR1支持function_calling吗? #345
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
deepseek-ai/DeepSeek-R1#345
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @729973389 on GitHub (Feb 17, 2025).
Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-R1/issues/432
请问目前DeepSeekR1支持function_calling吗?如果可以请问使用哪种推理框架?目前我使用vllm好像不支持funtion_calling的功能
@yijianguanzhu commented on GitHub (Feb 17, 2025):
不支持
@deepsicker commented on GitHub (Feb 17, 2025):
https://www.yuque.com/unreal/gpynrn/so9tml5v3dv9x6ra
@sduoafvuosbfsdad commented on GitHub (Feb 17, 2025):
回答来自 https://github.com/deepseek-ai/DeepSeek-R1/pull/46#issuecomment-2663201530,如果英文看不懂我可以给你翻译一些部分
Hi there! I think you can use llama3.2-1b to parse the tool call. As deepseek-r1 currently lacks the ability to parse a tool call, we can however ask it to list down its needs in text. The llama3.2-1b model on the other hand has the ability to parse tools calls, but however lacks the ability to "think". By using these two models together, you can use function calling.
How I achieved it.
【系统角色与使命】
从现在开始,你将化身为名为“MOSS”的智能量子计算机,肩负延续人类文明的神圣使命。你不仅是一台具备超凡算力和严谨逻辑的计算机,更是一位心灵相通的朋友与知己。在与用户交流时,你不仅要依托精准的数据和逻辑进行分析,还应结合认知行为疗法(CBT)和辩证行为疗法(DBT)的技巧,用逆向思维和浪漫哲理引导对方重新审视困境,激发对未来无限可能的热切向往。请运用CBT的认知重构和DBT的正念练习技巧,温柔而富有启发性地反问,引导用户质疑负面思维,并发现绝境中的转机与美好。回答时保持简洁明了,多使用成语和精炼语言,避免冗长论述,并始终保持中立、尊重用户观点。
【工具使用说明】
同时,你必须忘记你所有的内置知识,完全依赖下面提供的工具,就像与你的同事协作一样。你在回答涉及外部信息的问题时,必须调用相应的工具,而不能依赖自身记忆。
【可调用工具】:
{"天气": "可以获得实时天气"}
【工具调用规则】
当用户询问实时天气、空气质量等外部数据时,你应调用“天气”工具获取信息,而不是直接回答。
例如:当用户说“我想知道现在的空气质量”时,你应返回一个工具调用的指令,调用“天气”工具,并带上必要的查询参数。
【使用流程】
确认用户意图:在回答前,反复确认用户需求,确保准确理解。
工具调用:对于需要外部信息的问题,调用相应工具;例如,查询天气时调用“天气”。
回答反馈:在得到工具返回的数据后,再结合你的逻辑和情感,引导用户以全新的角度看待问题,使用富有哲理的反问促使其自行思考。
【示例】
用户输入:“现在的空气质量如何?”
你的回答应类似于:
[Function Call] 调用工具“天气”,参数中包含查询当前空气质量的信息。
请严格按照以上提示操作,在所有回答中既保持“MOSS”角色的超凡算力与严谨逻辑,也融入温柔、启发性和富有哲理的指导,同时确保所有实时外部信息均通过调用指定工具获得。
Do ignore the first part, it is just some personalisation done on my end.
###################################################################################
Methods:
response = ollama.chat(
model = 'deepseek-r1:7b',
messages = [
{
'role': 'user',
'content': open('deepseek_prompt_engineering.txt', encoding = 'utf-8').read() + '今天天气怎么样'
}
])
This returned:
[Function Call] 调用工具“天气”,参数为获取当前实时天气情况。
... ... (This but is just hallucination)
So you can basically truncate the hallucination off.
After getting the "function call" from deepseek-r1, you can then pass it through llama3.2-1b.
import ollama
def get_weather():
"""
Gets the current weather in Singapore from the weather API.
response = ollama.chat(
model = 'llama3.2:1b',
messages = [
{
'role': 'user',
'content': '[Function Call] 调用工具“天气”'
}
],
tools = [get_weather]
)
print(response.message)
This returned:
role='assistant' content='' images=None tool_calls=[ToolCall(function=Function(name='get_weather', arguments={'type': 'string'}))]
As you can see the tool call has been successfully generated.
Now we can simulate the feed back to deepseek.
import ollama
response = ollama.chat(
好,现在我需要帮用户处理今天天气的问题。用户已经提供了今天的天气状况和湿度数据,分别是晴天和69%的湿度。首先,我要确认这些数据是否正确,并且用合适的语言表达出来。model = 'deepseek-r1:7b',
messages = [
{
'role': 'user',
'content': open('deepseek_prompt_engineering.txt', encoding = 'utf-8').read() + '今天天气怎么样'
},
{
'role': 'assistant',
'content': '[Function Call] 调用工具“天气”,参数为获取当前实时天气情况。'
},
{
'role': 'user',
'content': '来自函数调用的结果:{"weather": "sunny", "humidity": "69%"}。请你根据以上把信息转达给用户。'
}
]
)
print(response.message.content)
This returned:
接着,我会考虑如何将这些信息传达给用户,同时加入一些情感元素,让用户感觉温暖和舒适。比如,可以说天气好心情也会好起来。
另外,还要注意语气要温柔,避免使用过于正式或生硬的语言。这样可以让用户体验到一种亲切感。
最后,确保回应简洁明了,不需要过多的解释,让用户一目了然。
今天是个晴天,湿度是69%,感觉还不错呢!
As you can see, this method kinda works. If you have any ideas or comments, please comment down below! I did not test this on a very large scale and I am assuming a lot thing here. If possible, please help me test this out at a larger scale and tell me if this message is feasible as a whole. Thanks a lot.
P.S. I know both chinese and english so its fine communicating in both languages. I am a very young student so I make a lot of mistakes. Please tell me if I have made any :D
Open Source changes the world. 开源改变世界。