Skip to content

Commit

Permalink
fix: Zoo example
Browse files Browse the repository at this point in the history
  • Loading branch information
Josephasafg committed Aug 21, 2024
1 parent 5daa2d2 commit e2952a8
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions examples/studio/chat/chat_response_format.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
from enum import Enum

from pydantic import BaseModel, ValidationError
from pydantic import BaseModel

from ai21 import AI21Client
from ai21.logger import set_verbose
Expand Down Expand Up @@ -28,7 +29,7 @@ class ZooTicketsOrder(BaseModel):
ChatMessage(
role="user",
content="Please create a JSON object for ordering zoo tickets for September 22, 2024, "
f"for myself and two kids, based on the following JSON schema: {ZooTicketsOrder.model_json_schema()}.",
f"for myself and two kids, based on the following JSON schema: {ZooTicketsOrder.schema()}.",
)
]

Expand All @@ -42,11 +43,5 @@ class ZooTicketsOrder(BaseModel):
response_format=ResponseFormat(type="json_object"),
)

print(response)

try:
order = ZooTicketsOrder.model_validate_json(response.choices[0].message.content)
print("Zoo tickets order details JSON:")
print(order)
except ValidationError as exc:
print(exc)
zoo_order_json = json.loads(response.choices[0].message.content)
print(zoo_order_json)

0 comments on commit e2952a8

Please sign in to comment.