[30a88f42] feat: Centralize API key handling and fix product enrichment\n\n- Centralized GEMINI_API_KEY loading from project root .env file.\n- Corrected product enrichment: added /enrich-product endpoint in Node.js, implemented mode in Python backend, and updated frontend to use new API for product analysis.\n- Fixed to pass product data correctly for enrichment.\n- Updated documentation ().

This commit is contained in:
2026-02-17 07:14:51 +00:00
parent 7be5d47604
commit d13d3a2f36
6 changed files with 94 additions and 13 deletions

View File

@@ -622,6 +622,40 @@ def next_step(language, context_file, generation_step, channels, focus_industry=
summary = [re.sub(r'^\*\s*|^-\s*|^\d+\.\s*', '', s.strip()) for s in summary_match[1].split('\n') if s.strip()] if summary_match else []
return {step_key: {"summary": summary, "headers": table_data['headers'], "rows": table_data['rows']}}
def enrich_product(product_name, product_url, language):
logging.info(f"Enriching product: {product_name} ({product_url})")
api_key = load_api_key()
if not api_key: raise ValueError("Gemini API key is missing.")
grounding_text = ""
if product_url:
grounding_text = get_text_from_url(product_url)
prompt_text = f"""
# ANWEISUNG
Du bist ein B2B-Marketing-Analyst. Deine Aufgabe ist es, die Daten für EIN Produkt zu generieren.
Basierend auf dem Produktnamen und (optional) dem Inhalt der Produkt-URL, fülle die Spalten einer Markdown-Tabelle aus.
Die Ausgabe MUSS eine einzelne, kommaseparierte Zeile sein, die in eine Tabelle passt. KEINE Header, KEIN Markdown, nur die Werte.
# PRODUKT
- Name: "{product_name}"
- URL-Inhalt: "{grounding_text[:3000]}..."
# SPALTEN
Produkt/Lösung | Beschreibung (1-2 Sätze) | Kernfunktionen | Differenzierung | Primäre Quelle (URL)
# BEISPIEL-OUTPUT
Saugroboter NR1500,Ein professioneller Saugroboter für große Büroflächen.,Autonome Navigation;Intelligente Kartierung;Lange Akkulaufzeit,Fokus auf B2B-Markt;Datenschutzkonform,https://nexaro.com/products/nr1500
# DEINE AUFGABE
Erstelle jetzt die kommaseparierte Zeile für das Produkt "{product_name}".
"""
response_text = call_gemini_api(prompt_text, api_key)
# Return as a simple list of strings
return [cell.strip() for cell in response_text.split(',')]
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--mode', required=True)
@@ -633,10 +667,13 @@ def main():
parser.add_argument('--channels')
parser.add_argument('--language', required=True)
parser.add_argument('--focus_industry') # New argument
parser.add_argument('--product_name')
parser.add_argument('--product_url')
args = parser.parse_args()
try:
if args.mode == 'start_generation': result = start_generation(args.url, args.language, args.regions, args.focus)
elif args.mode == 'next_step': result = next_step(args.language, args.context_file, args.generation_step, args.channels, args.focus_industry)
elif args.mode == 'enrich_product': result = enrich_product(args.product_name, args.product_url, args.language)
sys.stdout.write(json.dumps(result, ensure_ascii=False))
except Exception as e:
logging.error(f"Error: {e}", exc_info=True)