Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into handle-lifespan-exception
Browse files Browse the repository at this point in the history
  • Loading branch information
harishmohanraj committed Mar 8, 2024
2 parents 5cf2aa0 + fe15bee commit e5894fc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
6 changes: 5 additions & 1 deletion captn/captn_agents/backend/function_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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"],
},
}

Expand Down
16 changes: 15 additions & 1 deletion captn/captn_agents/backend/functions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ast
from typing import Any, Dict, List, Optional, Tuple, Union
from unittest.mock import patch

Expand All @@ -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

Expand Down Expand Up @@ -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
)
Expand Down
19 changes: 8 additions & 11 deletions captn/captn_agents/backend/google_ads_team.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand Down

0 comments on commit e5894fc

Please sign in to comment.