기능 호출
알아채다
deepseek-chat
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}")
1.
2.
get_weather({location: 'Hangzhou'})
3.
get_weather({location: 'Hangzhou'})
모델에 결과를 제공합니다4.
get_weather
함수의 기능을 사용자가 제공해야합니다. 모델 자체는 특정 기능을 실행하지 않습니다.Modified at 2025-02-06 09:55:58