Streamlit is a very useful Python package for creating interactive web pages. It has excellent documentation and offers a quick and easy way to prototype web interfaces. Streamlit can easily provide sidebar controls, graphing and other neat features, but for the purposes of interacting with LLMs, the interesting thing is it implements a very easy to use web chat interface in just a few lines of code.
An example of a simple Streamlit interface for the ChatGPT LLM can be found here. To run it you will need to perform the following steps:
- get an API key from OpenAI at https://openai.com/blog/openai-api
- open a command window (assuming windows) and add your API key keyto create an environmental variable
setx OPENAI_API_KEY "<your-key>"
- pip install the required packages to your python environment
pip install openai pip install streamlit
- you can then check that streamlit works by running
streamlit hello
- Download the sample app’s python file from here
- run the app from the command line (or conda command line if using conda for your python environment) using
streamlit run streamlit_llm_app.py
If everything has gone well your browser should open a window allowing you to chat with ChatGPT. Congratulations you are now using Streamlit as an interface for Large Language Models.
So how is this an advantage over using the chat GPT website? Well because you are running via the API rather than the chat interface you can customise what is available in the interface. You can insert system prompts in between the chat prompts to aid in prompt engineering. You could potentially use libraries like Langchain to allow for richer interactions than simple chat. Basically running LLMs via Streamlit offers you the convenience of a web interface combined with the power of python to customise what is going on under the hood.
Best of all Streamlit has built in tools for handling Pandas dataframes and graphing data so there is potential to perform a wide range of other data related tasks as well as LLM interaction and even to get the two to interact.