Create a string field from an iterable string field as it is consumed

22 views Asked by At

I have the following model:

from pydantic import BaseModel
from collections.abc import AsyncIterable

class Message(BaseModel):
    content_iterable: AsyncIterable[str]
    content: str | None = None

content_iterable is an iterator that needs to be consumed by a client.

I would like content to be set as the full result of content_iterable once it has been consumed.

A client to my API will be consuming content_iterable, so I cannot simply consume it in my app and then set the result to content.

Is this possible?

0

There are 0 answers