Coder Social home page Coder Social logo

st-chat-message's Introduction

st-chat-message

Description

This is a simple chat message component for streamlit. It is based on the streamlit-chat component, trying to be as compatible as possible, but it adding a few features:

  • Markdown support
  • LaTeX support
  • Tables

Installation

pip install st-chat-message

or

poetry add st-chat-message

Usage

import streamlit as st
from st_chat_message import message

message("Hello world!", is_user=True)
message("Hi")

img.png

Buiding from source

Prerequisites

  • nodejs >= 18.x
  • yarn >= 1.22.x
  • poetry >= 1.2.x
  • python >= 3.8.x

Building

./build.sh

Publishing

poetry publish 

License

This project is licensed under the MIT License - see the LICENSE file for details

st-chat-message's People

Contributors

undo76 avatar

Stargazers

Marc Hadfield avatar  avatar  avatar Josh Ogden avatar  avatar Edward Lo avatar KID avatar Bob Seaton avatar Aniket Yevankar avatar MJ Shin avatar umeco avatar Lixiang avatar  avatar Hongxuan Li avatar Paraskevi Kivroglou avatar Shrimanta Satpati avatar Nurul B. Ibrahim avatar  avatar Se June Joo avatar kota-matsuo avatar 雨渐渐 avatar  avatar Paul Spedding avatar Dexter Tortoriello avatar Vladislav Sorokin avatar Jett Wang avatar  avatar  avatar Josef Strunc avatar  avatar Tim avatar Franky1 avatar Sungju Kim avatar Stephen Bonifacio avatar  avatar Lucy Oh avatar  avatar  avatar yiran.vang avatar  avatar

Watchers

Zhijun avatar  avatar

st-chat-message's Issues

Stream Problem

Hello, thank you for providing such a great chat-message library. I have understood how to use it correctly according to your example and can also use stream.

But when I use it with LangChain's CallBack, I directly use st.experimental_rerun() will cause the entire script to run again, making the langchain callBack function unable to continue executing, making it permanently stuck in the first place. Here is my code:

class StreamHandler(BaseCallbackHandler):
    def __init__(self, stream_key: str, initial_text=""):
        # self.text = initial_text
        self.key = stream_key

    def on_llm_start(
        self,
        *args,
        **kwargs: Any,
    ) -> Any:
        st.session_state.current_text = ''
        st.session_state.partial = True
        message(st.session_state.current_text, key=key, partial=st.session_state.partial)


    def on_llm_new_token(self, token: str, **kwargs) -> None:
        st.session_state.current_text += token
        st.experimental_rerun()

    def on_llm_end(
        self,
        response: LLMResult,
        **kwargs
    ):
        st.session_state.partial = False

key = f"message_{len(st.session_state.langchain_messages) + 1}"
stream_handler = StreamHandler(key)
response = agent.run(prompt, callbacks=[stream_handler])

So I'm thinking, is there a way for messages to control internal state updates through Python? Just like:

class StreamHandler(BaseCallbackHandler):
    def __init__(self, container, initial_text=""):
        self.container = container
        self.text = initial_text

    def on_llm_new_token(self, token: str, **kwargs) -> None:
        self.text += token
        self.container.markdown(self.text)

with st.chat_message("assistant"):
            stream_handler = StreamHandler(st.empty())
            response = st.session_state.agent.run(prompt, callbacks=[stream_handler])

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.