ps1811 commited on
Commit
10d99e1
·
1 Parent(s): 61d113e

Cleaned search_term_optimizer.py

Browse files
Files changed (1) hide show
  1. app/ads1/search_term_optimizer.py +6 -30
app/ads1/search_term_optimizer.py CHANGED
@@ -1,7 +1,6 @@
1
  import pandas as pd
2
  from app.recs.generate import TARGET_CPL, generate_explanation, is_bad_llm_output
3
 
4
-
5
  def build_search_term_features(df: pd.DataFrame) -> pd.DataFrame:
6
  df = df.copy()
7
 
@@ -41,13 +40,10 @@ def detect_review_terms(df):
41
  ]
42
 
43
  def detect_scaling_terms(df):
44
- return df[
45
- (df["conversions"] > 0)
46
- ].sort_values("cpa", ascending=True)
47
 
48
  def classify_search_term(dfs: dict) -> dict:
49
  df = dfs["search_terms"].copy()
50
-
51
  df = build_search_term_features(df)
52
 
53
  negatives = detect_negative_terms(df)
@@ -91,36 +87,16 @@ def build_search_optimizer_context(dfs: dict, campaign_name: str | None = None):
91
  }
92
 
93
  def run_search_term_optimizer(dfs: dict,campaign_name: str | None = None) -> str:
94
- print(
95
- "\n🚀 [search_term_card] STARTED",
96
- flush=True
97
- )
98
  if not dfs:
99
  return (
100
  "⚠️ No campaign data — "
101
  "select a campaign first."
102
  )
103
- context = build_search_optimizer_context(
104
- dfs,
105
- campaign_name
106
- )
107
-
108
  print("🧠 [search_term_card] context built",flush=True)
109
-
110
- prompt = build_search_optimizer_prompt(
111
- context
112
- )
113
-
114
- print(
115
- "✍️ [search_term_card] prompt built",
116
- flush=True
117
- )
118
-
119
  result = generate_explanation(prompt)
120
-
121
- print(
122
- "📤 [search_term_card] result received",
123
- flush=True
124
- )
125
-
126
  return result
 
1
  import pandas as pd
2
  from app.recs.generate import TARGET_CPL, generate_explanation, is_bad_llm_output
3
 
 
4
  def build_search_term_features(df: pd.DataFrame) -> pd.DataFrame:
5
  df = df.copy()
6
 
 
40
  ]
41
 
42
  def detect_scaling_terms(df):
43
+ return df[(df["conversions"] > 0)].sort_values("cpa", ascending=True)
 
 
44
 
45
  def classify_search_term(dfs: dict) -> dict:
46
  df = dfs["search_terms"].copy()
 
47
  df = build_search_term_features(df)
48
 
49
  negatives = detect_negative_terms(df)
 
87
  }
88
 
89
  def run_search_term_optimizer(dfs: dict,campaign_name: str | None = None) -> str:
90
+ print("\n🚀 [search_term_card] STARTED", flush=True)
 
 
 
91
  if not dfs:
92
  return (
93
  "⚠️ No campaign data — "
94
  "select a campaign first."
95
  )
96
+ context = build_search_optimizer_context(dfs,campaign_name)
 
 
 
 
97
  print("🧠 [search_term_card] context built",flush=True)
98
+ prompt = build_search_optimizer_prompt(context)
99
+ print("✍️ [search_term_card] prompt built",flush=True)
 
 
 
 
 
 
 
 
100
  result = generate_explanation(prompt)
101
+ print("📤 [search_term_card] result received", flush=True)
 
 
 
 
 
102
  return result