ITADN

chore: add model-service and update .gitignore

#254Pull RequestMCVelasquez45 创建于 2025-08-27
M
MCVelasquez45commented
PR title feat(model-service): add OpenAI-compatible wrapper (+ pm2 + env example) and update ignores PR body ## Summary This PR adds a minimal **Node/Express model-service** that exposes: - `GET /health` → returns `{ ok, model, base }` - `POST /generate` → forwards `messages` to `${OPENAI_BASE_URL}/chat/completions` and returns `{ text }` The wrapper is **provider-agnostic** (OpenAI, Mistral API, OpenRouter, etc.) via `.env`. ### What changed - `model-service/server.js` – Express service with `/health` and `/generate`, reads `.env` via `dotenv` [oai_citation:0‡server.js](file-service://file-JURuk7mmAVcVM2WEGWCpAq) - `model-service/package.json` – scripts: `dev`, `start`, `pm2`; Node ≥ 18 engines [oai_citation:1‡package.json](file-service://file-Wtgi461xhjnUh6YWMGhSGr) - `model-service/.env.example` – starter env for provider URL/key/model/port - `model-service/ecosystem.config.js` – pm2 process file (`npm run pm2`) [oai_citation:2‡ecosystem.config.js](file-service://file-MUyPrTm6wz1YxU9V2q7Lok) - `model-service/Procfile` – proc entry for platforms that use Procfile - Root `.gitignore` – ignore `model-service/.env` (secrets not committed) ### Why - Gives contributors and students a **local OpenAI-compatible endpoint** without changing app code when switching providers. - Keeps the interface stable while we iterate on infra (hosted or self-hosted later). ### How to run (reviewer quick start) ```bash cd model-service cp .env.example .env # paste your provider key npm install npm run dev curl http://localhost:7071/health curl -s -X POST http://localhost:7071/generate \ -H "Content-Type: application/json" \ -d '{"messages":[{"role":"user","content":"Say hello from Second Story!"}]}' Env configuration OPENAI_BASE_URL=https://api.openai.com/v1 # or https://api.mistral.ai/v1, https://openrouter.ai/api/v1 OPENAI_API_KEY=sk-REPLACE_ME MODEL_NAME=gpt-4o-mini # or mistral-small, openai/gpt-4o-mini, etc. PORT=7071 Notes • Node ≥ 18 required (declared in package.json engines).  • pm2 run supported: npm run pm2 pm2 logs reentry-model-service (Process config in ecosystem.config.js.)  Testing done • GET /health returns {"ok":true,"model":"...", "base":"..."} • POST /generate returns { "text": "..." } round-tripped from provider. • Verified .env is ignored and not committed. Follow-ups (separate PRs) • Add scripts/test-model.sh convenience script and student_setup.md • Add CI job to npm i && node -v && curl /health • Optional: add /api RAG layer with citations --- ### Labels to apply - `type: feat` - `area: inference` (or `area: model-service`) - `ready for review` ### Reviewers to request - Anyone responsible for infra/dev-tools in your org.
合并状态:未合并 0 条评论