Skip to content

Commit

Permalink
Merge pull request #32 from SAIG-KMITL/fix/generate-roadmap
Browse files Browse the repository at this point in the history
fix: post process recommended_course, make sure it is valid
  • Loading branch information
MAOK-Yongsuk authored Nov 28, 2024
2 parents 0c67c08 + f31efa0 commit 29f31f0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions internal/roadmap_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,30 @@ def generate_roadmap(user_input: Dict[str, Any], courses: List[Dict[str, Any]])
workflow = create_roadmap_workflow()
final_state = workflow.invoke(initial_state)

# Post process - Update the validated roadmap with filtered courses
filtered_courses, total_duration = validated_roadmap_course(courses, final_state["validated_roadmap"]['validated_roadmap']["recommended_courses"])
final_state["validated_roadmap"]['validated_roadmap']["recommended_courses"] = filtered_courses
final_state["validated_roadmap"]['validated_roadmap']["total_duration"] = total_duration
# Extract roadmap from the final state
return final_state["validated_roadmap"]

def validated_roadmap_course(courses: List[Any], validated_roadmap: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
# Extract valid course IDs from the courses list
valid_course_ids = {course.id for course in courses}

# Track seen IDs to ensure only the first occurrence is added, also update new total_duration
seen_ids = set()
unique_courses = []
total_duration = 0

for course in validated_roadmap:
if course["id"] in valid_course_ids and course["id"] not in seen_ids:
unique_courses.append(course)
seen_ids.add(course["id"])
total_duration += course["duration"]

return unique_courses, total_duration

# -- Example --
# # for test llm
# from utils.mock_data import MockDataGenerator
Expand Down

0 comments on commit 29f31f0

Please sign in to comment.