Chatstream
Example Shiny for Python app which talks to the OpenAI API
Install / Use
/learn @wch/ChatstreamREADME
Note: Chatstream is now out of date. Instead, please use the ui.Chat() component that is now bundled with Shiny for Python.
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
openaipackage has dependencies which do not install on Pyodide, but chatstream currently has anopenai_pyodideshim which uses the browser'sfetchAPI. However, there is one more hurdle: thetiktokenpackage (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.
Related Skills
node-connect
351.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
351.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
351.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
