From 94377a238536928bc9f65544197ad08434d25a1a Mon Sep 17 00:00:00 2001 From: neagualexa Date: Thu, 30 Jul 2026 15:04:04 +0100 Subject: [PATCH 1/3] update muEd chat functions usage --- docs/advanced/chat_functions/local.md | 14 +- docs/advanced/chat_functions/quickstart.md | 284 +++++++++++---------- docs/advanced/index.md | 2 +- docs/index.md | 2 +- 4 files changed, 163 insertions(+), 139 deletions(-) diff --git a/docs/advanced/chat_functions/local.md b/docs/advanced/chat_functions/local.md index 1fbca3b74..3f5e8c754 100644 --- a/docs/advanced/chat_functions/local.md +++ b/docs/advanced/chat_functions/local.md @@ -1,5 +1,7 @@ # Running and Testing Chat function Locally +All request payloads below follow the [μEd](https://mued.org/) `ChatRequest` schema, which is the specification chat functions on Lambda Feedback follow. Only `messages` is required; `conversationId`, `user`, `context` and `configuration` are optional. + ## Run Unit Tests You can run the unit tests using `pytest`: @@ -44,12 +46,12 @@ docker run -e OPENAI_API_KEY={your key} -e OPENAI_MODEL={your LLM chosen model n docker run --env-file .env -it --name my-lambda-container -p 8080:8080 llm_chat ``` -This will start the evaluation function and expose it on port `8080` and it will be open to be curl: +This will start the chat function and expose it on port `8080` and it will be open to be curl: ```bash curl --location 'http://localhost:8080/2015-03-31/functions/function/invocations' \ --header 'Content-Type: application/json' \ ---data '{"body":"{\"conversationId\": \"12345Test\", \"messages\": [{\"role\": \"USER\", \"content\": \"hi\"}], \"user\": {\"type\": \"LEARNER\"}}"}' +--data '{"body":"{\"messages\": [{\"role\": \"USER\", \"content\": \"hi\"}]}"}' ``` ### Call Docker Container @@ -70,13 +72,15 @@ POST URL: http://localhost:8080/2015-03-31/functions/function/invocations ``` -Body (stringified within `body` for the API request): +Minimal body — only the required `messages` field: ```JSON -{"body":"{\"conversationId\": \"12345Test\", \"messages\": [{\"role\": \"USER\", \"content\": \"hi\"}], \"user\": {\"type\": \"LEARNER\"}}"} +{ + "messages": [{ "role": "USER", "content": "hi" }] +} ``` -Input Body with optional fields: +Full body as Lambda Feedback sends it, with all optional μEd fields populated: ```json { "conversationId": "", diff --git a/docs/advanced/chat_functions/quickstart.md b/docs/advanced/chat_functions/quickstart.md index fefe63040..eb1c45090 100644 --- a/docs/advanced/chat_functions/quickstart.md +++ b/docs/advanced/chat_functions/quickstart.md @@ -9,150 +9,170 @@ A chat function is a function which calls Large Language Models (LLMs) to respon Chat functions host a chatbot. Chatbots capture and automate the process of assisting students during their learning process when outside of classroom. +## The μEd specification + +Chat functions on Lambda Feedback consume the [μEd API](https://mued.org/) request schema. The `messages`, `user`, `context` and `configuration` fields of an incoming request follow the μEd `ChatRequest` format, and the chat function translates them into a tutoring prompt (in the boilerplate this is done by `src/agent/context.py`). + +Per the μEd `ChatRequest` schema, **only `messages` is required** — `conversationId`, `user`, `context` and `configuration` are all optional. Refer to [mued.org](https://mued.org/) for the authoritative field definitions. + ## Getting Setup for Development 1. Get the code on your local machine (Using github desktop or the `git` cli) - - For new functions: clone the template repo for [chat-function-boilerplate](https://github.com/lambda-feedback/chat-function-boilerplate). **Make sure the new repository is set to public (it needs access to organisation secrets)**. + - For new functions: use the template repo [chat-function-boilerplate](https://github.com/lambda-feedback/chat-function-boilerplate) via *Use this template > Create a new repository*, choosing the `Lambda Feedback` organisation as the owner. **Make sure the new repository is set to public (it needs access to organisation secrets and GitHub deployment protection rules)**. - For existing functions: please make your changes on a new separate branch -2. _If you are creating a new chatbot_, you can either edit the `src/agents/base_agent` or copy it and rename it based on the name of your chatbot. -3. You are now ready to start making changes and implementing features by editing each of the main function-logic files: +2. Add your LLM credentials to a `.env` file in the root of the repository. OpenAI, Google AI and Ollama are supported out of the box: - 1. **`src/agents/{base_agent}/{base}_agent.py`**: This file contains the main LLM pipeline using [LangGraph](https://langchain-ai.github.io/langgraph/) and [LangChain](https://python.langchain.com/docs/introduction/). - - - the chat function expects the following arguments when it being called: - - Body with necessary fields: - - ```JSON - { - "conversationId": "12345Test", - "messages": [{ "role": "USER", "content": "hi" }], - "user": { "type": "LEARNER" } - } - ``` - - Body with optional fields: - - ```JSON - { - "conversationId": "12345Test", - "messages": [ - { "role": "USER", "content": "" }, - { "role": "ASSISTANT", "content": "" }, - { "role": "USER", "content": "hi" } - ], - "user": { - "type": "LEARNER", - "preference": { "conversationalStyle": "" }, - "taskProgress": { - "timeSpentOnQuestion": "30 minutes", - "accessStatus": "a good amount of time spent on this question today.", - "markedDone": "This question is still being worked on.", - "currentPart": { - "position": 0, - "timeSpentOnPart": "10 minutes", - "markedDone": "This part is not marked done.", - "responseAreas": [ - { - "responseType": "EXPRESSION", - "totalSubmissions": 3, - "wrongSubmissions": 2, - "latestSubmission": { - "submission": "", - "feedback": "", - "answer": "" - } - } - ] - } - } - }, - "context": { - "summary": "", - "set": { "title": "Fundamentals", "number": 2, "description": "" }, - "question": { - "title": "Understanding Polymorphism", - "number": 3, - "guidance": "", - "content": "", - "estimatedTime": "15-25 minutes", - "parts": [ - { - "position": 0, - "content": "", - "answerContent": "", - "workedSolutionSections": [ - { "position": 0, "title": "Step 1", "content": "..." } - ], - "structuredTutorialSections": [ - { "position": 0, "title": "Hint", "content": "..." } - ], - "responseAreas": [ - { - "position": 0, - "responseType": "EXPRESSION", - "answer": "", - "preResponseText": "