File size: 769 Bytes
0b0b616
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
import streamlit as st
import os


from langchain.llms import OpenAI   
from langchain.chat_models import ChatOpenAI 
from dotenv import load_dotenv
from langchain.schema import HumanMessage,SystemMessage,AIMessage

load_dotenv()

def get_openai_response(question):
 chatllm=ChatOpenAI(openai_api_key=os.getenv('OPENAI_API_KEY'),temperature=0.6,model='gpt-4o-mini')
 
 response=chatllm([
 SystemMessage(content="You are an AI assistant"),
 HumanMessage(content=question)
 ])
 return response.content


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)

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


if submit:
 st.subheader("The response is: ")
 st.write(response)