Skip to content

Llm Implementation#49

Merged
ahmedalkawaz merged 2 commits into
mainfrom
llm-implementation
Mar 27, 2026
Merged

Llm Implementation#49
ahmedalkawaz merged 2 commits into
mainfrom
llm-implementation

Conversation

@ahmedalkawaz
Copy link
Copy Markdown

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

@ahmedalkawaz ahmedalkawaz merged commit 30a7734 into main Mar 27, 2026
2 checks passed
cnk2024 added a commit that referenced this pull request Apr 3, 2026
This reverts commit 30a7734, reversing
changes made to 20116d2.
cnk2024 added a commit that referenced this pull request Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants