diff --git a/k8s/welearn-api/values.dev.yaml b/k8s/welearn-api/values.dev.yaml index 7de324c..34239cc 100644 --- a/k8s/welearn-api/values.dev.yaml +++ b/k8s/welearn-api/values.dev.yaml @@ -4,7 +4,7 @@ ingress: config: nonSensitive: AZURE_API_BASE: "https://apim-welearn-openai.azure-api.net" - AZURE_GPT_40_API_BASE: "https://welearn-openai-sweden.openai.azure.com" + AZURE_GPT_4O_API_BASE: "https://welearn-openai-sweden.openai.azure.com" PG_HOST: dev-lab-projects-backend.postgres.database.azure.com AZURE_LLAMA_31_8B_API_BASE: https://meta-llama-3-1-8b-instruct-wl.swedencentral.models.ai.azure.com/ AZURE_LLAMA_31_70B_API_BASE: https://meta-llama-3-1-70b-instruct-wl.swedencentral.models.ai.azure.com/ diff --git a/k8s/welearn-api/values.prod.yaml b/k8s/welearn-api/values.prod.yaml index 30f6c69..f983c89 100644 --- a/k8s/welearn-api/values.prod.yaml +++ b/k8s/welearn-api/values.prod.yaml @@ -4,7 +4,7 @@ ingress: config: nonSensitive: AZURE_API_BASE: "https://apim-welearn-openai.azure-api.net" - AZURE_GPT_40_API_BASE: "https://welearn-openai-sweden.openai.azure.com" + AZURE_GPT_4O_API_BASE: "https://welearn-openai-sweden.openai.azure.com" PG_HOST: prod-prod-projects-backend.postgres.database.azure.com AZURE_LLAMA_31_8B_API_BASE: https://meta-llama-3-1-8b-instruct-wl.swedencentral.models.ai.azure.com/ AZURE_LLAMA_31_70B_API_BASE: https://meta-llama-3-1-70b-instruct-wl.swedencentral.models.ai.azure.com/ diff --git a/k8s/welearn-api/values.yaml b/k8s/welearn-api/values.yaml index 27cb03b..13ef4da 100644 --- a/k8s/welearn-api/values.yaml +++ b/k8s/welearn-api/values.yaml @@ -39,7 +39,7 @@ config: CORPUS: conversation MODELS_FOLDER_ROOTS: "/models" AZURE_API_BASE: "https://welearn-openai.openai.azure.com/openai/" - AZURE_GPT_40_API_BASE: "https://welearn-openai-sweden.openai.azure.com/" + AZURE_GPT_4O_API_BASE: "https://welearn-openai-sweden.openai.azure.com/" CLIENT_ORIGINS_REGEX: '^{{ join "|" (values .Values.allowedHostsRegexes | sortAlpha ) }}$' PG_USER: welearn_datastack PG_DATABASE: welearn_datastack diff --git a/src/app/services/tutor/agents.py b/src/app/services/tutor/agents.py index 780a167..64301e5 100644 --- a/src/app/services/tutor/agents.py +++ b/src/app/services/tutor/agents.py @@ -70,8 +70,6 @@ def __init__(self, model_client: ChatCompletionClient) -> None: "Assessment Methods: Propose methods to evaluate student progress." "Course Schedule: Create a week-by-week breakdown with key topics and associated learning outcomes." "References: Include all sources that you use to construct the syllabus." - "3. Save a file to the current directory:" - f"Syllabus File: Contains the drafted syllabus based on the provided template. You must follow this template :\n {TEMPLATES['template0']}. Name the file: uni-prof_syllabus.md" ), expected_output=f"You must follow this template :\n {TEMPLATES['template0']}", ) @@ -81,9 +79,19 @@ def __init__(self, model_client: ChatCompletionClient) -> None: @message_handler async def handle_documents_and_themes( - self, message: TutorSearchResponse, ctx: MessageContext + self, message: MessageWithResources, ctx: MessageContext ) -> None: - prompt = f"Using the content in TEXT CONTENTS, you generate a syllabus that is engaging and coherent in relation to the THEMES extracted from these contents. \n\nTEXT CONTENTS:\n{message.extracts[0].original_document}\n\nTHEMES:\n{message.extracts[0].themes}" + contents = [] + for curr_content in message.content: + if isinstance(curr_content, TutorSearchResponse): + contents.append(curr_content.extracts) + + themes = [] + for curr_content in contents: + if isinstance(curr_content, TutorSearchResponse): + themes.extend(curr_content.extracts) + + prompt = f"Using the content in TEXT CONTENTS, you generate a syllabus that is engaging and coherent in relation to the THEMES extracted from these contents. \n\nTEXT CONTENTS:\n{contents}\n\nTHEMES:\n{themes}" start_time = time.time() llm_result = await self._model_client.create( @@ -102,7 +110,7 @@ async def handle_documents_and_themes( await self.publish_message( MessageWithResources( - content=response, resources=message.documents, source=self.id.type + content=response, resources=message.resources, source=self.id.type ), topic_id=TopicId(sdg_expert_topic_type, source=self.id.key), ) @@ -139,8 +147,7 @@ def __init__(self, model_client: ChatCompletionClient, memory: ListMemory) -> No "References: NEVER delete, summarize, or modify any references already present in the syllabus. Only append this section with any additional sources that you use to construct the syllabus. " ), expected_output=( - f"1. Final Syllabus File: The revised syllabus, ready for the pedagogical engineer's review. You must follow this template :\n {TEMPLATES['template0']}. Name the file: SDG-exp_syllabus.md" - "When you are done with generating the final output, reply with SDG EXPERT DONE." + f"1. The revised syllabus, ready for the pedagogical engineer's review. You must follow this template :\n {TEMPLATES['template0']}." ), ), memory=[memory], @@ -217,9 +224,7 @@ def __init__(self, model_client: ChatCompletionClient, memory: ListMemory) -> No "3. Check for consistency, clarity, and overall syllabus coherence to ensure usability for instructors." ), expected_output=( - "Save a to the current directory:" - f"1. Final Syllabus File: The polished syllabus, ready for user review. You must follow this template :\n {TEMPLATES['template0']}. Name the file: peda-eng_syllabus.md" - "When you are done with generating the final output, reply with TERMINATE." + f"1. Final Syllabus: The polished syllabus, ready for user review. You must follow this template :\n {TEMPLATES['template0']}." ), ), memory=[memory], diff --git a/src/app/services/tutor/models.py b/src/app/services/tutor/models.py index ec22284..d08e2f6 100644 --- a/src/app/services/tutor/models.py +++ b/src/app/services/tutor/models.py @@ -38,8 +38,8 @@ class MessageWithAnalysis(BaseModel): class MessageWithResources(BaseModel): - content: Dict | str - resources: List[Document] + content: list[ExtractorOutput] | str + resources: List[Dict] source: str = "default" diff --git a/src/app/services/tutor/tutor.py b/src/app/services/tutor/tutor.py index 7df1168..d68d255 100644 --- a/src/app/services/tutor/tutor.py +++ b/src/app/services/tutor/tutor.py @@ -22,7 +22,8 @@ sdg_expert_topic_type, university_teacher_topic_type, ) -from src.app.services.tutor.models import Message, TaskResponse, TutorSearchResponse +from src.app.services.tutor.models import Message, TaskResponse, TutorSearchResponse, MessageWithResources +from src.app.services.tutor.utils import extract_doc_info settings = get_settings() @@ -39,6 +40,8 @@ async def tutor_manager(content: TutorSearchResponse) -> Message: queue = asyncio.Queue[TaskResponse]() + formatted_content = MessageWithResources(content=content.extracts, resources=extract_doc_info(content.documents)) + async def collect_result( _agent: ClosureContext, message: TaskResponse, ctx: MessageContext ) -> None: @@ -102,7 +105,7 @@ async def collect_result( ) await runtime.send_message( - content, + formatted_content, recipient=AgentId(university_teacher_topic_type, "default"), ) diff --git a/src/app/services/tutor/utils.py b/src/app/services/tutor/utils.py index aa21f0f..fc31ae4 100644 --- a/src/app/services/tutor/utils.py +++ b/src/app/services/tutor/utils.py @@ -1,3 +1,6 @@ +from src.app.models.documents import Document + + def build_system_message( role: str, backstory: str, @@ -13,3 +16,21 @@ def build_system_message( if expected_output: message += f"\nThis is the expected criteria for your final answer: {expected_output}\nYou MUST return the actual complete content as the final answer, not a summary." return message + + +def extract_doc_info(documents: list[Document]) -> list[dict]: + """ + Extracts the document information from a list of documents. + Args: + documents (list[Document]): List of Document objects. + Returns: + list[dict]: List of dictionaries containing document information. + """ + return [ + { + "title": doc.payload.document_title, + "url": doc.payload.document_url, + "content": doc.payload.slice_content, + } + for doc in documents + ]