import os
import json
from openai import OpenAI
client = OpenAI(
api_key=os.environ["API_KEY"],
base_url="https://api.siflow.cn/model-api",
)
resp = client.chat.completions.create(
model="MiniMaxAI/MiniMax-M2.7",
messages=[
{
"role": "system",
"content": "You are a helpful assistant designed to output JSON.",
},
{
"role": "user",
"content": "What is the capital of France? Please respond as {\"capital\": ...}",
},
],
response_format={"type": "json_object"},
temperature=0.3,
max_completion_tokens=256,
stream=False,
)
raw = resp.choices[0].message.content
print("RAW:", raw)
try:
data = json.loads(raw)
print("PARSED:", data)
except json.JSONDecodeError:
print("JSON parsing failed; retry with lower temperature or higher max_completion_tokens")