NutsNews home-server translation fallback update
Section titled “NutsNews home-server translation fallback update”This update changes new Worker-generated article translations so the home server is tried before OpenAI.
What changed
Section titled “What changed”- Added
POST /translatetolocal-ai-service/server.mjs. - Updated
worker/src/index.tsso summary translations use this order:- Home-server local AI translation.
- One retry if the local translation fails.
- OpenAI fallback.
- One retry if OpenAI translation fails.
- Added stronger validation so translation responses must include both
titleandsummarybefore being saved. - Updated Better Stack delivery events for translation failures and OpenAI fallback logs.
- Updated docs for multi-language summaries and the home-server local AI service.
Required Worker config
Section titled “Required Worker config”For Workers to use the home server for translations, deployed shard configs need these values available:
LOCAL_AI_URL=https://ai.nutsnews.comLOCAL_AI_MODEL=qwen2.5:3bLOCAL_AI_API_KEY=<Cloudflare Secrets Store binding>AI_PROVIDER does not have to be local for translation fallback to work. Article review can still use OpenAI while translations use the home server first, as long as LOCAL_AI_URL and LOCAL_AI_API_KEY are configured.
Home-server deploy files
Section titled “Home-server deploy files”Copy these files to /opt/nutsnews/local-ai-service on the home server:
local-ai-service/server.mjslocal-ai-service/package.jsonlocal-ai-service/.env.exampleKeep the real .env on the server. Do not overwrite it unless you intentionally want to change secrets.
Optional .env value for translation length:
TRANSLATION_SUMMARY_MAX_CHARS=250Test commands
Section titled “Test commands”From the project root:
cd workernpm cinpx tsc --noEmitOn the home server after copying local-ai-service/server.mjs:
sudo systemctl restart nutsnews-local-aisudo systemctl status nutsnews-local-ai --no-pager --lines=12
AI_KEY="$(sudo grep '^LOCAL_AI_API_KEY=' /opt/nutsnews/local-ai-service/.env | cut -d= -f2-)"
curl -s -X POST http://127.0.0.1:8788/translate \ -H "content-type: application/json" \ -H "x-nutsnews-ai-key: ${AI_KEY}" \ -d '{ "model":"qwen2.5:3b", "language_code":"fr", "source":"NutsNews Test", "title":"Community garden brings neighbors together", "summary":"A neighborhood garden is helping families spend time outside, learn about plants, and share peaceful moments together.", "category":"Community" }' | python3 -m json.tool