forked from Azure-Samples/azure-openai-entity-extraction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_githubmodels.py
34 lines (26 loc) · 840 Bytes
/
basic_githubmodels.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
import rich
from openai import OpenAI
from pydantic import BaseModel
client = OpenAI(
base_url="https://models.inference.ai.azure.com",
api_key=os.environ["GITHUB_TOKEN"],
# Specify the API version to use the Structured Outputs feature
default_query={"api-version": "2024-08-01-preview"},
)
model_name = "gpt-4o"
class CalendarEvent(BaseModel):
name: str
date: str
participants: list[str]
completion = client.beta.chat.completions.parse(
model=model_name,
messages=[
{"role": "system", "content": "Extract the event information."},
{"role": "user", "content": "Alice and Bob are going to a science fair on Friday."},
],
response_format=CalendarEvent,
)
output = completion.choices[0].message.parsed
event = CalendarEvent.model_validate(output)
rich.print(event)