(SOLVED) Error: Your app is having trouble loading the streamlit_chat.streamlit_chat component

Hello, I am trying to get a simple streamlit app working. I am running VS Code on windows 11. I am running the code in a virtual python environment that has python 3.11. I am using 1.27.2 of Streamlit. There are no errors in the command line from where I launched the app. I have tried different browsers, incognito mode, rebooting, and switching server ports - no luck. The code is from an online course and a couple of other windows users have the same issue.

from typing import Set

from backend.core import run_llm
import streamlit as st
from streamlit_chat import message

st.header("LangChain Udemy Course- Documentation Helper Bot")

prompt = st.text_input("Prompt", placeholder="Enter your prompt here..")

if "user_prompt_history" not in st.session_state:
    st.session_state["user_prompt_history"] = []

if "chat_answers_history" not in st.session_state:
    st.session_state["chat_answers_history"] = []

def create_sources_string(source_urls: Set[str]) -> str:
    if not source_urls:
        return ""
    sources_list = list(source_urls)
    sources_string = "sources:\n"
    for i, source in enumerate(sources_list):
        sources_string += f"{i+1}. {source}\n"
    return sources_string

if prompt:
    with st.spinner("Generating response.."):
        generated_response = run_llm(query=prompt)
        sources = set(
            [doc.metadata["source"] for doc in generated_response["source_documents"]]

        formatted_response = (
            f"{generated_response['result']} \n\n {create_sources_string(sources)}"


if st.session_state["chat_answers_history"]:
    for generated_response, user_query in zip(
        message(user_query, is_user=True)


Found the error. Streamlit-chat needed to be set to

Glad to hear that you’ve found a solution. Streamlit also has built-in chat elements namely st.chat_input for accepting user input prompt and st.chat_message as a container for displaying app output or user query.

More info in the Docs:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.