Home Artists Posts Import Register

Downloads

Content

UPDATE: This code would redefine the agent memory each time with streamlit erasing the memory. I have uploaded a file with the fixed code so that when using this with streamlit, agent's memory doesn't reset. I am leaving the old code file as reference


CODE THAT NEEDS TO CHANGE:
if "agent_memory" not in st.session_state:

   st.session_state["agent_memory"] =
  ConversationBufferMemory(memory_key="chat_history") 

llm=OpenAI(temperature=0, verbose=True)

agent_chain = initialize_agent(tools,  llm, agent="conversational-react-description", memory=st.session_state["agent_memory"], verbose=True)


this is for video: https://youtu.be/NIG8lXk0ULg

Turn any python function into a custom langchain agent with tools including short term conversational memory

Comments

Mark

Thanks for making this great video. Question, have you tried using the lambda function to import the tools i.e wolframalpha? See below. func=lambda llm, serpapi_api_key, wolfram_alpha_appid: load_tools(["serpapi", "wolfram-alpha"], llm=llm, serpapi_api_key=serpapi_api_key, wolfram_alpha_appid=wolfram_alpha_appid)

echohive42

I haven’t tried with lambda but you can load those built in tools easily with load_tools import from langchain as such: tools = load_tools(["serpapi", "llm-math", "wolfram-alpha"], llm=llm, serpapi_api_key=os.getenv("SERPAPI_API_KEY"), wolfram_alpha_appid=os.getenv("WOLFRAM_ALPHA_APPID"). It is in the code from “gpt-3 searches the internet” post and video

Jim McMillan

Help me understand how this is connecting to OpenAI API? I don't see the call from the code. Is it pulling my API key from the environment or do I not need one? Great work. Thank you.

echohive42

Sorry for the late reply. I must have missed this one. It automatically reads the API key from a user environment variable named as "OPENAI_API_KEY" if you have that setup, then you are good to go. Otherwise you would have to explicitly define it.