Skip to content

Streaming with Literal["Value"] = "value" #2054

@tamis-laan

Description

@tamis-laan

I have something similar to the following:

class Person(BaseModel):
  type: Literal["Person"] = "Person"
  name: str
  age: int

When streaming I get:

{ "name": " Joh", "age": {} }
...
{ "name": " Johny Stevenson", "age": 31 }
{ "name": " Johny Stevenson", "age": 31, "type": "Person" }

This "type": "Person" pops up at the end of the stream, but it is known before hand.

In my case I need type for rendering the content on the frontend it should be there in the partial response regardless because it's known before hand.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpythonPull requests that update python codequestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions