Function Calling & Structured Outputs
ModelMart fully supports Function Calling (Tools) and JSON Schema Structured Outputs.
1. Tool Calling Example (Python)
from openai import OpenAI import json client = OpenAI( api_key="mm_live_xxxxxxxxxxxx", base_url="https://api.modelmart.io.vn/v1" ) tools = [ { "type": "function", "function": { "name": "get_weather", "description": "Get real-time weather for a given city.", "parameters": { "type": "object", "properties": { "city": {"type": "string"} }, "required": ["city"] } } } ] messages = [{"role": "user", "content": "What's the weather in Tokyo?"}] response = client.chat.completions.create( model="claude-sonnet-5", messages=messages, tools=tools ) tool_call = response.choices[0].message.tool_calls[0] print(f"Tool called: {tool_call.function.name} with args: {tool_call.function.arguments}")
2. Structured JSON Outputs
Enforce strict output compliance with JSON Schema:
response = client.chat.completions.create( model="gpt-5.6-sol", messages=[ {"role": "user", "content": "Extract: Alice, 30, Software Engineer in London."} ], response_format={ "type": "json_schema", "json_schema": { "name": "person", "strict": True, "schema": { "type": "object", "properties": { "name": {"type": "string"}, "age": {"type": "integer"}, "occupation": {"type": "string"}, "city": {"type": "string"} }, "required": ["name", "age", "occupation", "city"], "additionalProperties": False } } } ) print(response.choices[0].message.content)