diff --git a/python/tutorial-source/llm-18-lines-of-code/requirements.txt b/python/tutorial-source/llm-18-lines-of-code/requirements.txt new file mode 100644 index 000000000..37db69adf --- /dev/null +++ b/python/tutorial-source/llm-18-lines-of-code/requirements.txt @@ -0,0 +1,3 @@ +streamlit +openai +langchain diff --git a/python/tutorial-source/llm-18-lines-of-code/streamlit_app.py b/python/tutorial-source/llm-18-lines-of-code/streamlit_app.py new file mode 100644 index 000000000..817bee2b4 --- /dev/null +++ b/python/tutorial-source/llm-18-lines-of-code/streamlit_app.py @@ -0,0 +1,19 @@ +import streamlit as st +from langchain.llms import OpenAI + +st.title('🦜🔗 Quickstart App') + +openai_api_key = st.sidebar.text_input('OpenAI API Key') + +def generate_response(input_text): + llm = OpenAI(temperature=0.7, openai_api_key=openai_api_key) + st.info(llm(input_text)) + +with st.form('my_form'): + text = st.text_area('Enter text:', 'What are the three key pieces of advice for learning how to code?') + submitted = st.form_submit_button('Submit') + if not openai_api_key.startswith('sk-'): + st.warning('Please enter your OpenAI API key!', icon='⚠') + if submitted and openai_api_key.startswith('sk-'): + generate_response(text) + \ No newline at end of file