Untitled

 avatar
unknown
python
9 months ago
1.2 kB
9
Indexable
def _evaluate_single_match(topic: str, profile_text: str) -> Optional[Dict[str, Any]]:
    """
    Ask the LLM to score how well a training profile matches a topic and return a dict.
    """
    try:
        parsed = evaluate_training_match(topic, profile_text)  # returns a dict
        if not parsed:
            logger.warning("No response from evaluate_training_match. Topic=%r", topic)
            return None

        # If some caller ever returns a JSON string, make it robust:
        if isinstance(parsed, str):
            try:
                import json
                parsed = json.loads(parsed)
            except Exception:
                logger.error("evaluate_training_match returned non-dict/non-JSON")
                return None

        # Normalize fields with safe defaults.
        return {
            "score": parsed.get("score", 0),
            "matched_keywords": parsed.get("matched_keywords", []) or [],
            "missing_keywords": parsed.get("missing_keywords", []) or [],
            "explanation": parsed.get("explanation", "") or "",
        }
    except Exception as e:
        logger.error("Error during evaluate_training_match. Topic=%r | %s", topic, e)
        return None
Editor is loading...
Leave a Comment