|
import os |
|
import streamlit as st |
|
from langchain.chains import ConverstationChain |
|
from langchain_openai import ChatOpenAI |
|
from langchain.memory import ConversationBufferMemory |
|
|
|
os.environ["OPENAI_API_KEY"] = "" |
|
|
|
|
|
@st.cache_resource |
|
def init_chatbot(): |
|
memory = ConversationBufferMemory() |
|
chatbot = ConverstationChain( |
|
llm =ChatOpenAI(model = "gpt-4o-mini"), |
|
memory = memory, |
|
verbose = False |
|
) |
|
|
|
return chatbot |
|
|
|
|
|
st.title("Langchain Chatbot") |
|
st.write("Hi, I'm a chatbot built with Langchain powered by GPT. How can I assist you today?") |
|
|
|
user_input = st.text_input("You:", placeholder = "Ask me anything....") |
|
|
|
if user_input: |
|
with st.spinner("Thinking......"): |
|
resp = chatbot.run(user_input) |
|
st.write(f"Chatbot: {resp}") |
|
|