-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
35 lines (26 loc) · 950 Bytes
/
app.py
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
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
import streamlit as st
import os
from dotenv import load_dotenv
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
## Langsmith Tracking
os.environ["LANGCHAIN_TRACING_V2"] = "true"
os.environ["LANGCHAIN_API_KEY"] = os.getenv("LANGCHAIN_API_KEY")
# Prompt Temp
prompt = ChatPromptTemplate.from_messages(
[
("system","You are a helpful assistant. Please respond to the user queries")
("user","Question:{question}")
]
)
## Streamlit framework
st.title('Langchain Demo with OPENAI API')
input_text = st.text_input("Search the topic u want")
#OpenAI LLm
llm = ChatOpenAI(model="gpt-3.5-turbo")
output_parser = StrOutputParser()
chain=prompt|llm|output_parser
if input_text:
st.write(chain.invoke({'question':input_text}))