├── .streamlit └── config.toml ├── README.md ├── diagram.jpg ├── requirements.txt └── streamlit_app.py /.streamlit/config.toml: -------------------------------------------------------------------------------- 1 | [theme] 2 | primaryColor="#F63366" 3 | backgroundColor="#FFFFFF" 4 | secondaryBackgroundColor="#F0F2F6" 5 | textColor="#262730" 6 | font="sans serif" 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🦜🔗 Langchain - Quickstart App 2 | 3 | Build your first LLM powered app with Langchain and Streamlit. 4 | 5 | ## Overview of the App 6 | 7 | 8 | 9 | - Accepts input text (*e.g.* `What are the three key pieces of advice for learning how to code?`) as prompt input using Streamlit's `st.text_area()`, then assign this to the `text` variable. 10 | - LLM model is called via `llm()` and it is applied on the prompt input `text` to generate a response via `llm(text)` 11 | 12 | ## Demo App 13 | 14 | [![Streamlit App](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://langchain-quickstart.streamlit.app/) 15 | 16 | ## Get an OpenAI API key 17 | 18 | You can get your own OpenAI API key by following the following instructions: 19 | 1. Go to https://platform.openai.com/account/api-keys. 20 | 2. Click on the `+ Create new secret key` button. 21 | 3. Next, enter an identifier name (optional) and click on the `Create secret key` button. 22 | 23 | ## Try out the app 24 | 25 | Once the app is loaded, go ahead and enter your OpenAI API key and type a question in the text box and wait for a generated response. 26 | -------------------------------------------------------------------------------- /diagram.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataprofessor/langchain-quickstart/329106910e6781309951b6add6e803b0a4abc061/diagram.jpg -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | streamlit 2 | openai 3 | langchain 4 | langchain-community 5 | -------------------------------------------------------------------------------- /streamlit_app.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | from langchain.llms import OpenAI 3 | st.set_page_config(page_title="🦜🔗 Quickstart App") 4 | st.title('🦜🔗 Quickstart App') 5 | 6 | openai_api_key = st.sidebar.text_input('OpenAI API Key') 7 | 8 | def generate_response(input_text): 9 | llm = OpenAI(temperature=0.7, openai_api_key=openai_api_key) 10 | st.info(llm(input_text)) 11 | 12 | with st.form('my_form'): 13 | text = st.text_area('Enter text:', 'What are the three key pieces of advice for learning how to code?') 14 | submitted = st.form_submit_button('Submit') 15 | if not openai_api_key.startswith('sk-'): 16 | st.warning('Please enter your OpenAI API key!', icon='⚠') 17 | if submitted and openai_api_key.startswith('sk-'): 18 | generate_response(text) 19 | --------------------------------------------------------------------------------