From bce2312044c184dd411ef8da36258790f225cb02 Mon Sep 17 00:00:00 2001 From: sunith vs <63339782+sunithvs@users.noreply.github.com> Date: Sat, 17 May 2025 20:58:17 +0400 Subject: [PATCH] feat: clean profile summary --- modules/ai_generator.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/ai_generator.py b/modules/ai_generator.py index ca08cf52..953ee4c7 100644 --- a/modules/ai_generator.py +++ b/modules/ai_generator.py @@ -3,6 +3,7 @@ from groq import Groq from config.settings import Settings +import re class AIDescriptionGenerator: @@ -12,6 +13,18 @@ def __init__(self): """Initialize Groq client""" self.client = Groq(api_key=Settings.get_groq_key()) + @staticmethod + def _clean_summary(text: str) -> str: + """Remove leading phrases like 'here the summary' from the output""" + patterns = [ + r"^\s*here(?:'s| is)?\s+(?:the\s+)?summary[:,]?\s*", + r"^\s*summary[:,]?\s*", + ] + cleaned = text + for pattern in patterns: + cleaned = re.sub(pattern, "", cleaned, flags=re.IGNORECASE) + return cleaned.strip() + def generate_profile_summary(self, profile_data): """ Generate a professional profile summary @@ -54,7 +67,8 @@ def generate_profile_summary(self, profile_data): if not response.choices or response.choices[0].message.content == "": raise Exception("No response from AI model") - return response.choices[0].message.content + raw_text = response.choices[0].message.content + return self._clean_summary(raw_text) def generate_activity_summary(self, contributions): """