import jsonimport openaiclient = openai.OpenAI( base_url='https://api.inference.wandb.ai/v1', api_key="<your-api-key>", # https://wandb.ai/settings で APIキー を作成してください)response = client.chat.completions.create( model="openai/gpt-oss-20b", messages=[ {"role": "system", "content": "You are a helpful assistant that outputs JSON."}, {"role": "user", "content": "Give me a list of three fruits with their colors."}, ], response_format={"type": "json_object"} # これにより JSON モードが有効になります)content = response.choices[0].message.contentparsed = json.loads(content)print(parsed)
不正なコードを報告
コピー
AIに質問
curl https://api.inference.wandb.ai/v1/chat/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer <your-api-key>" \ -d '{ "model": "openai/gpt-oss-20b", "messages": [ {"role": "system", "content": "You are a helpful assistant that outputs JSON."}, {"role": "user", "content": "Give me a list of three fruits with their colors."}, ], "response_format": {"type": "json_object"} }'