diff options
author | Navan Chauhan <navanchauhan@gmail.com> | 2023-10-13 23:50:10 -0600 |
---|---|---|
committer | Navan Chauhan <navanchauhan@gmail.com> | 2023-10-13 23:50:10 -0600 |
commit | 9f914f8d479d58d7ccc045784fe614dfea9a1219 (patch) | |
tree | db5a58ae9bdae7a7aa139c6220e048c359657298 /lang_prompt_demo.py | |
parent | 6edba6384b42fa03785ac5887e91eb310e876ced (diff) |
langchain
Diffstat (limited to 'lang_prompt_demo.py')
-rw-r--r-- | lang_prompt_demo.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lang_prompt_demo.py b/lang_prompt_demo.py new file mode 100644 index 0000000..d63aea3 --- /dev/null +++ b/lang_prompt_demo.py @@ -0,0 +1,37 @@ +import os +import sys +import typing +from dotenv import load_dotenv + +from tools.contacts import get_all_contacts +from tools.vocode import call_phone_number +from langchain.memory import ConversationBufferMemory + +from stdout_filterer import RedactPhoneNumbers + +load_dotenv() + +from langchain.chat_models import ChatOpenAI +from langchain.agents import initialize_agent +from langchain.agents import AgentType + +if __name__ == "__main__": + # Redirect stdout to our custom class + sys.stdout = typing.cast(typing.TextIO, RedactPhoneNumbers(sys.stdout)) + + OBJECTIVE = ( + input("Objective: ") + or "Find a random person in my contacts and tell them a joke" + ) + llm = ChatOpenAI(temperature=0, model_name="gpt-4") # type: ignore + memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True) + # Logging of LLMChains + verbose = True + agent = initialize_agent( + tools=[get_all_contacts, call_phone_number], + llm=llm, + agent=AgentType.CHAT_CONVERSATIONAL_REACT_DESCRIPTION, + verbose=verbose, + memory=memory, + ) + agent.run(OBJECTIVE) |