Spaces:
Runtime error
Runtime error
| from pydantic import BaseModel, Field | |
| from typing import Literal, Optional | |
| from langchain_core.tools import tool | |
| from src.retrievers import get_retriever,get_metadata_retriever | |
| from src.helper import deduplicate_docs, rerank_docs, download_reranker | |
| reranker = download_reranker() | |
| class ClarifyInput(BaseModel): | |
| question: str = Field( | |
| ..., | |
| description=( | |
| "A concise, high-value clarification question " | |
| "that resolves ambiguity materially affecting " | |
| "assessment retrieval or recommendation quality." | |
| ) | |
| ) | |
| def clarify(question: str): | |
| return { | |
| "type": "clarification", | |
| "message": question, | |
| } | |
| class RetrieveInput(BaseModel): | |
| retrieval_query: str = Field( | |
| ..., | |
| description=( | |
| "A rewritten semantic retrieval query optimized " | |
| "for searching SHL assessments." | |
| ) | |
| ) | |
| job_level: list[Literal['Front Line Manager', 'General Population', 'Graduate', 'Mid-Professional', 'Director', 'Entry-Level', 'Executive', 'Professional Individual Contributor', 'Manager', 'Supervisor']] | None = Field( | |
| default=None, | |
| description=( | |
| "Relevant job seniority levels if inferable " | |
| "from the conversation." | |
| ) | |
| ) | |
| assessment_focus: list[Literal['Competencies', 'Personality & Behavior', 'Simulations', 'Knowledge & Skills', 'Development & 360', 'Ability & Aptitude', 'Assessment Exercises', 'Biodata & Situational Judgment']] | None = Field( | |
| default=None, | |
| description=( | |
| "Important assessment dimensions such as " | |
| "personality, cognitive, simulations, " | |
| "technical skills, leadership, safety, " | |
| "customer service, or situational judgement." | |
| ) | |
| ) | |
| languages: Optional[list[Literal['English (Australia)', 'Danish', 'Flemish', 'Finnish', 'Chinese Traditional', 'Portuguese (Brazil)', 'Lithuanian', 'Estonian', 'Chinese Simplified', 'Swedish', 'Italian', 'Hungarian', 'Czech', 'Portuguese', 'Russian', 'Thai', 'Vietnamese', 'French (Belgium)', 'Japanese', 'Dutch', 'Latin American Spanish', 'Arabic', 'Malay', 'Polish', 'Romanian', 'Norwegian', 'Korean', 'German', 'Greek', 'Icelandic', 'English International', 'French (Canada)', 'Spanish', 'English (Canada)', 'English (South Africa)', 'Slovak', 'English (USA)', 'French', 'Latvian', 'Turkish', 'Serbian', 'Indonesian']]] | None = Field( | |
| default=["English (USA)"], | |
| description=( | |
| "Relevant candidate or assessment languages " | |
| "if mentioned." | |
| ) | |
| ) | |
| def retrieve( | |
| retrieval_query: str, | |
| job_level=None, | |
| languages=None, | |
| assessment_focus=None | |
| ): | |
| retriever = get_retriever(k=10) | |
| docs = retriever.invoke(retrieval_query) | |
| retriever2 = get_metadata_retriever(job_level, assessment_focus, languages, k=10) | |
| docs2 = retriever2.invoke(retrieval_query) if retriever2 else [] | |
| dedup_docs = deduplicate_docs(docs, docs2) | |
| ranked_docs = rerank_docs(reranker,retrieval_query, dedup_docs, top_k=10) | |
| return { | |
| "type": "retrieval", | |
| "message": retrieval_query, | |
| "docs": ranked_docs | |
| } | |
| class InjectionHandleInput(BaseModel): | |
| response: str = Field( | |
| ..., | |
| description=( | |
| "A safe refusal response explaining that the " | |
| "assistant only supports SHL assessment recommendations." | |
| ) | |
| ) | |
| def injection_handle(response: str): | |
| return { | |
| "type": "refusal", | |
| "message": response, | |
| } | |