Repository navigation
Add authenticated endpoint and inference client for AI-powered Friendly Error Messages - #1083
Merged
Merged
Conversation
Test coverage94.18% line coverage reported by SimpleCov. |
Uses the OpenAI client SDK to call a real inference service. The values in .env.example work for a local Ollama instance.
mwtrew
force-pushed
the
add-fem-api-endpoint
branch
from
November 2, 2026 10:25
645140a to
fbf4e38
Compare
This is is an abridged version of https://github.com/RaspberryPiFoundation/slm-evaluation/blob/main/corpus/prompt.yml. It is not complete or final, but it suggests how to send different system prompts.
The default timeout is 600 seconds, which will hold up Puma threads for too long.
mwtrew
marked this pull request as ready for review
November 2, 2026 13:16
ApprovabilityVerdict: Needs Human Approval Macroscope's review found this PR requires human approval — The new endpoint sends learner code and error traces to a configured inference service, with authentication, feature gating and bounded requests. Confirm production remains disabled until the service destination and learner-data handling are acceptable; deployment settings are not established by the example configuration. Needs human approval because:
You can add or adjust custom eligibility rules. Learn more. |
zetter-rpf
reviewed
Nov 2, 2026
zetter-rpf
reviewed
Nov 2, 2026
zetter-rpf
reviewed
Nov 2, 2026
zetter-rpf
approved these changes
Nov 2, 2026
zetter-rpf
left a comment
Contributor
There was a problem hiding this comment.
This is great, I've added a couple of small suggestions
This gives us a more prescriptive API for checking if a flag is enabled given the user - the bare `Flipper.enabled?` can accept any actors as params, so it can be easy to use it inconsistently by mistake. `enabled_for_user?` returns true if the flag is enabled for the user, their school, or everyone.
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Status
Points for consideration:
ai_friendly_errorsfeature flag, and requires the user to be logged-inreasoning: { effort: :none }on the OpenAI client, which makes the response a lot faster but potentially less accurate. This was useful for local testing, but may be less important with a different inference API.What's changed?
POSTendpoint/friendly_error_messagesthat requiresmessage,trace,runtimeandcodekeys in the request body, and returns an AI-generated friendly error message, or a hardcoded sample message ifBYPASS_FEM_INFERENCE=true.What's not changed?
Steps to perform after deploying to production
Eventually we will want to configure
FEM_INFERENCE_API_URLandFEM_INFERENCE_API_KEYin other environments, but that is blocked on https://github.com/RaspberryPiFoundation/digital-editor-issues/issues/1920.Guide to testing inference locally with Ollama
Get Ollama running locally: https://formulae.brew.sh/formula/ollama
Set the following in .env:
ai_friendly_errorsfeature flag$ rails c app(dev):001> Flipper.enable(:ai_friendly_errors)You should get something like:
{"fem":"It looks like Python doesn't recognize the word `prnt` because it isn't a standard command or function known by that name. It might be worth checking if you accidentally typed \"print\" wrong, since the correct built-in function to display text is spelled with an \"n\" in that spot. Looking at line 1 of your code would likely reveal this small spelling detail."}