File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
python/tutorial-source/llm-18-lines-of-code Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change
1
+ streamlit
2
+ openai
3
+ langchain
Original file line number Diff line number Diff line change
1
+ import streamlit as st
2
+ from langchain .llms import OpenAI
3
+
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
+
You can’t perform that action at this time.
0 commit comments