-
Notifications
You must be signed in to change notification settings - Fork 0
/
first_app.py
39 lines (28 loc) · 987 Bytes
/
first_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
36
37
38
39
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_API_KEY"] = "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"
os.environ["LANGCHAIN_TRACING_V2"] = "true"
#prompt Template
prompt_template = ChatPromptTemplate.from_messages(
[
("system", "You are a helpful assistant that can answer questions with humor."),
("user", "Question:{question}"),
]
)
#streamlit framework
st.title("Ask me anything Akshay")
question = st.text_input("Enter a question")
#llm
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
output_parser = StrOutputParser()
chain = prompt_template | llm | output_parser
#run the chain
result = chain.invoke({"question": question})
if question:
st.write(result)