Git Product home page Git Product logo

chatstream's Introduction

chatstream for Shiny for Python

The chatstream package provides a Shiny for Python module for building AI chat applications. Please keep in mind that this is very much a work in progress, and the API is likely to change.

See this post on the Shiny blog to see some examples in action!

Chatstream currently supports the OpenAI API. To use this, you must have an OpenAI API key. You can get one from the OpenAI or from Azure's OpenAI Service. (Note that if you have use Azure, you will need to point the applications to the Azure endpoint instead of the default OpenAI endpoint.)

Installation

The chatstream package is not on PyPI, but can be installed with pip:

pip install chatstream@git+https://github.com/wch/chatstream.git

Alternatively, if you'd like to develop a local copy of the package, first clone the repository and then install it with pip:

cd chatstream
pip install -e .[dev]

Running examples

Before running any examples, you must set an environment variable named OPENAI_API_KEY with your OpenAI API key.

You can set the environment variable with the following command:

export OPENAI_API_KEY="<your_openai_api_key>"

Then run:

shiny run examples/basic/app.py --launch-browser

Some examples (like recipes) have a requirements.txt file. For those examples, first install the requirements, then run the application as normal:

pip install -r examples/recipes/requirements.txt
shiny run examples/recipes/app.py --launch-browser

FAQ

  • Does this work with Shinylive? It almost does. The openai package has dependencies which do not install on Pyodide, but chatstream currently has an openai_pyodide shim which uses the browser's fetch API. However, there is one more hurdle: the tiktoken package (which counts the number of tokens used by a piece of text) needs to be built to run on Pyodide.

  • Does this work with langchain? It currently does not. Note that most of the langchain interfaces do not support streaming responses, so instead of showing responses as each word comes in, there is a wait and then the entire response arrives at once.

chatstream's People

Contributors

jcheng5 avatar wch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

chatstream's Issues

How would you incorporate langchain with memory in chatstream?

As mentioned, I built something similar with python's streamlit chat + langchain + pdf loader. The memory for this application was made by adding it to streamlit session. Here is some of my code for the memory with streamlit chat:

   with st.sidebar.form(key="message_form", clear_on_submit=True):
        user_input = st.text_input("Type your message here...", value="", key="user_input")
        submit_button = st.form_submit_button("Send")    
    if submit_button:
        st.session_state.messages.append(HumanMessage(content=user_input))
        with st.spinner("Thinking..."): 
            response = chat(st.session_state.messages)
        st.session_state.messages.append(AIMessage(content=response.content))

If I wanted to use chatstream instead, how would I handle this?

doc_query just keeps asking how it can assist me?

I'm running the example doc_query Shiny app. I uploaded a PDF (a downloaded copy of the Framingham City Charter) to the app, and the app seemed to show that the file uploaded properly and was indexed. However, every time I ask a question, I just get "How can I assist you?" back from the app. I did export my OpenAI key. (The recipes example is working fine, though). I was hoping to mention this in an article I'm writing but want to get it working first!

[
  {
    "role": "user",
    "content": "What is the mayor's salary?"
  },
  {
    "role": "assistant",
    "content": "How can I assist you today?"
  },
  {
    "role": "user",
    "content": "What is the mayor's salary?"
  },
  {
    "role": "assistant",
    "content": "How can I assist you today?"
  },
  {
    "role": "user",
    "content": "What is a city councilor's salary?"
  },
  {
    "role": "assistant",
    "content": "How can I assist you today?"
  }
]

Blank screens?

Hi folks,

I just wanted to start messing around with this, and I get blank screens for the UI component of chatstream (the part I'm interested in, I could live with or without the python). I've tried to replicate both the examples/basic/app.py, which shows only a blank screen, and the examples/controls/app.py, which shows only the right side panel of controls.

I downloaded via pip install chatstream@git+https://github.com/wch/chatstream.git into a virtual environment on Python 3.9.6, and worked with this on a Ubuntu 18.0 server.

My python libraries in the virtual environment:

              package  version               requirement
1             aiohttp    3.8.4            aiohttp==3.8.4
2           aiosignal    1.3.1          aiosignal==1.3.1
3               anyio    3.7.0              anyio==3.7.0
4             appdirs    1.4.4            appdirs==1.4.4
5             asgiref    3.7.2            asgiref==3.7.2
6       async-timeout    4.0.2      async-timeout==4.0.2
7               attrs   23.1.0             attrs==23.1.0
8             certifi 2023.5.7         certifi==2023.5.7
9  charset-normalizer    3.1.0 charset-normalizer==3.1.0
10              click    8.1.3              click==8.1.3
11        contextvars      2.4          contextvars==2.4
12     exceptiongroup    1.1.1     exceptiongroup==1.1.1
13         frozenlist    1.3.3         frozenlist==1.3.3
14                h11   0.14.0               h11==0.14.0
15          htmltools    0.2.1          htmltools==0.2.1
16               idna      3.4                 idna==3.4
17         immutables     0.19          immutables==0.19
18      linkify-it-py    2.0.2      linkify-it-py==2.0.2
19     markdown-it-py    2.2.0     markdown-it-py==2.2.0
20    mdit-py-plugins    0.3.5    mdit-py-plugins==0.3.5
21              mdurl    0.1.2              mdurl==0.1.2
22          multidict    6.0.4          multidict==6.0.4
23              numpy   1.24.3             numpy==1.24.3
24             openai   0.27.7            openai==0.27.7
25          packaging     23.1           packaging==23.1
26   python-multipart    0.0.6   python-multipart==0.0.6
27              regex 2023.5.5           regex==2023.5.5
28           requests   2.31.0          requests==2.31.0
29              shiny    0.3.3              shiny==0.3.3
30            sniffio    1.3.0            sniffio==1.3.0
31          starlette   0.27.0         starlette==0.27.0
32           tiktoken    0.4.0           tiktoken==0.4.0
33               tqdm   4.65.0              tqdm==4.65.0
34  typing_extensions    4.6.2  typing_extensions==4.6.2
35        uc-micro-py    1.0.2        uc-micro-py==1.0.2
36            urllib3    2.0.2            urllib3==2.0.2
37            uvicorn   0.22.0           uvicorn==0.22.0
38         websockets   11.0.3        websockets==11.0.3
39               yarl    1.9.2               yarl==1.9.2

Timeline for adding to pypi?

Do you think that chatstream will be added to pypi anytime in the near future, or is it still under heavy development and not yet ready for publishing to pypi?

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.