Healthy Diet AI 代理是一个基于 Bun + TypeScript 的后端,用于营养聊天、食物图像分析、RAG 文档采集以及基于知识的饮食指导。
Healthy Diet AI 代理是一个基于 Bun + TypeScript 的后端,用于营养聊天、食物图像分析、RAG 文档采集以及基于知识的饮食指导。
Healthy Diet AI Agent is a Bun + TypeScript backend for nutrition and healthy diet support. It features chat, food image analysis, RAG document knowledge retrieval, knowledge graph, and MOHW (Ministry of Health and Welfare) data synchronization.
This repository now supports two deployment modes:
health-diet-api ecosystemBunTypeScriptExpressLangChain, LangGraph, DeepAgentsSQLite or SupabaseDocker Composesrc/rag_clean/pdf_to_clean_markdown.py) for converting official guideline PDFs into structured Markdown with prose tablesThis project was originally built to complement the following two projects:
PU-Hub/healthy-diet as the API-side projectarchie0732/healthy-diet-web as the frontend Web projectAs this repository started receiving more attention and views, the project's direction was adjusted. While keeping the ability to integrate with the original stack, we are gradually refactoring this repository into a standalone, independently deployable AI agent service.
sqlite or supabasehealth-diet-api…
Suitable for:
Characteristics:
SUPABASE_URL and SUPABASE_SERVICE_KEY are not requiredSQLITE_DB_PATHSuitable for:
Characteristics:
bun install
cp .env.example .env
Core runtime variables:
PORTAI_API_URLSTORAGE_BACKEND=sqlite|supabaseSQLITE_DB_PATHCLI_USER_IDCLI_THREAD_IDSupabase variables for integration mode:
SUPABASE_URLSUPABASE_SERVICE_KEYGoogle routing variables:
GEMINI_AI_APIGEMINI_API_KEYGOOGLE_CHAT_MODELGOOGLE_BASE_URLProject-level agent behavior now lives in:
agent_config.jsonBackground sync variables:
MOHW_NEWS_SYNC_ENABLEDMOHW_NEWS_SYNC_INTERVAL_MINUTESMOHW_NEWS_SYNC_RUN_ON_STARTConfig precedence:
agent_config.json provides the repository default behaviorMOHW_NEWS_SYNC_ENABLED overrides agent_config.json features.mohw_enabled when explicitly setRecommended .env configuration:
PORT=8001
AI_API_URL=http://127.0.0.1:8080/v1/
STORAGE_BACKEND=sqlite
SQLITE_DB_PATH=./data/healthy-diet-agent.db
CLI_USER_ID=local-user
CLI_THREAD_ID=local-thread
Start the HTTP server:
bun run start
Default URLs:
http://localhost:8001POST /api/chatGET /pingSend a prompt directly in the terminal:
bun run cli -- --message "Analyze my lunch"
You can also specify user, thread, and model source:
bun run cli -- --message "Give me a low sugar dinner idea" --user-id demo-user --thread-id demo-thread --model-source auto
In general, manual schema setup is not required because the app automatically bootstraps the SQLite schema upon startup.
If you want to manually create the database or pre-seed local testing data, you can use:
docs/sqlite/schema.sqldocs/sqlite/seed.sample.sqlIf you have sqlite3 installed in your environment:
sqlite3 ./data/healthy-diet-agent.db < docs/sqlite/schema.sql
sqlite3 ./data/healthy-diet-agent.db < docs/sqlite/seed.sample.sql
seed.sample.sql is only a local development example. You can modify the user, chatroom, and dialogue data inside it before importing.
The default Docker setup runs in standalone SQLite mode.
docker compose up --build
Default behavior:
STORAGE_BACKEND=sqliteSQLITE_DB_PATH=/app/data/healthy-diet-agent.db./data:/app/dataCommon mounts:
./data./knowledge_base./users_imagesFor automated production deployment using GitHub Actions, GHCR, and a self-hosted runner, see:
To connect to an existing system, set:
STORAGE_BACKEND=supabase
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SERVICE_KEY=your-service-role-key
Notes:
health-diet-api or other Supabase-based architecturesFor common customization of agent roles and retrieval behaviors, you can do so without modifying the core runtime code.
Recommended customization steps:
agent_config.jsonknowledge_base/AGENT.mdknowledge_base/NUTRITION_RULES.mdmohw_news in agent_config.jsonagent_config.json currently controls:
Config precedence:
agent_config.json provides the repository default behaviorMOHW_NEWS_SYNC_ENABLED overrides agent_config.json features.mohw_enabled when explicitly setPOST /api/chatPOST /api/approvePOST /api/generate_titleGET /pingGET /api/rag/searchPOST /api/rag/searchGET /api/rag/documentsPOST /api/rag/documentsGET /api/rag/documents/:document_idDELETE /api/rag/documents/:document_idPOST /api/rag/documents/:document_id/reindexGET /api/rag/documents/:document_id/fileGET /api/rag/documents/:document_id/previewGET /api/rag/sources/:document_id/fileGET /api/rag/sources/:document_id/previewPOST /api/admin/knowledge/uploadPOST /api/admin/knowledge/ingest/:idGET /api/admin/knowledge/jobs/:jobIdPOST /api/graph/extract-allGET /api/graph/statusPOST /api/graph/documents/:document_id/extractGET /api/graph/documents/:document_idPOST /api/graph/searchGET /api/graph/nodesGET /api/graph/nodes/:node_idGET /api/graph/relations/:relation_id/evidencePOST /api/news/syncGET /api/newsGET /api/news/:idGET /api/news-filesdata/healthy-diet-agent.db or SQLITE_DB_PATHusers_images/knowledge_base/uploads/knowledge_base/ingested_markdown/knowledge_base/NUTRITION_RULES.mdknowledge_base/mohw_clarifications/Run focused tests:
bun test src/server/httpRuntime.test.ts src/storage/runtime.test.ts src/server/serverHandlers.test.ts src/server/dbTools.test.ts src/server/ragDocuments.test.ts src/cli.test.ts
Run all tests:
bun test
health-diet-api.AI_API_URL or the configured Google route.X-Admin-User-Id and X-Admin-Role (admin or nutritionist) headers.Authorization header is no longer considered sufficient for administrator privileges./api/chat fails after creating the initial chat history row, the placeholder reply will be updated from __PENDING__ to a [FAILED] ... marker.The Development-only R2.19 experiment adds four checksum-verified WHO source
documents and an offline MiniLM q8 candidate retriever. On outcome-exposed
R2.16 data, the frozen BM25-MiniLM reciprocal-rank fusion reached required
Recall@20 of 0.9615. This is diagnostic model selection only; a new
lineage-disjoint, owner-approved confirmation is still required. See
experiments/version_aware_rag/V5_R2_19_NEURAL_HYBRID_DIAGNOSTIC_RESULT.md.
R2.20 executed one new 32-record, lineage-disjoint Development confirmation for
the R2.19-selected BM25-MiniLM RRF candidate generator and the R2.16
Top-6-anchored pair reranker. Candidate Recall@20 reached 0.9808, and all
three strict improvements passed, but current-only Recall@3 decreased from
1.0000 to 0.8333. The gate therefore failed and is locked at o
暂无开放 Issues,或尚未同步最近议题。