Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chain of Thought UI crashes when langchain steps output dicts instead of strings #291

Closed
mpartel opened this issue Aug 18, 2023 · 3 comments · Fixed by #292
Closed

Chain of Thought UI crashes when langchain steps output dicts instead of strings #291

mpartel opened this issue Aug 18, 2023 · 3 comments · Fixed by #292

Comments

@mpartel
Copy link

mpartel commented Aug 18, 2023

With [Async]LangchainCallbackHandler, when my intermediate steps output dicts instead of strings, the UI crashes.

Repro:

  • Use the following code.
  • Input a message.
  • Click on "Took 1 step".
  • Get "Something went wrong." with JS console saying "TypeError: r.trim is not a function".
import chainlit as cl
from langchain.chains import TransformChain

@cl.on_message
async def main(message: str):
    def transform(inputs):
        return {
            'output': {
                'structured': {
                    'report': 'Done'
                }
            }
        }
    chain = TransformChain(
        input_variables=['text'],
        output_variables=['output'],
        transform=transform,
    )
    result = chain.run({'text': message}, callbacks=[cl.LangchainCallbackHandler()])
    return await cl.Message(content=result['structured']['report']).send()

(Possibly related typing bug in LangChain 0.0.267, but I'm almost certain their intention is to allow intermediate steps to output whatever.)

@willydouhard
Copy link
Collaborator

Interesting, will investigate

@willydouhard
Copy link
Collaborator

Screenshot 2023-08-18 at 17 10 22 Okay so this chain outputs a json object. Currently the Message component in the UI only accept strings. What would be the expected behavior here? Display the json object in a code block?

@mpartel
Copy link
Author

mpartel commented Aug 18, 2023

Yes, that sounds good 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants