Spaces:
Running
Running
| import time | |
| from fastapi import APIRouter | |
| from uuid import uuid4 | |
| # from externals.databases.pg_crud import get_all_cv_profiles, get_cv_profile_with_scores | |
| from externals.databases.database import get_db | |
| from services.agentic.agentic_setup import AgenticService | |
| from services.knowledge.knowledge_setup import KnowledgeService | |
| from services.models.data_model import (Criteria, | |
| CriteriaWeight, | |
| PayloadMatchOne, | |
| ResponseMatchOne, | |
| DataResponseMatchOne, | |
| PayloadMatchBulk, | |
| ResponseMatchBulk, | |
| DataResponseMatchBulk) | |
| from interfaces.api.deps import get_current_user | |
| from fastapi import APIRouter, UploadFile, File, Depends, status, HTTPException | |
| from externals.databases.pg_models import CVUser, CVFilter, CVWeight | |
| from utils.logger import get_logger | |
| logger = get_logger("agentic service") | |
| router = APIRouter( | |
| prefix="/agentic", | |
| tags=["Agentic"], | |
| ) | |
| async def create_filter( | |
| filter: Criteria, | |
| db=Depends(get_db), | |
| current_user: CVUser = Depends(get_current_user), | |
| ): | |
| try: | |
| agentic_service = AgenticService(db=db, | |
| user=current_user) | |
| cv_filter = CVFilter( | |
| criteria_id=uuid4(), | |
| gpa_edu_1=filter.get("gpa_edu_1"), | |
| gpa_edu_2=filter.get("gpa_edu_2"), | |
| gpa_edu_3=filter.get("gpa_edu_3"), | |
| univ_edu_1=filter.get("univ_edu_1"), | |
| univ_edu_2=filter.get("univ_edu_2"), | |
| univ_edu_3=filter.get("univ_edu_3"), | |
| major_edu_1=filter.get("major_edu_1"), | |
| major_edu_2=filter.get("major_edu_2"), | |
| major_edu_3=filter.get("major_edu_3"), | |
| domicile=filter.get("domicile"), | |
| yoe=filter.get("yoe"), | |
| hardskills=filter.get("hardskills"), | |
| softskills=filter.get("softskills"), | |
| certifications=filter.get("certifications"), | |
| business_domain=filter.get("business_domain") | |
| ) | |
| logger.info(f"cv_filter: {cv_filter}") | |
| data = await agentic_service.filter.create_filter(filter=cv_filter) | |
| return { | |
| "status": "success", | |
| "message": "Filter created successfully", | |
| "criteria_id": data | |
| } | |
| except Exception as E: | |
| logger.error(f"create filter error: {E}") | |
| raise HTTPException( | |
| status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, | |
| detail=f"create filter error: {E}" | |
| ) | |
| async def get_filter_by_id( | |
| criteria_id: str, | |
| db=Depends(get_db), | |
| current_user: CVUser = Depends(get_current_user), | |
| ): | |
| agentic_service = AgenticService(db=db, | |
| user=current_user) | |
| data = await agentic_service.filter.get_filter_by_id(criteria_id=criteria_id) | |
| return data | |
| async def create_weight( | |
| criteria_id: str, | |
| weight: CriteriaWeight, | |
| db=Depends(get_db), | |
| current_user: CVUser = Depends(get_current_user), | |
| ): | |
| try: | |
| agentic_service = AgenticService(db=db, | |
| user=current_user) | |
| cv_weight = CVWeight( | |
| criteria_id=criteria_id, | |
| weight_id=uuid4(), | |
| gpa_edu_1=weight.get("gpa_edu_1"), | |
| gpa_edu_2=weight.get("gpa_edu_2"), | |
| gpa_edu_3=weight.get("gpa_edu_3"), | |
| univ_edu_1=weight.get("univ_edu_1"), | |
| univ_edu_2=weight.get("univ_edu_2"), | |
| univ_edu_3=weight.get("univ_edu_3"), | |
| major_edu_1=weight.get("major_edu_1"), | |
| major_edu_2=weight.get("major_edu_2"), | |
| major_edu_3=weight.get("major_edu_3"), | |
| domicile=weight.get("domicile"), | |
| yoe=weight.get("yoe"), | |
| hardskills=weight.get("hardskills"), | |
| softskills=weight.get("softskills"), | |
| certifications=weight.get("certifications"), | |
| business_domain=weight.get("business_domain") | |
| ) | |
| data = await agentic_service.weight.create_weight(weight=cv_weight) | |
| return { | |
| "status": "success", | |
| "message": "Weight created successfully", | |
| "data": data | |
| } | |
| except Exception as E: | |
| logger.error(f"create weight error: {E}") | |
| raise HTTPException( | |
| status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, | |
| detail=f"create weight error: {E}" | |
| ) | |
| async def calculate_score( | |
| weight_id: str, | |
| db=Depends(get_db), | |
| current_user: CVUser = Depends(get_current_user), | |
| ): | |
| try: | |
| agentic_service = AgenticService(db=db, | |
| user=current_user) | |
| data = await agentic_service.score.scoring(weight_id=weight_id) | |
| return { | |
| "status": "success", | |
| "message": "Score calculated successfully", | |
| "data": data | |
| } | |
| except Exception as E: | |
| logger.error(f"calculate score error: {E}") | |
| raise HTTPException( | |
| status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, | |
| detail=f"calculate score error: {E}" | |
| ) | |
| # @router.get("/get_profile_table") | |
| # async def get_profile_table( | |
| # limit: int, | |
| # ): | |
| # data = await get_all_cv_profiles(limit) | |
| # return data | |
| # @router.get("/get_profile_table_and_score") | |
| # async def get_profile_table_and_score( | |
| # criteria_id: str, | |
| # profile_id: str, | |
| # ): | |
| # data = await get_cv_profile_with_scores( | |
| # criteria_id=criteria_id, | |
| # profile_id=profile_id, | |
| # ) | |
| # return data | |
| # @router.post("/match_one") | |
| # async def profile_matching_one( | |
| # payload: PayloadMatchOne, | |
| # ): | |
| # """ | |
| # Generate profile matching score between one profile and one criteria. | |
| # Returns: | |
| # status: str | |
| # message: str | |
| # data: DataResponseExtractOne | |
| # """ | |
| # _start = time.time() | |
| # try: | |
| # agentic = Agent() | |
| # response = await agentic.scoring_profile(input_scoring=payload) | |
| # print(f"response match one profile:", response) | |
| # _end = time.time() - _start | |
| # logger.info(f"API runtime profile scoring: {_end}s") | |
| # return response | |
| # except Exception as E: | |
| # logger.error(f"profile scoring error, {E}") | |
| # _end = time.time() - _start | |
| # logger.info(f"API runtime profile scoring: {_end}s") | |
| # return ResponseMatchOne( | |
| # status="failed", | |
| # message=f"profile scoring error, {E}", | |
| # data=DataResponseMatchOne( | |
| # profile_id=payload.get("profile_id"), | |
| # criteria_id=payload.get("criteria").get("criteria_id"), | |
| # score=0 | |
| # ) | |
| # ) | |
| # @router.post("/match_bulk") | |
| # async def profile_matching_bulk( | |
| # payload: PayloadMatchBulk, | |
| # ): | |
| # """ | |
| # Generate profile matching score between many profiles and one criteria. | |
| # Returns: | |
| # status: str | |
| # message: str | |
| # data: DataResponseExtractOne | |
| # """ | |
| # _start = time.time() | |
| # try: | |
| # agentic = Agent() | |
| # response = await agentic.scoring_profile(input_scoring=payload) | |
| # print(f"response match one profile:", response) | |
| # _end = time.time() - _start | |
| # logger.info(f"API runtime profile scoring: {_end}s") | |
| # return response | |
| # except Exception as E: | |
| # logger.error(f"profile scoring error, {E}") | |
| # _end = time.time() - _start | |
| # logger.info(f"API runtime profile scoring: {_end}s") | |
| # return ResponseMatchBulk( | |
| # status="failed", | |
| # message=f"profile scoring error, {E}", | |
| # data=DataResponseMatchBulk( | |
| # profile_id=payload.get("profile_id"), | |
| # criteria_id=payload.get("criteria").get("criteria_id"), | |
| # score=0 | |
| # ) | |
| # ) |