Skip to content

Issue on docs: "Text to SQL" example crashes without array check #261

@anselanza

Description

@anselanza

Path: /examples/openai-sql

This is a nice example, but I noticed that the following line will throw an error and crash the program:

if token := part.choices[0].delta.content or "":

The problem is that the part.choices may be zero length initially (first part of the stream), and therefore throws an IndexError: list index out of range error, instead of substituting the default ("") and proceeding.

The following additional check makes everything work as expected:

if part.choices and (token := part.choices[0].delta.content or ""):

Hopefully this is helpful for another newbie to Chainlit such as my self!

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