import json
import httpx
from openai import OpenAI
# 必须替换整个字符串为实际密钥;不要保留“你的密钥”等中文占位文字。
API_KEY = "sk-your-api-key"
# 按模型广场展示的完整名称替换;当前示例使用 gpt-5.4-mini。
MODEL = "gpt-5.4-mini"
client = OpenAI(
api_key=API_KEY,
base_url="https://moxus.cloud/v1",
# 直接连接 Moxus AI,不读取系统或终端代理环境变量。
http_client=httpx.Client(trust_env=False, timeout=60.0),
)
resp = client.chat.completions.create(
model=MODEL,
messages=[
{"role": "user", "content": "张三今年28岁,是一名工程师。"}
],
response_format={
"type": "json_schema",
"json_schema": {
"name": "person_info",
"strict": True,
"schema": {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer"},
"occupation": {"type": "string"},
},
"required": ["name", "age", "occupation"],
"additionalProperties": False,
},
},
},
)
data = json.loads(resp.choices[0].message.content)
print(data["name"], data["age"], data["occupation"])