NutsNews local-first AI fallback update
Section titled “NutsNews local-first AI fallback update”This update makes the Worker support a full local-first AI flow:
- Article review tries the home server first through
POST /review. - If local review fails, the Worker retries the home server once.
- If local review still fails and OpenAI fallback is enabled, the Worker falls back to OpenAI.
- Accepted article translations already use the same pattern through
POST /translate: local first, retry once, then OpenAI fallback.
Important deployment variables
Section titled “Important deployment variables”Use these when generating and deploying Workers:
export ENABLE_LOCAL_AI_SECRET_BINDING=trueexport AI_PROVIDER="local"export LOCAL_AI_URL="https://ai.nutsnews.com"export LOCAL_AI_MODEL="qwen2.5:3b"export AI_PROVIDER_FALLBACK_TO_OPENAI=trueexport AI_REVIEW_CONCURRENCY=1export ENABLED_SUMMARY_LANGUAGES="fr,ja,de-CH,de,el"export SUMMARY_TRANSLATION_LIMIT=12AI_PROVIDER="local" is the setting that moves article review to the home server first.
AI_PROVIDER_FALLBACK_TO_OPENAI=true keeps OpenAI as the safety net when the home server fails.
AI_REVIEW_CONCURRENCY=1 is recommended for a small home server so multiple shards do not overload Ollama.
Deploy Workers
Section titled “Deploy Workers”cd /Users/ramideltoro/WebstormProjects/nutsnews2/worker
export ENABLE_LOCAL_AI_SECRET_BINDING=trueexport AI_PROVIDER="local"export LOCAL_AI_URL="https://ai.nutsnews.com"export LOCAL_AI_MODEL="qwen2.5:3b"export AI_PROVIDER_FALLBACK_TO_OPENAI=trueexport AI_REVIEW_CONCURRENCY=1export ENABLED_SUMMARY_LANGUAGES="fr,ja,de-CH,de,el"export SUMMARY_TRANSLATION_LIMIT=12
npm cinpx tsc --noEmitnpm run generate:wranglernpm run deploy:allVerify generated config
Section titled “Verify generated config”grep -n \ -e '"AI_PROVIDER"' \ -e '"LOCAL_AI_URL"' \ -e '"LOCAL_AI_MODEL"' \ -e '"AI_PROVIDER_FALLBACK_TO_OPENAI"' \ -e '"AI_REVIEW_CONCURRENCY"' \ -e '"ENABLED_SUMMARY_LANGUAGES"' \ -e '"SUMMARY_TRANSLATION_LIMIT"' \ generated-wrangler/wrangler.shard1.jsoncYou should see:
"AI_PROVIDER": "local","LOCAL_AI_URL": "https://ai.nutsnews.com","LOCAL_AI_MODEL": "qwen2.5:3b","AI_PROVIDER_FALLBACK_TO_OPENAI": "true","AI_REVIEW_CONCURRENCY": "1","ENABLED_SUMMARY_LANGUAGES": "fr,ja,de-CH,de,el","SUMMARY_TRANSLATION_LIMIT": "12"Runtime logs to expect
Section titled “Runtime logs to expect”A fully local-first successful article should show:
worker.local_ai.article_reviewedworker.translation.local.article_summary_translatedworker.translation.local.article_summary_translatedIf local review fails, fallback should show:
worker.local_ai.fallback_to_openaiworker.openai.article_reviewedTest one shard
Section titled “Test one shard”curl "https://nutsnews-worker-1.nutsnews.workers.dev/?limit=1"Watch these response fields:
"aiProvider": "local","localAiCallCount": 1,"openAiCallCount": 0,"articleSummaryTranslationCount": 2openAiCallCount should stay at 0 when local review works. It may become 1 only if local review fails and fallback is used.
