Spaces:
Sleeping
Sleeping
axeronis commited on
Commit ·
4d35386
1
Parent(s): 30ba090
Fix: Resolved GeminiLLMClient method error in name extraction and fixed CRM auto-sync NoneType error
Browse files
backend/app/services/ai_core/lead_analyzer.py
CHANGED
|
@@ -520,6 +520,9 @@ async def trigger_crm_auto_sync(
|
|
| 520 |
lead: Lead
|
| 521 |
) -> None:
|
| 522 |
"""Trigger automatic CRM synchronization if enabled."""
|
|
|
|
|
|
|
|
|
|
| 523 |
try:
|
| 524 |
if lead.heat_level != LeadHeat.HOT:
|
| 525 |
return # Only sync hot leads
|
|
|
|
| 520 |
lead: Lead
|
| 521 |
) -> None:
|
| 522 |
"""Trigger automatic CRM synchronization if enabled."""
|
| 523 |
+
if not CRM_AVAILABLE or not CRMIntegration:
|
| 524 |
+
return
|
| 525 |
+
|
| 526 |
try:
|
| 527 |
if lead.heat_level != LeadHeat.HOT:
|
| 528 |
return # Only sync hot leads
|
backend/app/services/llm_client.py
CHANGED
|
@@ -43,9 +43,9 @@ class GeminiLLMClient:
|
|
| 43 |
|
| 44 |
logger.info(f"✅ Gemini LLM client initialized (model: {self.default_model_name})")
|
| 45 |
|
| 46 |
-
async def generate_text(self, prompt: str) -> str:
|
| 47 |
"""Convenience method for text-only response."""
|
| 48 |
-
resp = await self.generate_response(prompt)
|
| 49 |
return resp["text"]
|
| 50 |
|
| 51 |
async def generate_response(
|
|
@@ -57,7 +57,8 @@ class GeminiLLMClient:
|
|
| 57 |
temperature: Optional[float] = None,
|
| 58 |
max_retries: int = 3,
|
| 59 |
priority: int = 5,
|
| 60 |
-
media_parts: Optional[List[Any]] = None
|
|
|
|
| 61 |
) -> Dict[str, Any]:
|
| 62 |
"""
|
| 63 |
Generate AI response using Gemini 1.5.
|
|
@@ -71,7 +72,8 @@ class GeminiLLMClient:
|
|
| 71 |
chat_history=chat_history,
|
| 72 |
temperature=temperature,
|
| 73 |
max_retries=max_retries,
|
| 74 |
-
media_parts=media_parts
|
|
|
|
| 75 |
)
|
| 76 |
|
| 77 |
async def _generate_response_internal(
|
|
@@ -82,14 +84,15 @@ class GeminiLLMClient:
|
|
| 82 |
chat_history: Optional[List[Dict[str, Any]]] = None,
|
| 83 |
temperature: Optional[float] = None,
|
| 84 |
max_retries: int = 3,
|
| 85 |
-
media_parts: Optional[List[Any]] = None
|
|
|
|
| 86 |
) -> Dict[str, Any]:
|
| 87 |
"""Internal Gemini call."""
|
| 88 |
|
| 89 |
# Base Configuration
|
| 90 |
config = types.GenerateContentConfig(
|
| 91 |
temperature=temperature or 0.7,
|
| 92 |
-
max_output_tokens=2048, #
|
| 93 |
system_instruction=system_instruction
|
| 94 |
)
|
| 95 |
|
|
|
|
| 43 |
|
| 44 |
logger.info(f"✅ Gemini LLM client initialized (model: {self.default_model_name})")
|
| 45 |
|
| 46 |
+
async def generate_text(self, prompt: str, max_output_tokens: Optional[int] = None) -> str:
|
| 47 |
"""Convenience method for text-only response."""
|
| 48 |
+
resp = await self.generate_response(prompt, max_output_tokens=max_output_tokens)
|
| 49 |
return resp["text"]
|
| 50 |
|
| 51 |
async def generate_response(
|
|
|
|
| 57 |
temperature: Optional[float] = None,
|
| 58 |
max_retries: int = 3,
|
| 59 |
priority: int = 5,
|
| 60 |
+
media_parts: Optional[List[Any]] = None,
|
| 61 |
+
max_output_tokens: Optional[int] = None
|
| 62 |
) -> Dict[str, Any]:
|
| 63 |
"""
|
| 64 |
Generate AI response using Gemini 1.5.
|
|
|
|
| 72 |
chat_history=chat_history,
|
| 73 |
temperature=temperature,
|
| 74 |
max_retries=max_retries,
|
| 75 |
+
media_parts=media_parts,
|
| 76 |
+
max_output_tokens=max_output_tokens
|
| 77 |
)
|
| 78 |
|
| 79 |
async def _generate_response_internal(
|
|
|
|
| 84 |
chat_history: Optional[List[Dict[str, Any]]] = None,
|
| 85 |
temperature: Optional[float] = None,
|
| 86 |
max_retries: int = 3,
|
| 87 |
+
media_parts: Optional[List[Any]] = None, # List of types.Part
|
| 88 |
+
max_output_tokens: Optional[int] = None
|
| 89 |
) -> Dict[str, Any]:
|
| 90 |
"""Internal Gemini call."""
|
| 91 |
|
| 92 |
# Base Configuration
|
| 93 |
config = types.GenerateContentConfig(
|
| 94 |
temperature=temperature or 0.7,
|
| 95 |
+
max_output_tokens=max_output_tokens or 2048, # Default to 2048
|
| 96 |
system_instruction=system_instruction
|
| 97 |
)
|
| 98 |
|
backend/app/utils/name_extraction.py
CHANGED
|
@@ -148,7 +148,7 @@ async def _extract_name_with_llm(text: str, llm_client) -> Optional[str]:
|
|
| 148 |
|
| 149 |
Ответ (имя или NONE):"""
|
| 150 |
|
| 151 |
-
response = await llm_client.
|
| 152 |
extracted = response.strip().strip('"').strip("'").strip(".")
|
| 153 |
|
| 154 |
# Clean up response
|
|
|
|
| 148 |
|
| 149 |
Ответ (имя или NONE):"""
|
| 150 |
|
| 151 |
+
response = await llm_client.generate_text(prompt, max_output_tokens=20)
|
| 152 |
extracted = response.strip().strip('"').strip("'").strip(".")
|
| 153 |
|
| 154 |
# Clean up response
|