Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/app/services/tutor/agents.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
import json
from pathlib import Path

from langchain_core.language_models import BaseChatModel
Expand All @@ -11,6 +12,25 @@

logger = utils_logger(__name__)


_DISCIPLINARY_SKILLS = None


def get_disciplinary_skills():
global _DISCIPLINARY_SKILLS
if _DISCIPLINARY_SKILLS is None:
try:
path = Path(__file__).parent / "disciplinary_skills.json"
with open(path, "r", encoding="utf-8") as f:
_DISCIPLINARY_SKILLS = {
d["code_rncp"]: d["skills"] for d in json.load(f)["disciplines"]
}
except Exception:
# Handle error, log, or provide fallback
_DISCIPLINARY_SKILLS = {}
return _DISCIPLINARY_SKILLS


# TODO: add template file move this to utils
TEMPLATES = {"template0": Path("src/app/services/tutor/template.md").read_text()}

Expand Down Expand Up @@ -59,6 +79,7 @@ def __init__(self, model: BaseChatModel, lang) -> None:
super().__init__("UniversityTeacherAgent", model, system_prompt)

async def generate(self, message: MessageWithResources) -> SyllabusResponseAgent:
DISCIPLINARY_SKILLS = get_disciplinary_skills()
contents = "summary :".join(message.summary)
themes = ",".join([theme["theme"] for theme in message.themes])
prompt = (
Expand All @@ -67,6 +88,7 @@ async def generate(self, message: MessageWithResources) -> SyllabusResponseAgent
f"The syllabus should be written in lang: {message.lang} the section names must also be written in {message.lang}, this is important \n\nTEXT CONTENTS:\n{contents}\n\n"
f"THEMES:\n{themes} \n\nTake into account the users input courses title, level, duration and "
f"description: {message.course_title}, {message.level}, {message.duration}, {message.description}."
f"{('\n\nThe syllabus should also contribute to build the following disciplinary skills:'+'\n- '.join(DISCIPLINARY_SKILLS[message.discipline])) if message.discipline in DISCIPLINARY_SKILLS.keys() else ''}"
)
response = await self.run(prompt)
return SyllabusResponseAgent(content=response, source=self.name)
Expand Down
Loading