Gọi công cụ & hàm
Cho phép 154 model gọi hàm của bạn. Vòng lặp tác tử đầy đủ, gọi song song.
Define a tool
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather in a city.",
"parameters": {
"type": "object",
"properties": {
"city": { "type": "string" },
"unit": { "type": "string", "enum": ["c", "f"] }
}, "required": ["city"]
}
}
}] Python: full agentic loop
from openai import OpenAI client = OpenAI(base_url="https://meshtok.com/v1", api_key="sk-...") messages = [{"role": "user", "content": "What's the weather in Tokyo?"}] resp = client.chat.completions.create(model="deepseek/deepseek-v4-pro", messages=messages, tools=tools) tool_call = resp.choices[0].message.tool_calls[0] import json result = get_weather(**json.loads(tool_call.function.arguments)) messages.append(resp.choices[0].message) messages.append({"role": "tool", "tool_call_id": tool_call.id, "content": json.dumps(result)}) final = client.chat.completions.create(model="deepseek/deepseek-v4-pro", messages=messages) print(final.choices[0].message.content)