import os
from openai import AzureOpenAI
from pydantic import BaseModel
client = AzureOpenAI(
azure_endpoint = os.getenv(“AZURE_OPENAI_ENDPOINT”),
api_key=os.getenv(“AZURE_OPENAI_API_KEY”),
api_version=os.getenv(“AZURE_OPENAI_API_VERSION”)
)
class Step(BaseModel):
explanation: str
output: str
class MathReasoning(BaseModel):
steps: list[Step]
final_answer: str
response = client.chat.completions.create(
model=“gpt-4o-mini”,
messages=[
{“role”: “system”, “content”: “You are a helpful math tutor. Guide the user through the solution step by step.”},
{“role”: “user”, “content”: “how can I solve 8x + 7 = -23”}
],
response_format=MathReasoning,
)
print(response.choices[0].message.parsed)
gives
TypeError: Object of type ModelMetaclass is not JSON serializable