mirror of
https://github.com/langchain-ai/streamlit-agent.git
synced 2026-07-01 09:25:05 -04:00
18 lines
629 B
Python
18 lines
629 B
Python
from langchain.llms import OpenAI
|
|
from langchain.agents import AgentType, initialize_agent, load_tools
|
|
from langchain.callbacks import StreamlitCallbackHandler
|
|
import streamlit as st
|
|
|
|
llm = OpenAI(temperature=0, streaming=True)
|
|
tools = load_tools(["ddg-search"])
|
|
agent = initialize_agent(
|
|
tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True
|
|
)
|
|
|
|
if prompt := st.chat_input():
|
|
st.chat_message("user").write(prompt)
|
|
with st.chat_message("assistant"):
|
|
st_callback = StreamlitCallbackHandler(st.container())
|
|
response = agent.run(prompt, callbacks=[st_callback])
|
|
st.write(response)
|