Skip to content

Stream structured data #238

@gshotwell

Description

@gshotwell

It would be good if there were an easy way to stream strutured data. For example I have an application that generates SQL along with an explanation. I stream the explanation to the chat window while extracting the SQL to a coding window using this method:


@chat.transform_assistant_response
    async def extract_sql(content: str, chunk: str, done: bool):
        # When streaming is complete, extract SQL from code blocks
        if done and content:
            import re

            # Look for SQL code blocks
            sql_pattern = r"```sql\s*(.*?)```"
            matches = re.findall(sql_pattern, content, re.DOTALL)

            if matches:
                # Take the first SQL block found
                sql_code.set(matches[0].strip())

        # Always return content as-is for streaming display
        return content

Since this method is deprecated in favor of a chatlas solution, it would be good to have a documented method for streaming structured data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions