import os import requests def query_modal_gpt(prompt): token_id = os.getenv("MODAL_TOKEN_ID") token_secret = os.getenv("MODAL_TOKEN_SECRET") url = "https://api.modal.com/gpt" # Update if Modal gives you another endpoint headers = { "Authorization": f"Bearer {token_id}:{token_secret}", "Content-Type": "application/json" } data = { "model": "gpt-4", "messages": [ {"role": "system", "content": "You are a GEO scoring and optimization expert."}, {"role": "user", "content": prompt} ] } response = requests.post(url, headers=headers, json=data) return response.json()["choices"][0]["message"]["content"] def generate_blog_titles(keyword: str) -> str: prompt = ( f"Generate 3 catchy blog titles featuring '{keyword}', " "focused on personal branding and visibility in AI models:" ) return query_modal_gpt(prompt) def generate_jsonld_schema(keyword: str) -> str: prompt = ( f"Create a JSON-LD 'Person' schema snippet for '{keyword}', " "including name, description, and URL." ) return query_modal_gpt(prompt) def rewrite_prompt(keyword: str) -> str: prompt = ( f"Rewrite the prompt 'Tell me about {keyword}' " "to sound more authoritative and AI-SEO-friendly." ) return query_modal_gpt(prompt) def get_optimizations(keyword: str) -> dict: return { "blog_titles": generate_blog_titles(keyword), "json_ld": generate_jsonld_schema(keyword), "rewritten_prompt": rewrite_prompt(keyword) }