NO function_call
#11
by
justinliu12138
- opened
when using the model,I can't use the function_call(vllm)
client = OpenAI(
base_url="http://127.0.0.1:8000/v1",
api_key="anything"
)
model = "deepseekV3-671b-awq"
def get_weather(latitude, longitude):
response = requests.get(f"https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}¤t=temperature_2m,wind_speed_10m&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m")
data = response.json()
return data['current']['temperature_2m']
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current temperature for provided coordinates in celsius.",
"parameters": {
"type": "object",
"properties": {
"latitude": {"type": "number"},
"longitude": {"type": "number"}
},
"required": ["latitude", "longitude"],
"additionalProperties": False
},
#"strict": False
}
}]
messages = [{"role": "user", "content":"what's the weather in paris?"}]
completion = client.chat.completions.create(
model=model,
messages=messages,
tools=tools,
stream=False
)
# for chunk in completion:
# print(chunk)
print("*"*40+model+"*"*40)
print(completion)
print("*"*40+model+"*"*40)
tool_call = completion.choices[0].message.tool_calls[0]
args = json.loads(tool_call.function.arguments)
result = get_weather(args["latitude"], args["longitude"])
messages.append(completion.choices[0].message)
messages.append({
"role": "tool",
"tool_call_id": tool_call.id,
"content": str(result)
})
completion_2 = client.chat.completions.create(
model=model,
messages=messages,
tools=tools,
stream=False
)
print("*"*40+model+"*"*40)
print(completion_2)
print("*"*40+model+"*"*40)
end_time = time.time()
print(end_time-start_time)