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?
gpt-3.5-turbo
gpt-4-turbo
gpt-4
Other (Claude 3.5 Sonnet)
Describe the bug
When trying to output list[Union[BaseModelA, BaseModelB] in a streamed response, the BaseModels do not become Partial models like they're supposed to. This results in a validation error when reading from the stream.
To Reproduce
importasyncioimportosfromtypingimportUnionimportinstructorfrompydanticimportBaseModel, FieldclassHighway(BaseModel):
name: str=Field(
...,
description="The name of the highway.",
)
classCar(BaseModel):
name: str=Field(
...,
description="The name of the car.",
)
classExit(BaseModel):
name: str=Field(
...,
description="The name of the exit.",
)
classPopulatedRoad(BaseModel):
steps: list[Union[Exit, Car]] =Field(
...,
description="The steps of the road.",
)
if__name__=="__main__":
asyncdefmain():
fromanthropicimportAsyncAnthropicasync_client=instructor.from_anthropic(
AsyncAnthropic(
api_key=os.getenv("ANTHROPIC_API_KEY"),
),
mode=instructor.Mode.ANTHROPIC_JSON,
)
response_gen=async_client.messages.create_partial(
system="You are a helpful assistant that creates populated roads.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "Create a populated road. Has to have at least 10 unique steps.",
}
],
}
],
model="claude-3-5-sonnet-20241022",
response_model=PopulatedRoad,
max_tokens=2000,
stream=True,
)
asyncforchunkinresponse_gen:
print(chunk)
asyncio.run(main())
Expected behavior
Current Behavior
The text was updated successfully, but these errors were encountered:
What Model are you using?
Describe the bug
When trying to output
list[Union[BaseModelA, BaseModelB]
in a streamed response, the BaseModels do not become Partial models like they're supposed to. This results in a validation error when reading from the stream.To Reproduce
Expected behavior
Current Behavior
The text was updated successfully, but these errors were encountered: