Llm Implementation#49
Merged
Merged
Conversation
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.
Context
This PR integrates an LLM-based translation service into NodeBB, enabling automatic detection and translation of non-English posts at creation time.
Description
When a user creates a post, NodeBB calls a separate Python Flask translator service powered by Ollama. The service classifies the language of the post and translates it to English if needed. Non-English posts display a "Click here to view the translated message" button that reveals the translation inline.
Changes
Created translator/ directory containing a standalone Flask translation microservice (src/translator.py, app.py, requirements.txt)
LLM integration uses Ollama with llama3.1:8b model for language classification and translation via structured prompts
Robust error handling: validates LLM output against a known languages list, falls back to assuming English on gibberish responses, empty translations, or service errors
Updated src/translate/index.js to call the Flask service asynchronously with graceful fallback if the service is unreachable
Unit tests in translator/test/unit/test_translator.py covering normal responses, English detection, gibberish handling, timeouts, empty translations, and empty input
Testing
Unit tests: cd translator && uv run pytest (7 tests passing)
Integration: requires three processes running simultaneously:
ollama serve (LLM backend)
cd translator && uv run flask run (translator service on port 5000)
NodeBB (./nodebb build && ./nodebb start)
Create a non-English post (e.g. "Dies ist eine deutsche Nachricht.") and verify the translate button appears with the English translation