-
Notifications
You must be signed in to change notification settings - Fork 499
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update langchain usage in tutorial (#1116)
* docs: update langchain usage * Update instructions to match --------- Co-authored-by: Debbie Matthews <[email protected]>
- Loading branch information
1 parent
15e17f5
commit 358b466
Showing
2 changed files
with
49 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 16 additions & 11 deletions
27
python/tutorial-source/llm-18-lines-of-code/streamlit_app.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
import streamlit as st | ||
from langchain.llms import OpenAI | ||
from langchain_openai.chat_models import ChatOpenAI | ||
|
||
st.title('🦜🔗 Quickstart App') | ||
st.title("🦜🔗 Quickstart App") | ||
|
||
openai_api_key = st.sidebar.text_input("OpenAI API Key", type="password") | ||
|
||
openai_api_key = st.sidebar.text_input('OpenAI API Key', type='password') | ||
|
||
def generate_response(input_text): | ||
llm = OpenAI(temperature=0.7, openai_api_key=openai_api_key) | ||
st.info(llm(input_text)) | ||
model = ChatOpenAI(temperature=0.7, api_key=openai_api_key) | ||
st.info(model.invoke(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-'): | ||
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) |