File size: 899 Bytes
f6c8ba7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from langchain_openai import ChatOpenAI  # Import the correct class
from dotenv import load_dotenv
import os
import streamlit as st

load_dotenv()  # Load environment variables

# Function to load OpenAI model and get responses
def get_openai_response(question):
    # Use ChatOpenAI for chat models like gpt-3.5-turbo
    llm = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0.5, openai_api_key=os.getenv("OPENAI_API_KEY"))
    response = llm.invoke(question)  # Use invoke() instead of __call__()
    return response.content

# Initialize Streamlit app
st.set_page_config(page_title="Q&A Demo")

st.header("LangChain Application")

input = st.text_input("Input: ", key="input")
response = get_openai_response(input)
print(type)

submit = st.button("Ask the question")

# If ask button is clicked
if submit:
    st.subheader("The response is")
    st.write(response)