関数・ツール呼び出し

154モデルが関数を呼び出し可能。

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)
→ ストリーミング応答 → 構造化出力 チャット