Build powerful generative AI apps

Thousands of developers use Streamlit as their go-to platform to experiment and build generative AI apps. Create, deploy, and share LLM-powered apps as fast as ChatGPT can compute!

Try example code Deploy on Community Cloud

Your LLM code playground

Play around with a few of Streamlit’s open source examples using LLMs.

  • Build a chatbot
  • File Q&A with Anthropic
  • Search with Langchain
  • Langchain Quickstart App
  • Langchain - Blog Outline Generator App
Copy

Chatbot · Streamlit

Built with Streamlit 🎈

Fullscreen

Chatbot

keyboard_double_arrow_left

OpenAI API Key

Show password text

Get an OpenAI API key
View the source code

💬 ChatbotLink to heading

🚀 A Streamlit chatbot powered by OpenAI

Unlock your creativity with LLMs

Works with everything in the AI ecosystem

Did you know...

LLMs are genius at writing apps

Streamlit is a breeze for humans and AI alike. Just watch ChatGPT write a Streamlit app in a matter of seconds. It's pair programming like never before.

FAQ

  • What is a Large Language Model (LLM)?

A large language model is a kind of neural network – so-called Transformer – with a large number of parameters and trained on a huge corpus of natural language data which enable general-purpose, programmable AI. LLMs cost 10-100s of millions of dollars to train and include 100s of billions of parameters, making them the most complex AI projects built by humanity.

  • Which LLMs work with Streamlit?

Any LLM with a python implementation or API call works with Streamlit. This includes popular open source and closed source models like OpenAI, LLaMa, Anthropic, PaLM, and other open source models such as the ones hosted on HuggingFace or built with Transformers.

  • How to obtain an OpenAI API key?

You can get your own OpenAI API key by following the following instructions * Go to https://platform.openai.com/account/api-keys. * Click on the + Create new secret key button. * Next, enter an identifier name (optional) and click on the Create secret key button.

  • How to load LLM API key in a Streamlit app

Then add your OpenAI API key as an environment variable in Streamlit Community Cloud: * At the lower right corner, click on < Manage app then click on the vertical "..." followed by clicking on Settings. * This brings the App settings, next, click on the Secrets tab and paste the API key into the text box. * Click Save Now, that we have the API key defined in secrets, it should now be automatically detected in-app from the OPENAI_API_KEY environment variable. This can be explicitly called via st.secrets[“OPENAI_API_KEY”]

  • How do I connect Streamlit to OpenAI?

You can use the OpenAI python library. Run pip install openai streamlit. Here’s a very simple example: python import streamlit as st import openai openai.api_key = st.secrets.openai_api_key input = st.text_input("Ask a question") if st.button("Submit"): chat_completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": input}]) st.write(chat_completion.choices[0].message.content)

  • How do I connect Streamlit to an LLM?

You can connect any other LLM to Streamlit the same way you would connect to the LLM from any other Python application. Search for a python client or example code from the LLM, and adapt it to Streamlit similar to the example above. Another good option is to use LangChain, which maintains integrations to a huge range of LLMs for Python.