From 5856edfb295bc3d4348398912da66824986dda09 Mon Sep 17 00:00:00 2001 From: Gregory Sinnott Date: Sat, 14 Oct 2023 04:33:34 -0600 Subject: User inputs and call criteria changes --- lang_prompt_demo.py | 11 ++++++++++- tools/get_user_inputs.py | 37 +++++++++++++++++++++++++++++++++++++ tools/vocode.py | 21 +++++++++++++-------- 3 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 tools/get_user_inputs.py diff --git a/lang_prompt_demo.py b/lang_prompt_demo.py index d63aea3..31b5077 100644 --- a/lang_prompt_demo.py +++ b/lang_prompt_demo.py @@ -5,7 +5,9 @@ from dotenv import load_dotenv from tools.contacts import get_all_contacts from tools.vocode import call_phone_number +from tools.get_user_inputs import get_desired_inputs from langchain.memory import ConversationBufferMemory +from langchain.agents import load_tools from stdout_filterer import RedactPhoneNumbers @@ -21,6 +23,7 @@ if __name__ == "__main__": OBJECTIVE = ( input("Objective: ") + + "make sure you use the proper tool before calling final action to meet objective, feel free to say you need more information or cannot do something." or "Find a random person in my contacts and tell them a joke" ) llm = ChatOpenAI(temperature=0, model_name="gpt-4") # type: ignore @@ -28,10 +31,16 @@ if __name__ == "__main__": # Logging of LLMChains verbose = True agent = initialize_agent( - tools=[get_all_contacts, call_phone_number], + tools=[ + get_all_contacts, + call_phone_number, + get_desired_inputs, + ] + + load_tools(["human"]), llm=llm, agent=AgentType.CHAT_CONVERSATIONAL_REACT_DESCRIPTION, verbose=verbose, memory=memory, ) + agent.run(OBJECTIVE) diff --git a/tools/get_user_inputs.py b/tools/get_user_inputs.py new file mode 100644 index 0000000..3b59a3a --- /dev/null +++ b/tools/get_user_inputs.py @@ -0,0 +1,37 @@ +from typing import List +from langchain.agents import tool + +from dotenv import load_dotenv + +from langchain.agents import load_tools +from langchain.llms import OpenAI +from langchain.agents import initialize_agent, AgentType + +load_dotenv() + +import os + +INPUTS = {} + + +@tool("get_desired_inputs") +def get_desired_inputs(input: str) -> dict: + """ + You will be given a task that will be performed by an autonomous agent on behalf of a user. You will gather any necessary data from the user to complete the specified task before executing the task. + """ + + prompt = input + + llm = OpenAI(temperature=0) + agent = initialize_agent( + tools=load_tools(["human"]), + llm=llm, + agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION, + ) + + return agent.run(prompt) + + +def get_user_inputs(): + # iterate through INPUTS and populate values + print("Done") diff --git a/tools/vocode.py b/tools/vocode.py index f752eff..d50c8a3 100644 --- a/tools/vocode.py +++ b/tools/vocode.py @@ -1,12 +1,15 @@ import logging -import asyncio +import asyncio import os from langchain.agents import tool from dotenv import load_dotenv from vocode.streaming.models.message import BaseMessage from vocode.streaming.models.synthesizer import ElevenLabsSynthesizerConfig -from vocode.streaming.models.transcriber import DeepgramTranscriberConfig, PunctuationEndpointingConfig +from vocode.streaming.models.transcriber import ( + DeepgramTranscriberConfig, + PunctuationEndpointingConfig, +) load_dotenv() @@ -23,9 +26,11 @@ import time LOOP = asyncio.new_event_loop() asyncio.set_event_loop(LOOP) + @tool("call phone number") def call_phone_number(input: str) -> str: - """calls a phone number as a bot and returns a transcript of the conversation. + """Use when you need to make a phone call. Calls a phone number as a bot and returns a transcript of the conversation. + the input to this tool is a pipe separated list of a phone number, a prompt, and the first thing the bot should say. The prompt should instruct the bot with what to do on the call and be in the 3rd person, like 'the assistant is performing this task' instead of 'perform this task'. @@ -34,11 +39,11 @@ def call_phone_number(input: str) -> str: for example, `+15555555555|the assistant is explaining the meaning of life|i'm going to tell you the meaning of life` will call +15555555555, say 'i'm going to tell you the meaning of life', and instruct the assistant to tell the human what the meaning of life is. """ - phone_number, prompt, initial_message = input.split("|",2) + phone_number, prompt, initial_message = input.split("|", 2) call = OutboundCall( base_url=os.environ["BASE_URL"], to_phone=phone_number, - from_phone=os.environ['TWILIO_PHONE'], + from_phone=os.environ["TWILIO_PHONE"], config_manager=RedisConfigManager(), agent_config=ChatGPTAgentConfig( initial_message=BaseMessage(text=initial_message), @@ -47,12 +52,12 @@ def call_phone_number(input: str) -> str: ), synthesizer_config=ElevenLabsSynthesizerConfig.from_telephone_output_device( api_key=os.getenv("ELEVENLABS_API_KEY"), - voice_id=os.getenv("ELEVENLABS_VOICE_ID") + voice_id=os.getenv("ELEVENLABS_VOICE_ID"), ), transcriber_config=DeepgramTranscriberConfig.from_telephone_input_device( endpointing_config=PunctuationEndpointingConfig() ), - logger=logging.Logger("OutboundCall") + logger=logging.Logger("OutboundCall"), ) LOOP.run_until_complete(call.start()) while True: @@ -61,4 +66,4 @@ def call_phone_number(input: str) -> str: delete_transcript(call.conversation_id) return maybe_transcript else: - time.sleep(1) \ No newline at end of file + time.sleep(1) -- cgit v1.2.3