You've already forked RekomenciBackend
add pipline
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
from collections.abc import Sequence
|
||||
from decimal import Decimal
|
||||
from typing import cast
|
||||
|
||||
from httpx import AsyncClient
|
||||
|
||||
from template_project.application.common.data_structure import to_data_structure
|
||||
from template_project.application.resume.entity import ResumeId
|
||||
|
||||
|
||||
@to_data_structure
|
||||
class SuitableVacancyDs:
|
||||
vacancy_id: str
|
||||
from_salary: Decimal
|
||||
to_salary: Decimal
|
||||
key_skills: list[str]
|
||||
resume_similarity: float
|
||||
|
||||
|
||||
@to_data_structure
|
||||
class GenerateResumePredictionResponse:
|
||||
salary_from: Decimal
|
||||
salary_to: Decimal
|
||||
recommended_skills: list[str]
|
||||
|
||||
|
||||
class MlApiGateway:
|
||||
def __init__(self, client: AsyncClient) -> None:
|
||||
self._client = client
|
||||
|
||||
async def generate_embedding(self, text: str) -> list[float]:
|
||||
response = await self._client.post("/get_embedding", json={"text": text})
|
||||
return cast(list[float], response.json()["embedding"])
|
||||
|
||||
async def generate_resume_prediction(
|
||||
self,
|
||||
resume_id: ResumeId,
|
||||
key_skills: list[str],
|
||||
suituble_vacancies: Sequence[SuitableVacancyDs],
|
||||
) -> GenerateResumePredictionResponse:
|
||||
response = await self._client.post(
|
||||
"/predict_salary",
|
||||
json={
|
||||
"resume_id": resume_id,
|
||||
"key_skills": key_skills,
|
||||
"vacancies": [
|
||||
{
|
||||
"vacancy_id": suituble_vacancy.vacancy_id,
|
||||
"from_salary": suituble_vacancy.from_salary,
|
||||
"to_salary": suituble_vacancy.to_salary,
|
||||
"key_skills": suituble_vacancy.key_skills,
|
||||
"resume_similarity": suituble_vacancy.resume_similarity,
|
||||
} for suituble_vacancy in suituble_vacancies
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
response_json = response.json()
|
||||
return GenerateResumePredictionResponse(
|
||||
salary_from=response_json["salary_from"],
|
||||
salary_to=response_json["salary_to"],
|
||||
recommended_skills=response_json["recommended_skills"],
|
||||
)
|
||||
Reference in New Issue
Block a user