In my experience, LangChain is a very complex HIGH LEVEL abstraction, and if you follow their example exactly, itâs easy to get good results, but if you try to modify something yourself, it often brings very complicated bugs because they hide too much information in it.
Just by looking at this part of your code, I have no idea what is happening. Also, I havenât obtained the Azure OpenAI API key yet, so I cannot test AzureChatOpenAI either.
If I were to debug it, I think I would need to first test if the response is being properly outputted when streaming is set to False.
If everything mentioned above is working fine, I noticed that the error message states: âObject of type StreamHandler is not JSON serializable.â Itâs possible that the information returned by the AI is in JSON format. In that case, you might need to extract a specific part of the JSON, such as the text or token, and then pass it to the StreamHandler for processing. You can refer to the âoutput parserâ reference for guidance: https://python.langchain.com/en/latest/modules/prompts/output_parsers/getting_started.html
Or, if your entire programâs code is not very long, you may want to copy all the code along with the error messages into GPT-4 or Claude 100k and let GPT-4 do the debug.
In fact, I wrote this StreamHandler with the help of GPT-4. I gave GPT-4 the callback description page and let it come up with it. They are pretty good.
Hey @goldengrape,
Thanks for your suggestion. I tried the langchainâs built-in StreamingStdOutCallbackHandler to check if the streaming output worked correctly. I was able to stream the response on the terminal. But, as mentioned early I was looking for a way to stream the output on Streamlit. I was able to do this by adopting a custom stream_handler (StreamlitCallbackHandler(BaseCallbackHandler)). Then I used a callback_manager to the LLM before running the SequentialChain().