mirror of
https://github.com/kvcache-ai/ktransformers.git
synced 2026-05-03 14:11:15 +00:00
[Feature] Add SFT feature for KT
This commit is contained in:
parent
b09e99fd87
commit
4421d48108
445 changed files with 112306 additions and 0 deletions
45
KT-SFT/ktransformers/tests/function_call_test.py
Normal file
45
KT-SFT/ktransformers/tests/function_call_test.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
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}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue