in src/psearch/gen_ai/services/marketing_service.py [0:0]
def _parse_response(self, response_text: str) -> str:
"""Parse and clean the response from the Gemini model"""
# For marketing content, we typically want the raw text response
# Just do some basic cleaning
cleaned_text = response_text.strip()
# Remove any JSON formatting if present (the model might mistakenly return JSON)
try:
parsed_json = json.loads(cleaned_text)
if isinstance(parsed_json, dict) and "content" in parsed_json:
return parsed_json["content"]
if isinstance(parsed_json, str):
return parsed_json
except json.JSONDecodeError:
# Not JSON, which is fine
pass
return cleaned_text