From fe15bee25701801988749dbeff8d5453b855dcd1 Mon Sep 17 00:00:00 2001 From: rjambrecic <32619626+rjambrecic@users.noreply.github.com> Date: Thu, 7 Mar 2024 16:33:35 +0100 Subject: [PATCH] Display the customer id and name when recommending modifications (#435) * Display the customer id and name when recommending modifications --- .../captn_agents/backend/function_configs.py | 6 +++++- captn/captn_agents/backend/functions.py | 16 +++++++++++++++- captn/captn_agents/backend/google_ads_team.py | 19 ++++++++----------- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/captn/captn_agents/backend/function_configs.py b/captn/captn_agents/backend/function_configs.py index 3e327eb5..e222786f 100644 --- a/captn/captn_agents/backend/function_configs.py +++ b/captn/captn_agents/backend/function_configs.py @@ -751,6 +751,10 @@ "parameters": { "type": "object", "properties": { + "customer_id": { + "type": "string", + "description": "Id of the customer for whom the changes will be made", + }, "resource_details": { "type": "string", "description": """Make sure you add all the information which the client needs to know, beacuse the client does NOT see the internal team messages! @@ -776,7 +780,7 @@ Do you approve the changes? To approve the changes, please answer 'Yes' and nothing else.""", }, }, - "required": ["resource_details", "proposed_changes"], + "required": ["customer_id", "resource_details", "proposed_changes"], }, } diff --git a/captn/captn_agents/backend/functions.py b/captn/captn_agents/backend/functions.py index c590fe6c..8d5ff78c 100644 --- a/captn/captn_agents/backend/functions.py +++ b/captn/captn_agents/backend/functions.py @@ -1,3 +1,4 @@ +import ast from typing import Any, Dict, List, Optional, Tuple, Union from unittest.mock import patch @@ -7,6 +8,7 @@ from typing_extensions import Annotated from captn.captn_agents.backend.config import config_list_gpt_3_5, config_list_gpt_4 +from captn.google_ads.client import execute_query from ..model import SmartSuggestions @@ -63,12 +65,24 @@ def reply_to_client_2( def ask_client_for_permission( + user_id: int, + conv_id: int, + customer_id: str, clients_question_answere_list: List[Tuple[str, Optional[str]]], resource_details: str, proposed_changes: str, ) -> Dict[str, Any]: + query = f"SELECT customer.descriptive_name FROM customer WHERE customer.id = '{customer_id}'" # nosec: [B608] + query_result = execute_query( + user_id=user_id, conv_id=conv_id, customer_ids=[customer_id], query=query + ) + descriptiveName = ast.literal_eval(query_result)[customer_id][0]["customer"]["descriptiveName"] # type: ignore + + customer_to_update = f"We propose changes for the following customer: '{descriptiveName}' (ID: {customer_id})" + message = f"{customer_to_update}\n\n{resource_details}\n\n{proposed_changes}" + clients_question_answere_list.append((proposed_changes, None)) - message = f"{resource_details}\n\n{proposed_changes}" + return reply_to_client_2( message=message, completed=False, smart_suggestions=YES_OR_NO_SMART_SUGGESTIONS ) diff --git a/captn/captn_agents/backend/google_ads_team.py b/captn/captn_agents/backend/google_ads_team.py index d4fff4e6..0b833d97 100644 --- a/captn/captn_agents/backend/google_ads_team.py +++ b/captn/captn_agents/backend/google_ads_team.py @@ -1,7 +1,6 @@ __all__ = ["GoogleAdsTeam"] import ast -from pathlib import Path from typing import Any, Callable, Dict, List, Optional, Tuple, Union from autogen.io.websockets import IOWebsockets @@ -22,7 +21,6 @@ google_ads_create_update, list_accessible_customers, ) -from .execution_team import get_read_file from .function_configs import ( ask_client_for_permission_config, create_ad_copy_headline_or_description_config, @@ -35,7 +33,6 @@ execute_query_config, get_info_from_the_web_page_config, list_accessible_customers_config, - read_file_config, remove_ad_copy_headline_or_description_config, remove_google_ads_resource_config, reply_to_client_2_config, @@ -62,7 +59,6 @@ class GoogleAdsTeam(Team): list_accessible_customers_config, execute_query_config, reply_to_client_2_config, - read_file_config, update_ad_group_ad_config, update_ad_group_config, update_campaign_config, @@ -314,7 +310,9 @@ def _guidelines(self) -> str: Currently we are in a demo phase and clients need to see what we are CURRENTLY able to do. This is a template which you should follow when you are asked to optimize campaigns: -- The FIRST step should ALWAYS be listing the campaigns and asking the user in which one he is interested in. Do NOT try to analyse all campaigns at once! +- The FIRST step should ALWAYS be listing the campaigns and asking the user in which one he is interested in. Do NOT try to analyse all campaigns at once, otherwise you will be penalized!! +- After listing the campaigns, ask the user which one he is interested in or if he wants to create a new one. +If the user wants to update the existing campaign here is the list of things which you can do: - ad copy - Take a look at ad copy (headlines, descriptions, urls, (display) path1/path2...) and make suggestions on what should be changed (create/update/remove headlines etc.) Headlines can have MAXIMUM 30 characters and description can have MAXIMUM 90 characters, NEVER suggest headlines/descriptions which exceed that length! - keywords - analyse positive/negative keywords and find out which are (i)relevant for clients business and suggest some create/update/remove actions @@ -385,9 +383,8 @@ def _commands(self) -> str: "type":"manyOf" } -2. read_file: Read an existing file, params: (filename: string) 3. ask_client_for_permission: Ask the client for permission to make the changes. Use this method before calling any of the modification methods! -params: (resource_details: string, proposed_changes: str) +params: (customer_id: str, resource_details: str, proposed_changes: str) 'proposed_changes' parameter must contain info about each field which you want to modify and it MUST refernce it by the EXACT name as the one you are going to use in the modification method. e.g.: if you want to update/set "budget_amount_micros" you must mention "budget_amount_micros" in this parameter. same thing for "final_url", you must mention "final_url" in this parameter, if you mention "final url" or "final-url" it will NOT be accepted! @@ -557,8 +554,6 @@ def _string_to_list( "Error: parameter customer_ids must be a list of strings. e.g. ['1', '5', '10']" ) - read_file = get_read_file(working_dir=Path(work_dir)) - function_map = { # "get_login_url": lambda: get_login_url(user_id=user_id, conv_id=conv_id), "list_accessible_customers": lambda: list_accessible_customers( @@ -572,12 +567,14 @@ def _string_to_list( work_dir=work_dir, ), "reply_to_client": reply_to_client_2, - "ask_client_for_permission": lambda resource_details, proposed_changes: ask_client_for_permission( + "ask_client_for_permission": lambda customer_id, resource_details, proposed_changes: ask_client_for_permission( + user_id=user_id, + conv_id=conv_id, + customer_id=customer_id, clients_question_answere_list=clients_question_answere_list, resource_details=resource_details, proposed_changes=proposed_changes, ), - "read_file": read_file, "update_ad_group_ad": lambda customer_id, ad_group_id, ad_id, clients_approval_message, modification_question, cpc_bid_micros=None, status=None: google_ads_create_update( user_id=user_id, conv_id=conv_id,