from portkey_ai import Portkey
portkey = Portkey(
api_key="PORTKEY_API_KEY",
provider="anthropic"
)
completion = portkey.chat.completions.create(
model="claude-3-5-sonnet-20241022",
messages=[
{"role": "system", "content": "Extract the event information."},
{"role": "user", "content": "Alice and Bob are going to a science fair on Friday."}
],
response_format={
"type": "json_schema",
"json_schema": {
"name": "event_extraction",
"schema": {
"type": "object",
"properties": {
"location": { "type": "string" },
"date": { "type": "string" },
"participants": { "type": "array", "items": { "type": "string" } }
},
"required": ["location", "date", "participants"],
"additionalProperties": False
},
"strict": True
}
}
)
print(completion.choices[0].message.content)