response = client.chat.completions.create(
model="gpt-oss-120b",
messages=[
{"role": "user", "content": "Extract entities from: 'Apple acquired Beats in 2014 for $3B.'"}
],
response_format={
"type": "json_schema",
"json_schema": {
"name": "entity_extraction",
"strict": True,
"schema": {
"type": "object",
"properties": {
"company": {"type": "string"},
"acquired": {"type": "string"},
"year": {"type": "integer"},
"amount_usd": {"type": "string"}
},
"required": ["company", "acquired", "year", "amount_usd"],
"additionalProperties": False
}
}
}
)
import json
data = json.loads(response.choices[0].message.content)
# {"company": "Apple", "acquired": "Beats", "year": 2014, "amount_usd": "$3B"}