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
2 changes: 1 addition & 1 deletion k8s/welearn-api/values.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
2 changes: 1 addition & 1 deletion k8s/welearn-api/values.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
2 changes: 1 addition & 1 deletion k8s/welearn-api/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 15 additions & 10 deletions src/app/services/tutor/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']}",
)
Expand All @@ -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(
Expand All @@ -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),
)
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand Down
4 changes: 2 additions & 2 deletions src/app/services/tutor/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
7 changes: 5 additions & 2 deletions src/app/services/tutor/tutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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:
Expand Down Expand Up @@ -102,7 +105,7 @@ async def collect_result(
)

await runtime.send_message(
content,
formatted_content,
recipient=AgentId(university_teacher_topic_type, "default"),
)

Expand Down
21 changes: 21 additions & 0 deletions src/app/services/tutor/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from src.app.models.documents import Document


def build_system_message(
role: str,
backstory: str,
Expand All @@ -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
]