Skip to main content

24/7 faculty twin app built on SAGE and vllm-hust

Project description

sage-faculty-twin

面向单个教师的数字分身应用(FastAPI + SAGE + NeuroMem + OpenAI-compatible LLM)。

最重要的结论

  • 推荐后端链路:vllm-hust + vllm-ascend-hust(Ascend)。
  • 本仓库已提供一键启动脚本:tools/run_full_stack_with_vllm_hust.sh
  • 应用默认监听:127.0.0.1:55601

前置条件(最小)

  • Linux
  • Python 3.11(使用现有非 venv 环境)
  • 同级目录存在:../SAGE../neuromem../sageVDB
  • 本机可访问 vllm-hust OpenAI 端点(默认 127.0.0.1:18000

一键启动(推荐)

cd /home/shuhao/sage-faculty-twin
tools/run_full_stack_with_vllm_hust.sh

该脚本会做三件事:

  1. 检查 http://127.0.0.1:18000/v1/models 是否可用(不可用时尝试启动 vllm-hust serve)。
  2. 自动写入 .env 的关键 LLM 配置(base URL、model、stream)。
  3. 启动 my-twin(tools/run_app_server.sh)。

启动后验证

curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:55601/
curl -s http://127.0.0.1:55601/healthz
curl -s -N http://127.0.0.1:55601/chat \
  -H 'Content-Type: application/json' \
  -d '{"student_name":"测试同学","question":"请用一句话介绍你自己"}'

关键配置(.env)

最关键只有这 4 个:

  • DIGITAL_TWIN_LLM_BASE_URL(例如 http://127.0.0.1:18000/v1
  • DIGITAL_TWIN_API_KEY(本地直连可用 EMPTY;如果启用 systemd OpenAI 代理,请换成真实密钥)
  • DIGITAL_TWIN_MODEL_NAME(例如 meta-llama/Llama-3.1-8B-Instruct
  • DIGITAL_TWIN_STREAM_CHAT_ANSWER=true

联网检索(可选)建议再配 2 个:

  • TAVILY_TOKEN(或 DIGITAL_TWIN_TAVILY_TOKEN
  • DIGITAL_TWIN_WEB_SEARCH_ENABLED=true

OpenAI 代理(可选)

如果你想让 vllm-hust 通过 systemd 代理对外提供带鉴权的 OpenAI-compatible API,可以启用 sage-faculty-twin-vllm-openai-proxy.service

默认的 ./manage.sh install --start./manage.sh restart 只管理公共 app/site/tunnel 栈,不会自动启用这个代理。需要代理时显式使用:

./manage.sh install --with-vllm-proxy --start
./manage.sh restart --with-vllm-proxy

代理默认监听 127.0.0.1:18001,上游转发到 127.0.0.1:18000/v1。启用后,把 .env 里的 DIGITAL_TWIN_API_KEY 改成真实密钥,并将 DIGITAL_TWIN_LLM_BASE_URL 指向 http://127.0.0.1:18001/v1

如果 127.0.0.1:18001 已经被独立的 vllm-hust serve 进程直接占用,就不要启用这个代理;否则它会因为端口冲突而反复重启。

验证方式:

curl -H 'Authorization: Bearer <your-key>' http://127.0.0.1:18001/v1/models
curl -X POST http://127.0.0.1:18001/v1/chat/completions \
  -H 'Authorization: Bearer <your-key>' \
  -H 'Content-Type: application/json' \
  -d '{"model":"Qwen3-32B","messages":[{"role":"user","content":"hi"}],"max_tokens":5}'

常用覆盖参数(给一键脚本)

VLLM_PORT=18000 \
VLLM_MODEL=/data/shared-models/Qwen2.5-7B-Instruct \
VLLM_SERVED_MODEL_NAME=meta-llama/Llama-3.1-8B-Instruct \
VLLM_LOG_PATH=$HOME/logs/vllm-hust-twin.log \
tools/run_full_stack_with_vllm_hust.sh

最小排障

  • No module named sage_faculty_twin:确认通过脚本启动,避免外部 PYTHONPATH 覆盖。
  • /chat 422:请求体必须至少包含 student_namequestion
  • 页面无流式输出:确认 .envDIGITAL_TWIN_STREAM_CHAT_ANSWER=true,并确认上游 LLM 支持 chunked streaming。

目录入口

  • API:src/sage_faculty_twin/api.py
  • 编排:src/sage_faculty_twin/service.py
  • 启动脚本:tools/run_app_server.sh
  • 全栈一键脚本:tools/run_full_stack_with_vllm_hust.sh

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sage_faculty_twin-3.0.0.tar.gz (405.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sage_faculty_twin-3.0.0-py3-none-any.whl (286.3 kB view details)

Uploaded Python 3

File details

Details for the file sage_faculty_twin-3.0.0.tar.gz.

File metadata

  • Download URL: sage_faculty_twin-3.0.0.tar.gz
  • Upload date:
  • Size: 405.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for sage_faculty_twin-3.0.0.tar.gz
Algorithm Hash digest
SHA256 127d4cde638a5ca8a0c6926c30bd968cd09d8c99658352f4c8d6e608f389bdfd
MD5 a240cc3961cf612264e5e126e6cb66e7
BLAKE2b-256 750b10157065dcf8e2afff9385855da7f7a2021f6d0952f27a38f247506b1761

See more details on using hashes here.

File details

Details for the file sage_faculty_twin-3.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sage_faculty_twin-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 846e80677b33cf8a90bd4081412fa8cf24ad3e1b181fafcedb82b60bba7c31ef
MD5 f5e1eebfbc6d0ff4c9afffa0d9a16bd2
BLAKE2b-256 693df4c9a6c789777948bc2338a1aee5a99b1497e0818e944596107208995711

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page