Groq x st.write_stream - Space Chat ๐Ÿ›ธ

One word at a time output like ChatGPT using Groq with st.write_stream.

The app: https://space-chat.streamlit.app/

The core code to parse:

def parse_groq_stream(stream):
    for chunk in stream:
        if chunk.choices:
            if chunk.choices[0].delta.content is not None:
                yield chunk.choices[0].delta.content

stream = groq_client.chat.completions.create(
    model=st.session_state["groq_model"],
    messages=[
      {"role": m["role"], "content": m["content"]}
      for m in st.session_state.messages
    ],
    temperature=0.0,
    stream=True,
)

response = st.write_stream(parse_groq_stream(stream))

Github repo: GitHub - parker84/space-chat: Space chatbot that uses Groq + streamlit and generates responses one word at a time like ChatGPT.

Hereโ€™s what the app looks like:

2 Likes

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