Spaces:
Running
Running
sunheycho
commited on
Commit
·
a640033
1
Parent(s):
4b79c41
Fix confidence score parsing error in RecommendationAgent
Browse files- Handle malformed confidence strings like '0.70.70.70...'
- Extract first valid decimal number from repeated values
- Add error handling for confidence parsing with fallback to 'Unknown'
- Prevents int() conversion failure that caused session errors
- product_comparison.py +10 -1
product_comparison.py
CHANGED
@@ -912,7 +912,16 @@ class RecommendationAgent(BaseAgent):
|
|
912 |
|
913 |
# Log confidence
|
914 |
confidence = recommendation.get('confidence', 0)
|
915 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
916 |
self.log(session_id, f"Confidence in recommendation: {confidence_percent}")
|
917 |
|
918 |
self.log(session_id, "Recommendation generation completed")
|
|
|
912 |
|
913 |
# Log confidence
|
914 |
confidence = recommendation.get('confidence', 0)
|
915 |
+
try:
|
916 |
+
# Handle various confidence formats
|
917 |
+
if isinstance(confidence, str):
|
918 |
+
# Extract first valid number from string like '0.70.70.70...'
|
919 |
+
confidence_clean = confidence.split('.')[0] + '.' + confidence.split('.')[1] if '.' in confidence else confidence
|
920 |
+
confidence = float(confidence_clean)
|
921 |
+
confidence = float(confidence)
|
922 |
+
confidence_percent = f"{int(confidence * 100)}%"
|
923 |
+
except (ValueError, IndexError):
|
924 |
+
confidence_percent = "Unknown"
|
925 |
self.log(session_id, f"Confidence in recommendation: {confidence_percent}")
|
926 |
|
927 |
self.log(session_id, "Recommendation generation completed")
|