@@ -98,16 +98,17 @@ def test_image_prompt():
98
98
assert response .token_details is None
99
99
100
100
101
+ class Dog (BaseModel ):
102
+ name : str
103
+ age : int
104
+ bio : str
105
+
106
+
101
107
@pytest .mark .vcr
102
108
def test_schema_prompt ():
103
109
model = llm .get_model ("claude-3.7-sonnet" )
104
110
model .key = model .key or ANTHROPIC_API_KEY
105
111
106
- class Dog (BaseModel ):
107
- name : str
108
- age : int
109
- bio : str
110
-
111
112
response = model .prompt ("Invent a good dog" , schema = Dog )
112
113
dog = json .loads (response .text ())
113
114
assert dog == {
@@ -117,6 +118,30 @@ class Dog(BaseModel):
117
118
}
118
119
119
120
121
+ @pytest .mark .vcr
122
+ @pytest .mark .asyncio
123
+ async def test_schema_prompt_async ():
124
+ model = llm .get_async_model ("claude-3.7-sonnet" )
125
+ model .key = model .key or ANTHROPIC_API_KEY # don't override existing key
126
+ response = await model .prompt ("Invent a terrific dog" , schema = Dog )
127
+ dog_json = await response .text ()
128
+ dog = json .loads (dog_json )
129
+ assert dog == {
130
+ "name" : "Maximus Thunder" ,
131
+ "age" : 3 ,
132
+ "bio" : (
133
+ "Maximus Thunder is an extraordinary golden retriever with a natural "
134
+ "talent for search and rescue operations. His keen sense of smell "
135
+ "can detect people trapped under debris from over a mile away. When "
136
+ "he's not saving lives, Maximus enjoys surfing at the beach and has "
137
+ "won three local dog surfing competitions. He's also incredibly "
138
+ "gentle with children and regularly visits hospitals as a therapy "
139
+ "dog. His favorite treat is peanut butter, and he has a unique howl "
140
+ 'that sounds remarkably like he\' s saying "hello."'
141
+ ),
142
+ }
143
+
144
+
120
145
@pytest .mark .vcr
121
146
def test_prompt_with_prefill_and_stop_sequences ():
122
147
model = llm .get_model ("claude-3.5-haiku" )
0 commit comments