Spaces:
Sleeping
Sleeping
Doanh Van Vu commited on
Commit ·
71703c8
1
Parent(s): 769cb8f
Refactor recommendation request and mentee query text handling
Browse files- Updated the RecommendationRequest model to remove unnecessary fields and added `mentor_domain_ids` and `career_id` for improved data structure.
- Modified the `build_mentee_query_text` function to reflect changes in the mentee data structure, enhancing clarity by including `career_id`, `domain_ids`, and `mentor_domain_ids` while removing references to `desired_skills`, `current_skills`, and `interests`.
- models/schemas.py +1 -6
- test_api.py +3 -9
- utils/text_builder.py +13 -40
models/schemas.py
CHANGED
|
@@ -51,15 +51,10 @@ class MentorUpsertResponse(BaseModel):
|
|
| 51 |
|
| 52 |
class RecommendationRequest(BaseModel):
|
| 53 |
goals: Optional[str] = None
|
| 54 |
-
desired_skills: Optional[List[Union[SkillDto, Dict[str, Any], str]]] = None
|
| 55 |
-
current_skills: Optional[List[Union[SkillDto, Dict[str, Any], str]]] = None
|
| 56 |
-
interests: Optional[List[Union[DomainDto, Dict[str, Any], str]]] = None
|
| 57 |
-
domains: Optional[List[Union[DomainDto, Dict[str, Any], str]]] = None
|
| 58 |
-
min_rating: Optional[float] = Field(None, ge=0.0, le=5.0)
|
| 59 |
skill_ids: Optional[List[int]] = None
|
| 60 |
domain_ids: Optional[List[int]] = None
|
|
|
|
| 61 |
career_id: Optional[int] = None
|
| 62 |
-
status: Optional[str] = "ACTIVATED"
|
| 63 |
top_k: Optional[int] = Field(None, ge=1, le=100)
|
| 64 |
final_count: Optional[int] = Field(None, ge=1, le=20)
|
| 65 |
|
|
|
|
| 51 |
|
| 52 |
class RecommendationRequest(BaseModel):
|
| 53 |
goals: Optional[str] = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
skill_ids: Optional[List[int]] = None
|
| 55 |
domain_ids: Optional[List[int]] = None
|
| 56 |
+
mentor_domain_ids: Optional[List[int]] = None
|
| 57 |
career_id: Optional[int] = None
|
|
|
|
| 58 |
top_k: Optional[int] = Field(None, ge=1, le=100)
|
| 59 |
final_count: Optional[int] = Field(None, ge=1, le=20)
|
| 60 |
|
test_api.py
CHANGED
|
@@ -10,16 +10,10 @@ def test_recommend():
|
|
| 10 |
|
| 11 |
recommendation_data = {
|
| 12 |
"goals": "Tôi muốn học Python và FastAPI để phát triển web",
|
| 13 |
-
"
|
| 14 |
-
{"id": 1, "name": "Python"},
|
| 15 |
-
{"id": 2, "name": "FastAPI"}
|
| 16 |
-
],
|
| 17 |
-
"interests": [
|
| 18 |
-
{"id": 1, "name": "Web Development"}
|
| 19 |
-
],
|
| 20 |
-
"min_rating": 4.0,
|
| 21 |
-
"skill_ids": [1, 2],
|
| 22 |
"domain_ids": [1],
|
|
|
|
|
|
|
| 23 |
"top_k": 30,
|
| 24 |
"final_count": 6
|
| 25 |
}
|
|
|
|
| 10 |
|
| 11 |
recommendation_data = {
|
| 12 |
"goals": "Tôi muốn học Python và FastAPI để phát triển web",
|
| 13 |
+
"career_id": 1,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
"domain_ids": [1],
|
| 15 |
+
"mentor_domain_ids": [2, 3],
|
| 16 |
+
"skill_ids": [1, 2],
|
| 17 |
"top_k": 30,
|
| 18 |
"final_count": 6
|
| 19 |
}
|
utils/text_builder.py
CHANGED
|
@@ -108,48 +108,21 @@ def build_mentee_query_text(mentee_data: Dict[str, Any]) -> str:
|
|
| 108 |
if goals:
|
| 109 |
parts.append(f"Goals: {goals}")
|
| 110 |
|
| 111 |
-
|
| 112 |
-
if
|
| 113 |
-
|
| 114 |
-
for skill in desired_skills:
|
| 115 |
-
if isinstance(skill, dict):
|
| 116 |
-
skill_names.append(skill.get("name", ""))
|
| 117 |
-
elif isinstance(skill, str):
|
| 118 |
-
skill_names.append(skill)
|
| 119 |
-
if skill_names:
|
| 120 |
-
parts.append(f"Desired Skills: {', '.join(skill_names)}")
|
| 121 |
|
| 122 |
-
|
| 123 |
-
if
|
| 124 |
-
|
| 125 |
-
for skill in current_skills:
|
| 126 |
-
if isinstance(skill, dict):
|
| 127 |
-
skill_names.append(skill.get("name", ""))
|
| 128 |
-
elif isinstance(skill, str):
|
| 129 |
-
skill_names.append(skill)
|
| 130 |
-
if skill_names:
|
| 131 |
-
parts.append(f"Current Skills: {', '.join(skill_names)}")
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
elif isinstance(domain, str):
|
| 141 |
-
domain_names.append(domain)
|
| 142 |
-
if domain_names:
|
| 143 |
-
parts.append(f"Interests: {', '.join(domain_names)}")
|
| 144 |
-
elif domains:
|
| 145 |
-
domain_names = []
|
| 146 |
-
for domain in domains:
|
| 147 |
-
if isinstance(domain, dict):
|
| 148 |
-
domain_names.append(domain.get("name", ""))
|
| 149 |
-
elif isinstance(domain, str):
|
| 150 |
-
domain_names.append(domain)
|
| 151 |
-
if domain_names:
|
| 152 |
-
parts.append(f"Interests: {', '.join(domain_names)}")
|
| 153 |
|
| 154 |
return "\n".join(parts)
|
| 155 |
|
|
|
|
| 108 |
if goals:
|
| 109 |
parts.append(f"Goals: {goals}")
|
| 110 |
|
| 111 |
+
career_id = mentee_data.get("career_id")
|
| 112 |
+
if career_id:
|
| 113 |
+
parts.append(f"Career ID: {career_id}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
+
domain_ids = mentee_data.get("domain_ids", [])
|
| 116 |
+
if domain_ids:
|
| 117 |
+
parts.append(f"Preferred Domains (IDs): {', '.join(map(str, domain_ids))}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
+
mentor_domain_ids = mentee_data.get("mentor_domain_ids", [])
|
| 120 |
+
if mentor_domain_ids:
|
| 121 |
+
parts.append(f"Previous Mentor Domains (IDs): {', '.join(map(str, mentor_domain_ids))}")
|
| 122 |
+
|
| 123 |
+
skill_ids = mentee_data.get("skill_ids", [])
|
| 124 |
+
if skill_ids:
|
| 125 |
+
parts.append(f"Skills of Previous Mentors (IDs): {', '.join(map(str, skill_ids))}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
return "\n".join(parts)
|
| 128 |
|