Spaces:
Sleeping
🚨 CRITICAL BUG FIX: Resolve 'NoneType' and 'str' concatenation error
Browse filesERROR FIXED: 'unsupported operand type(s) for +=: NoneType and str'
ROOT CAUSE ANALYSIS:
❌ _extract_eligibility() and _extract_office_info() methods
❌ line.replace('**', '').strip() could return None in edge cases
❌ Attempting result += string with None caused TypeError
DEFENSIVE FIXES APPLIED:
✅ Added proper null checking for all string operations
✅ Added try-catch blocks with proper error logging
✅ Added fallback return values for all extraction methods
✅ Protected against empty/None response strings
✅ Enhanced error handling throughout extraction pipeline
METHODS FIXED:
✅ _extract_eligibility() - Now handles None/empty strings
✅ _extract_office_info() - Added null safety
✅ Proper fallback responses for both methods
RESULT:
- No more 'NoneType' += str errors
- Graceful degradation when text parsing fails
- Clean error logging for debugging
- Stable response generation
Ready for testing - should eliminate backend errors! 🎯
- groq_websocket_handler.py +30 -18
|
@@ -852,18 +852,25 @@ class GroqWebSocketHandler:
|
|
| 852 |
|
| 853 |
def _extract_eligibility(self, response: str) -> str:
|
| 854 |
"""Extract eligibility criteria from response"""
|
| 855 |
-
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
|
| 865 |
-
|
| 866 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 867 |
|
| 868 |
return "राजस्थान सरकार के कर्मचारी / Rajasthan Government Employees"
|
| 869 |
|
|
@@ -892,12 +899,17 @@ class GroqWebSocketHandler:
|
|
| 892 |
|
| 893 |
def _extract_office_info(self, response: str) -> str:
|
| 894 |
"""Extract office information from response"""
|
| 895 |
-
|
| 896 |
-
|
| 897 |
-
|
| 898 |
-
|
| 899 |
-
|
| 900 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 901 |
|
| 902 |
return "जिला कलेक्टर कार्यालय / District Collector Office"
|
| 903 |
|
|
|
|
| 852 |
|
| 853 |
def _extract_eligibility(self, response: str) -> str:
|
| 854 |
"""Extract eligibility criteria from response"""
|
| 855 |
+
try:
|
| 856 |
+
eligibility_keywords = ['eligible', 'eligibility', 'पात्र', 'पात्रता']
|
| 857 |
+
lines = response.split('\n') if response else []
|
| 858 |
+
|
| 859 |
+
for i, line in enumerate(lines):
|
| 860 |
+
if line and any(keyword in line.lower() for keyword in eligibility_keywords):
|
| 861 |
+
# Return the line and maybe the next one
|
| 862 |
+
result = line.replace('**', '').strip() if line else ""
|
| 863 |
+
if not result:
|
| 864 |
+
continue
|
| 865 |
+
|
| 866 |
+
if i + 1 < len(lines):
|
| 867 |
+
next_line = lines[i + 1].strip() if lines[i + 1] else ""
|
| 868 |
+
if len(next_line) > 10 and not next_line.startswith('#'):
|
| 869 |
+
result += f"\n{next_line}"
|
| 870 |
+
return result
|
| 871 |
+
except Exception as e:
|
| 872 |
+
logger.error(f"❌ Error extracting eligibility: {e}")
|
| 873 |
+
return "राजस्थान सरकार के कर्मचारी / Rajasthan Government Employees"
|
| 874 |
|
| 875 |
return "राजस्थान सरकार के कर्मचारी / Rajasthan Government Employees"
|
| 876 |
|
|
|
|
| 899 |
|
| 900 |
def _extract_office_info(self, response: str) -> str:
|
| 901 |
"""Extract office information from response"""
|
| 902 |
+
try:
|
| 903 |
+
office_keywords = ['office', 'department', 'collector', 'कार्यालय', 'विभाग', 'कलेक्टर']
|
| 904 |
+
lines = response.split('\n') if response else []
|
| 905 |
+
|
| 906 |
+
for line in lines:
|
| 907 |
+
if line and any(keyword in line.lower() for keyword in office_keywords):
|
| 908 |
+
cleaned_line = line.replace('**', '').strip() if line else ""
|
| 909 |
+
if cleaned_line:
|
| 910 |
+
return cleaned_line
|
| 911 |
+
except Exception as e:
|
| 912 |
+
logger.error(f"❌ Error extracting office info: {e}")
|
| 913 |
|
| 914 |
return "जिला कलेक्टर कार्यालय / District Collector Office"
|
| 915 |
|