Skip to content

Commit

Permalink
Remove ads restriction (#918)
Browse files Browse the repository at this point in the history
* Update packages

* Remove Ads restriction to have exactly 15 headlines and 4 descriptions

* Add python-multipart to dependencies
  • Loading branch information
rjambrecic committed Sep 3, 2024
1 parent f3576ea commit a35e491
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 14 deletions.
27 changes: 27 additions & 0 deletions captn/captn_agents/backend/tools/_campaign_creation_team_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,27 @@ def descriptions_validator(cls, descriptions: List[str]) -> Optional[List[str]]:
)


class GBBAdGroupAdForCreation(AdGroupAdForCreation):
headlines: Annotated[
List[
Annotated[
str,
"Maximum 30 characters. If keyword insertion is used, '{KeyWord' and '}' are NOT included in the 30 characters.",
]
],
Len(min_length=3, max_length=15),
]
descriptions: Annotated[
List[
Annotated[
str,
"Maximum 90 characters. If keyword insertion is used, '{KeyWord' and '}' are NOT included in the 90 characters.",
]
],
Len(min_length=2, max_length=4),
]


class AdGroupCriterionForCreation(AdBase):
ad_group_id: Optional[
Annotated[str, Field(..., description="Always set this field to None")]
Expand Down Expand Up @@ -138,6 +159,12 @@ class AdGroupWithAdAndKeywords(BaseModel):
keywords: Annotated[List[AdGroupCriterionForCreation], Len(min_length=1)]


class GBBAdGroupWithAdAndKeywords(AdGroupWithAdAndKeywords):
ad_group_ad: Annotated[
GBBAdGroupAdForCreation, "The ad for the ad group which will be created"
]


def _create_ad_group(
user_id: int,
conv_id: int,
Expand Down
18 changes: 11 additions & 7 deletions captn/captn_agents/backend/tools/_gbb_google_sheets_team_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
)
from ..toolboxes import Toolbox
from ._campaign_creation_team_tools import (
AdGroupAdForCreation,
AdGroupCriterionForCreation,
AdGroupForCreation,
AdGroupWithAdAndKeywords,
GBBAdGroupAdForCreation,
GBBAdGroupWithAdAndKeywords,
_create_ad_group_with_ad_and_keywords,
)
from ._functions import (
Expand Down Expand Up @@ -347,7 +347,7 @@ def _create_ad_group_with_ad_and_keywords_helper(
ad_group_name: str,
match_type: str,
ad_group_keywords_df: pd.DataFrame,
ad_group_ad: AdGroupAdForCreation,
ad_group_ad: GBBAdGroupAdForCreation,
context: GoogleSheetsTeamContext,
) -> None:
ad_group = AdGroupForCreation(
Expand All @@ -374,7 +374,7 @@ def _create_ad_group_with_ad_and_keywords_helper(
)
)

ad_group_with_ad_and_keywords = AdGroupWithAdAndKeywords(
ad_group_with_ad_and_keywords = GBBAdGroupWithAdAndKeywords(
customer_id=customer_id,
campaign_id=campaign_id,
ad_group=ad_group,
Expand Down Expand Up @@ -837,18 +837,22 @@ def _setup_campaign(

for _, row in ads_df[ads_df["campaign name"] == campaign_name].iterrows():
headlines = [
row[col] for col in row.index if col.lower().startswith("headline")
row[col]
for col in row.index
if col.lower().startswith("headline") and row[col]
]
descriptions = [
row[col] for col in row.index if col.lower().startswith("description")
row[col]
for col in row.index
if col.lower().startswith("description") and row[col]
]

path1 = row.get("path 1", None)
path2 = row.get("path 2", None)
final_url = row.get("final url")

campaign = created_campaign_names_and_ids[campaign_name]
ad_group_ad = AdGroupAdForCreation(
ad_group_ad = GBBAdGroupAdForCreation(
customer_id=customer_id,
campaign_id=campaign_id,
status="ENABLED",
Expand Down
15 changes: 8 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ lint = [
"mypy==1.11.2",
"black==24.4.2",
"isort>=5",
"ruff==0.6.1",
"ruff==0.6.3",
"pyupgrade-directories",
"bandit==1.7.9",
"semgrep==1.78.0",
Expand Down Expand Up @@ -90,10 +90,10 @@ benchmarking = [
]

agents = [
"fastapi==0.111.1",
"fastapi==0.112.2",
"APScheduler==3.10.4",
"prisma==0.13.1",
"google-ads==24.1.0",
"google-ads==25.0.0",
"httpx==0.27.0",
"uvicorn==0.30.6",
"python-dotenv==1.0.1",
Expand All @@ -104,14 +104,15 @@ agents = [
"pydantic==2.8.2",
"tenacity==9.0.0",
"prometheus-client==0.20.0",
"opentelemetry-distro==0.47b0",
"opentelemetry-instrumentation-fastapi==0.47b0",
"opentelemetry-instrumentation-logging==0.47b0",
"opentelemetry-exporter-otlp==1.26.0",
"opentelemetry-distro==0.48b0",
"opentelemetry-instrumentation-fastapi==0.48b0",
"opentelemetry-instrumentation-logging==0.48b0",
"opentelemetry-exporter-otlp==1.27.0",
"openpyxl==3.1.5",
"aiofiles==24.1.0",
"fastagency[studio]@git+https://github.com/airtai/fastagency.git@main",
"markdownify==0.13.1",
"python-multipart==0.0.9",
]

dev = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from captn.captn_agents.backend.toolboxes.base import Toolbox
from captn.captn_agents.backend.tools._campaign_creation_team_tools import (
AdGroupAdForCreation,
GBBAdGroupAdForCreation,
_remove_resources,
create_campaign_creation_team_toolbox,
)
Expand Down Expand Up @@ -309,3 +310,37 @@ def test_maximum_headline_string_length(self, headline, expected):
final_url="https://www.example.com",
status="ENABLED",
)


class TestGBBModels:
@pytest.mark.parametrize(
("headlines", "expected"),
[
(["H1", "H2", "H3", "H4"], None),
(["H1", "H2"], ValidationError),
(["H1", "H2", "H3", "H" * 31], ValueError),
],
)
def test_gbb_ad_group_ad_for_creation(
self, headlines: List[str], expected: Optional[Exception]
) -> None:
if expected is None:
ad_group_ad = GBBAdGroupAdForCreation(
customer_id="2222",
headlines=headlines,
descriptions=["D1", "D2", "D3", "D4"],
final_url="https://www.example.com",
status="ENABLED",
)
assert ad_group_ad.headlines == headlines

else:
with pytest.raises(expected) as e:
GBBAdGroupAdForCreation(
customer_id="2222",
headlines=headlines,
descriptions=["D1", "D2", "D3", "D4"],
final_url="https://www.example.com",
status="ENABLED",
)
print(f"Exception: {e}")

0 comments on commit a35e491

Please sign in to comment.