-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
32 lines (23 loc) · 795 Bytes
/
Copy pathapp.py
File metadata and controls
32 lines (23 loc) · 795 Bytes
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
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
import asyncio
import streamlit as st
from dotenv import load_dotenv
import os
load_dotenv()
os.environ["OPENAI_API_KEY"]=os.getenv("OPENAI_API_KEY")
prompt=ChatPromptTemplate.from_messages(
[
("system","You are ahelpful assistant."),
("user","Question:{question}")
]
)
st.title('Langchain with OPENAI API')
input_text=st.text_input("Search the topic u want")
llm=ChatOpenAI(model="gpt-4o-mini")
output_parser=StrOutputParser()
chain=prompt|llm|output_parser
if input_text:
st.write("Answering the question...")
st.write(chain.invoke({'question':input_text}))