Back to the LMS journey

DecidedStop 6 of 15

Moving AI checks to Python while Laravel keeps learner access

AI Core is a separate Python service for the LMS. It ranks the passages it is given and checks each claim in an answer. Laravel still decides which material a learner can use and what reply they get.

The question

The main LMS application is built in Laravel. AI Core is a separate Python service beside it, built with FastAPI, a Python tool for web services. It LMS · LMS AI Core · The AI servicePassage rankingPuts the passages Laravel sends in order, best match first. It looks at matching phrases and keywords. It also looks at each passage’s title and source.See it in the LMS build found for a question. It also LMS · LMS AI Core · The AI serviceClaim checkingSplits an answer into claims, which are single statements, and checks that the lesson supports each one. It also spots clashes in numbers, dates and names. And it spots clashes in quotes, in the order of things, and where one side says “not”.See it in the LMS build, or single statement, in an answer the AI writes. The question was how much of the rest of the LMS it should take over.

What I chose

None of it. Each request brings everything AI Core needs for that one job. A ranking request carries the question and the passages to rank. It also carries their search scores and how many results to send back. A checking request carries an answer or a LMS · LMS AI Core · The Laravel sideStudy guidesA saved guide is shown only while it still matches the lesson as it is now. It must also match the current AI provider, model and settings.See it in the LMS build. It also carries the lesson material behind it and the pass marks for the check.

Laravel keeps the rest. It stores the LMS · LMS AI Core · The Laravel sideLesson sourcesEach lesson is saved as a source with a version number, split into small chunks of text. Each chunk gets a fingerprint, a short code that changes when its content changes. Searches look only inside the learner’s own courses.See it in the LMS build and searches only what the learner may open. It also calls the AI providers and picks saved study guides. AI Core does not read LMS · The platformEnrolment and accessEvery request is checked against the learner’s enrolment, or the course the instructor is assigned to.See it in the LMS build.

How the service protects itself

Requests to AI Core’s main web addresses, the ones with a version number, need a shared LMS · LMS AI Core · The AI serviceKey-only accessEvery request to the service’s main web addresses, the ones with a version number, must carry an access key. If no key has been set up, the service refuses the request. Its public documentation pages are switched off.See it in the LMS build. This is a secret the caller sends with each request. If no key is set up, the service refuses the request with error 503. A missing or wrong key is refused too, with error 401. Its built-in documentation pages are off.

AI Core also uses Pydantic, a Python tool that checks each request. It refuses extra fields it does not expect at the top level of a request. It also limits the main inputs. A ranking request may have a question of up to 1,200 characters, up to 300 passages, and up to 50 results back. Some fields on each passage stay open, so this is not a full limit on request size.

What it costs

The key only goes so far. It shows that an allowed service is calling, not an allowed learner. So Laravel has to check that the learner may see the lesson material before it sends it to AI Core. Laravel also has to make sense of the result when it comes back.