Files
ZNJJ-api-server/src/core/config.py
T
Eric Wang a5407e03b2 feat(agent): align prompts and runtime with workflow@20261020
- archive workflow/20261020 export (diff vs 20261016: collection prompt
  only - state-decides-body rule, route when info complete)
- prompts: collection.md updated; 6 photo/confirm prompts archived with
  source nodeIds; render_prompt replaces {{$vars}} (Asia/Shanghai clock,
  person fields, explicit 'not provided' for missing prefills)
- llm: message history passed as user/assistant roles (chatNode history=50);
  optional LLM_TEMPERATURE; FakeLLMService supports history-aware responders
- collect: context via system supplement, raw user input as user message
  (Text Editor#2 parity), shared validated_reply (one call, one repair)
- welcome: Assigned Reply#3 original text, stored in dialogue history
- transitions: 2004 plate-confirm entries (2003->2004/2005, 2004->2005)
- verified: prompt files byte-identical to workflow JSON (parametrized test)
2026-10-21 15:10:51 +08:00

65 lines
2.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
from dotenv import load_dotenv
load_dotenv()
class Config:
PROJECT_NAME = "Flexible Employment Analysis API"
API_V1_STR = "/api/v1"
SECRET_KEY = os.getenv("SECRET_KEY", "your-secret-key")
DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///./test.db")
DEBUG = os.getenv("DEBUG", "false").lower() in ("true", "1", "t")
# FastGPT Configuration
FASTGPT_API_KEY = os.getenv("ANALYSIS_AUTH_TOKEN")
FASTGPT_BASE_URL = os.getenv("ANALYSIS_SERVICE_URL")
FASTGPT_APP_ID = os.getenv("APP_ID")
# Chat backend switch(作业 2)
# "fastgpt" 保持现有行为;"langgraph" 使用内存图 fake 回复。
AGENT_BACKEND = os.getenv("AGENT_BACKEND", "fastgpt")
# LLM provider(作业 4):fake 为脚本化假模型,离线可运行;
# openai 为真实 provider(OpenAI 兼容接口)。
AGENT_LLM_PROVIDER = os.getenv("AGENT_LLM_PROVIDER", "fake")
LLM_MODEL = os.getenv("LLM_MODEL", "fake-reply-model")
LLM_BASE_URL = os.getenv("LLM_BASE_URL", "")
LLM_API_KEY = os.getenv("LLM_API_KEY", "")
LLM_TIMEOUT_SECONDS = float(os.getenv("LLM_TIMEOUT_SECONDS", "30"))
LLM_MAX_RETRIES = int(os.getenv("LLM_MAX_RETRIES", "2"))
# 采样温度;None 表示使用 provider 缺省。对照 FastGPT 应用配置调整。
LLM_TEMPERATURE = (
float(os.getenv("LLM_TEMPERATURE")) if os.getenv("LLM_TEMPERATURE") else None
)
@classmethod
def validate(cls):
"""Validate required configuration."""
# TODO(作业 2): 语音管线仍依赖 FastGPT。当前仅按文本后端开关校验;
# 接入语音开关后,需要单独校验语音路径所需配置。
if cls.AGENT_BACKEND not in ("fastgpt", "langgraph"):
raise ValueError(
f"AGENT_BACKEND must be 'fastgpt' or 'langgraph', got {cls.AGENT_BACKEND!r}"
)
if cls.AGENT_LLM_PROVIDER not in ("fake", "openai"):
raise ValueError(
"AGENT_LLM_PROVIDER must be 'fake' or 'openai', "
f"got {cls.AGENT_LLM_PROVIDER!r}"
)
if cls.AGENT_LLM_PROVIDER == "openai" and (
not cls.LLM_API_KEY or not cls.LLM_BASE_URL
):
raise ValueError(
"AGENT_LLM_PROVIDER=openai requires LLM_API_KEY and LLM_BASE_URL"
)
if cls.AGENT_BACKEND != "fastgpt":
return
required = [
("FASTGPT_BASE_URL (ANALYSIS_SERVICE_URL)", cls.FASTGPT_BASE_URL),
("FASTGPT_API_KEY (ANALYSIS_AUTH_TOKEN)", cls.FASTGPT_API_KEY),
("FASTGPT_APP_ID (APP_ID)", cls.FASTGPT_APP_ID),
]
missing = [name for name, value in required if not value]
if missing:
raise ValueError(f"Missing required environment variables: {', '.join(missing)}")