[GH-ISSUE #6] Function Calling失效 #4

Closed
opened 2026-10-26 21:10:12 +00:00 by bsakaguchi · 1 comment
Owner

Originally created by @difsch2077 on GitHub (Dec 26, 2024).
Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-V3/issues/6

下面代码的输出为:
User> How's the weather in Hangzhou?
Model>
这里Model后面没有任何内容!!!

from openai import OpenAI

def send_messages(messages):
response = client.chat.completions.create(
model="deepseek-chat",
messages=messages,
tools=tools
)
return response.choices[0].message

client = OpenAI(
api_key="",
base_url="https://api.deepseek.com",
)

tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather of an location, the user shoud supply a location first",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
}
},
"required": ["location"]
},
}
},
]

messages = [{"role": "user", "content": "How's the weather in Hangzhou?"}]
message = send_messages(messages)
print(f"User>\t {messages[0]['content']}")

tool = message.tool_calls[0]
messages.append(message)

messages.append({"role": "tool", "tool_call_id": tool.id, "content": "24℃"})
message = send_messages(messages)
print(f"Model>\t {message.content}")

Originally created by @difsch2077 on GitHub (Dec 26, 2024). Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-V3/issues/6 下面代码的输出为: User> How's the weather in Hangzhou? Model> 这里Model后面没有任何内容!!! from openai import OpenAI def send_messages(messages): response = client.chat.completions.create( model="deepseek-chat", messages=messages, tools=tools ) return response.choices[0].message client = OpenAI( api_key="<your api key>", base_url="https://api.deepseek.com", ) tools = [ { "type": "function", "function": { "name": "get_weather", "description": "Get weather of an location, the user shoud supply a location first", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA", } }, "required": ["location"] }, } }, ] messages = [{"role": "user", "content": "How's the weather in Hangzhou?"}] message = send_messages(messages) print(f"User>\t {messages[0]['content']}") tool = message.tool_calls[0] messages.append(message) messages.append({"role": "tool", "tool_call_id": tool.id, "content": "24℃"}) message = send_messages(messages) print(f"Model>\t {message.content}")
Author
Owner

@difsch2077 commented on GitHub (Dec 26, 2024):

不小心重复了,关闭此项

<!-- gh-comment-id:2562991167 --> @difsch2077 commented on GitHub (Dec 26, 2024): 不小心重复了,关闭此项
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
deepseek-ai/DeepSeek-V3#4
No description provided.