You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have tried asking for help in the community on discord or discussions and have not received a response.
I have tried searching the documentation and have not found an answer.
What Model are you using?
Gemini 1.5 Pro (on Vertex AI)
Describe the bug
Since Vertex AI doesn't support Optional, the documentation recommends we use Field(default=0) as a workaround. But it doesn't work for me.
To Reproduce
The following code fails, but if I remove the default=0 it works.
client=instructor.from_vertexai(gm.GenerativeModel("gemini-1.5-pro"))
classUserModel(BaseModel):
age: int=Field(description="age", default=0)
response=client.create(
messages=[
{
"role": "user",
"content": """Jason is 20 years old""",
},
],
response_model=UserModel,
)
Traceback (most recent call last):
File "/path/to/main.py", line 27, in <module>
response = client.create(
^^^^^^^^^^^^^^
File "/path/to/venv/lib/python3.12/site-packages/instructor/client.py", line 91, in create
return self.create_fn(
^^^^^^^^^^^^^^^
File "/path/to/venv/lib/python3.12/site-packages/instructor/patch.py", line 140, in new_create_sync
response_model, new_kwargs = handle_response_model(
^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/venv/lib/python3.12/site-packages/instructor/process_response.py", line 447, in handle_response_model
contents, generation_config = vertexai_process_json_response(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/venv/lib/python3.12/site-packages/instructor/client_vertexai.py", line 84, in vertexai_process_json_response
response_schema = _create_gemini_json_schema(model)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/path/to/venv/lib/python3.12/site-packages/instructor/client_vertexai.py", line 18, in _create_gemini_json_schema
"required": schema_without_refs["required"],
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: 'required'
What Model are you using?
Describe the bug
Since Vertex AI doesn't support Optional, the documentation recommends we use
Field(default=0)
as a workaround. But it doesn't work for me.To Reproduce
The following code fails, but if I remove the
default=0
it works.This is the line that causes the exception:
instructor/instructor/client_vertexai.py
Line 18 in 8513e6e
Expected behavior
no exception
The text was updated successfully, but these errors were encountered: