From 8f7a84ee9811ad0b0ec667897a546100dd7d3b23 Mon Sep 17 00:00:00 2001 From: Luis Perez Morales Date: Wed, 17 Jan 2024 10:57:05 -0800 Subject: [PATCH] Update AI assistant messages and Twilio configuration --- alternative_helper.py | 39 ++++++++++++++++++++------------------- sms-helper/__init__.py | 26 ++++++++++++++------------ 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/alternative_helper.py b/alternative_helper.py index 64e94e0..56cd312 100644 --- a/alternative_helper.py +++ b/alternative_helper.py @@ -40,10 +40,10 @@ def check_pin_and_reply(PIN, incoming_message): Reply message """ if incoming_message.strip() == PIN: - return """Welcome back lord overlord Luis. - - I can schedule calls, texts, and reminders for you. - - I can also just answer questions or anything like that. - - Text 'yolo' to see this message again""" + return """Welcome to Hess Services AI Assistant. + - I can schedule calls and text reminders for you. + - I can also just answer questions, within reason. + - Text 'hess' to see this message again""" else: messages = CLIENT.messages.list(from_=send_to, to=send_from) sent_pin = False @@ -97,7 +97,7 @@ def get_time(): #-----------------------------------------# # Generate JSON body to schedule reminder #-----------------------------------------# -def schedule_reminder(natural_language_request): +def schedule_reminder(natural_language_request, number_from): """ Generate JSON body to schedule reminder @@ -110,12 +110,9 @@ def schedule_reminder(natural_language_request): ------- JSON body to schedule reminder """ - sys_prompt = """Your job is to create the JSON body for an API call to schedule texts and calls. Then , you will schedule the text or call for the user will request based on pacific time (given in pacific time). If user asks for a reminder today at 6 pm that is 18:00 (24 hour notation). + sys_prompt = """Your job is to create the JSON body for an API call to schedule texts and calls. Then , you will schedule the text or call for the user will request based on pacific time (given in pacific time). If user asks for a reminder today at 6 pm that is 18:00 (24 hour notation). Set the 'to_number' to the users number. Always set twilio = True. - If the user requests to be called or messaged on their work phone, set to_phone variable to '+12221110000' else send it to default phone '+15554443333'. Use twilio = True by default. - - Example endpoint: http://YOUR-ENDPOINT.elasticbeanstalk.com/schedule_single_reminder - Example call: + Example JSON: { "time": "18:20", "day": "2023-11-27", @@ -125,7 +122,7 @@ def schedule_reminder(natural_language_request): "to_number": "+15554443333" } - Example message: + Another example: { "time":"23:46", "day":"2023-11-27", @@ -141,7 +138,7 @@ def schedule_reminder(natural_language_request): model="gpt-3.5-turbo-1106", messages=[ {"role": "system", "content": f"{sys_prompt}"}, - {"role": "user", "content": f"{natural_language_request}. : {curr_time}"}, + {"role": "user", "content": f"{natural_language_request}. {number_from} : {curr_time}"}, ], response_format={ "type": "json_object" }, ) @@ -168,11 +165,11 @@ def get_follow_up_text(send_to, send_from, incoming_message): message : str Response from the AI to the user """ - if incoming_message == 'yolo': - return """Welcome back lord overlord Luis. - - I can schedule calls, texts, and reminders for you. - - I can also just answer questions or anything like that. - - Text 'yolo' to see this message again""" + if incoming_message == 'hess': + return """Welcome to Hess Services new AI assistant. + - I can schedule calls and text reminders for you. + - I can answer any questions, within reason. + - Text 'hess' to see this message again""" else: tools = [ { @@ -186,7 +183,11 @@ def get_follow_up_text(send_to, send_from, incoming_message): "natural_language_request": { "type": "string", "description": "Requested reminder in natural language. Example: 'Remind me to call mom tomorrow at 6pm' or 'Send me a message with a Matrix quote on wednesday at 8am'", - } + }, + "number_from": { + "type": "string", + "description": "Phone number to send text from. Example: '+15554443333'" + } }, "required": ["natural_language_request"], }, @@ -222,7 +223,7 @@ def get_follow_up_text(send_to, send_from, incoming_message): # Schedule reminder #--------------------------------# json_body = schedule_reminder(**args_dict) - url_endpoint = "http://YOUR-ENDPOINT.elasticbeanstalk.com/schedule_single_reminder" + url_endpoint = os.environ["AMAZON_ENDPOINT"] headers = {'Content-Type': 'application/json'} response = requests.post(url_endpoint, headers=headers, data=json.dumps(json_body)) if response.status_code == 200: diff --git a/sms-helper/__init__.py b/sms-helper/__init__.py index efb5181..9fb4f63 100644 --- a/sms-helper/__init__.py +++ b/sms-helper/__init__.py @@ -16,6 +16,8 @@ # For initial testing capture 100% of transactions for monitoring traces_sample_rate=1.0, ) +ACCOUNT_SID = os.environ["ACCOUNT_SID"] + #------------------------------------# # Main function @@ -28,22 +30,22 @@ def main(req: func.HttpRequest) -> func.HttpResponse: incoming_message = req.params["Body"].lower().strip() # Reply to the user based on the incoming message - helper.process_incoming_message(os.environ["SECURITY_PIN"], - send_to, - send_from, - incoming_message) + # helper.process_incoming_message(os.environ["SECURITY_PIN"], + # send_to, + # send_from, + # incoming_message) - return func.HttpResponse( - "You can text this number again if you need more information. (LPM)", status_code=200 - ) + # return func.HttpResponse( + # "You can text this number again if you need more information. (LPM)", status_code=200 + # ) #--------------------------------------------------------------------------# # To reduce the number of messages you could use the 'alternative_helper' # This one returns the response message as the HttpResponse. #--------------------------------------------------------------------------# - # response_for_user = alternative_helper.process_incoming_message(os.environ["SECURITY_PIN"], - # send_to, - # send_from, - # incoming_message) - # return func.HttpResponse(response_for_user, status_code=200) \ No newline at end of file + response_for_user = alternative_helper.process_incoming_message(os.environ["SECURITY_PIN"], + send_to, + send_from, + incoming_message) + return func.HttpResponse(response_for_user, status_code=200) \ No newline at end of file