mirror of
https://github.com/kvcache-ai/ktransformers.git
synced 2025-09-05 20:19:51 +00:00
45 lines
No EOL
1.2 KiB
Python
45 lines
No EOL
1.2 KiB
Python
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="placeholder",
|
|
base_url="http://0.0.0.0:10002/v1",
|
|
)
|
|
|
|
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']}")
|
|
print(message)
|
|
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}") |