Skip to content

Commit d306046

Browse files
committed
fix: fixed up the tempalte variable example
1 parent 5af2b96 commit d306046

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

Diff for: docs/integrations/genai.md

+19-6
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ Template variables make it easy to reuse prompts with different values. This is
123123
from google import genai
124124
import instructor
125125
from pydantic import BaseModel
126+
from google.genai import types
126127

127128

128129
# Define your Pydantic model
@@ -138,37 +139,49 @@ client = instructor.from_genai(client, mode=instructor.Mode.GENAI_TOOLS)
138139
# Single string (converted to user message)
139140
response = client.chat.completions.create(
140141
model="gemini-2.0-flash-001",
141-
messages=["Jason is 25 years old"],
142+
messages=["{{name}} is {{ age }} years old"],
142143
response_model=User,
144+
context={
145+
"name": "Jason",
146+
"age": 25,
147+
},
143148
)
144149

145150
print(response)
146-
#> name='Jason' age=25
151+
# > name='Jason' age=25
147152

148153
# Standard format
149154
response = client.chat.completions.create(
150155
model="gemini-2.0-flash-001",
151-
messages=[{"role": "user", "content": "Jason is 25 years old"}],
156+
messages=[{"role": "user", "content": "{{ name }} is {{ age }} years old"}],
152157
response_model=User,
158+
context={
159+
"name": "Jason",
160+
"age": 25,
161+
},
153162
)
154163

155164
print(response)
156-
#> name='Jason' age=25
165+
# > name='Jason' age=25
157166

158167
# Using genai's Content type
159168
response = client.chat.completions.create(
160169
model="gemini-2.0-flash-001",
161170
messages=[
162171
genai.types.Content(
163172
role="user",
164-
parts=[genai.types.Part.from_text(text="Jason is 25 years old")],
173+
parts=[genai.types.Part.from_text(text="{{name}} is {{age}} years old")],
165174
)
166175
],
167176
response_model=User,
177+
context={
178+
"name": "Jason",
179+
"age": 25,
180+
},
168181
)
169182

170183
print(response)
171-
#> name='Jason' age=25
184+
# > name='Jason' age=25
172185
```
173186

174187
## Validation and Retries

0 commit comments

Comments
 (0)