Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions backend/app/api/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,19 @@ def generate_ontology():

# 生成本体
logger.info("调用 LLM 生成本体定义...")
# till this point
generator = OntologyGenerator()
ontology = generator.generate(
document_texts=document_texts,
simulation_requirement=simulation_requirement,
additional_context=additional_context if additional_context else None
)
logger.info("OntologyGenerator....................")
try:
ontology = generator.generate(
document_texts=document_texts,
simulation_requirement=simulation_requirement,
additional_context=additional_context if additional_context else None
)
logger.info("OntologyGenerator try....................")
except Exception as e:
logger.error(f"本体生成失败: {traceback.format_exc()}") # ADD
raise

# 保存本体到项目
entity_count = len(ontology.get("entity_types", []))
Expand Down
69 changes: 51 additions & 18 deletions backend/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
if os.path.exists(project_root_env):
load_dotenv(project_root_env, override=True)
else:
# 如果根目录没有 .env,尝试加载环境变量(用于生产环境)
load_dotenv(override=True)


Expand All @@ -24,14 +23,27 @@ class Config:
SECRET_KEY = os.environ.get('SECRET_KEY', 'mirofish-secret-key')
DEBUG = os.environ.get('FLASK_DEBUG', 'True').lower() == 'true'

# JSON配置 - 禁用ASCII转义,让中文直接显示(而不是 \uXXXX 格式)
# JSON配置
JSON_AS_ASCII = False

# LLM配置(统一使用OpenAI格式)
LLM_API_KEY = os.environ.get('LLM_API_KEY')
LLM_BASE_URL = os.environ.get('LLM_BASE_URL', 'https://api.openai.com/v1')
LLM_MODEL_NAME = os.environ.get('LLM_MODEL_NAME', 'gpt-4o-mini')

# ===== Primary LLM (Groq) - 3 keys, auto-rotates on rate limit =====
LLM_API_KEY_1 = os.environ.get('LLM_API_KEY_1')
LLM_API_KEY_2 = os.environ.get('LLM_API_KEY_2')
LLM_API_KEY_3 = os.environ.get('LLM_API_KEY_3')
LLM_API_KEY_4 = os.environ.get('LLM_API_KEY_4')
LLM_BASE_URL = os.environ.get('LLM_BASE_URL', 'https://api.groq.com/openai/v1')
LLM_MODEL_NAME = os.environ.get('LLM_MODEL_NAME', 'meta-llama/llama-4-scout-17b-16e-instruct')

# Backward compatibility alias
LLM_API_KEY = os.environ.get('LLM_API_KEY_1') or os.environ.get('LLM_API_KEY')

# ===== Boost LLM (Gemini) - 3 keys, auto-rotates on rate limit =====
LLM_BOOST_API_KEY_1 = os.environ.get('LLM_BOOST_API_KEY_1')
LLM_BOOST_API_KEY_2 = os.environ.get('LLM_BOOST_API_KEY_2')
LLM_BOOST_API_KEY_3 = os.environ.get('LLM_BOOST_API_KEY_3')
LLM_BOOST_BASE_URL = os.environ.get('LLM_BOOST_BASE_URL')
LLM_BOOST_MODEL_NAME = os.environ.get('LLM_BOOST_MODEL_NAME')

# Zep配置
ZEP_API_KEY = os.environ.get('ZEP_API_KEY')

Expand All @@ -41,11 +53,11 @@ class Config:
ALLOWED_EXTENSIONS = {'pdf', 'md', 'txt', 'markdown'}

# 文本处理配置
DEFAULT_CHUNK_SIZE = 500 # 默认切块大小
DEFAULT_CHUNK_OVERLAP = 50 # 默认重叠大小
DEFAULT_CHUNK_SIZE = 500
DEFAULT_CHUNK_OVERLAP = 50

# OASIS模拟配置
OASIS_DEFAULT_MAX_ROUNDS = int(os.environ.get('OASIS_DEFAULT_MAX_ROUNDS', '10'))
OASIS_DEFAULT_MAX_ROUNDS = int(os.environ.get('OASIS_DEFAULT_MAX_ROUNDS', '3'))
OASIS_SIMULATION_DATA_DIR = os.path.join(os.path.dirname(__file__), '../uploads/simulations')

# OASIS平台可用动作配置
Expand All @@ -59,17 +71,38 @@ class Config:
]

# Report Agent配置
REPORT_AGENT_MAX_TOOL_CALLS = int(os.environ.get('REPORT_AGENT_MAX_TOOL_CALLS', '5'))
REPORT_AGENT_MAX_REFLECTION_ROUNDS = int(os.environ.get('REPORT_AGENT_MAX_REFLECTION_ROUNDS', '2'))
REPORT_AGENT_TEMPERATURE = float(os.environ.get('REPORT_AGENT_TEMPERATURE', '0.5'))

REPORT_AGENT_MAX_TOOL_CALLS = int(os.environ.get('REPORT_AGENT_MAX_TOOL_CALLS', '1'))
REPORT_AGENT_MAX_REFLECTION_ROUNDS = int(os.environ.get('REPORT_AGENT_MAX_REFLECTION_ROUNDS', '1'))
REPORT_AGENT_TEMPERATURE = float(os.environ.get('REPORT_AGENT_TEMPERATURE', '0.3'))

@classmethod
def get_primary_keys(cls) -> list:
"""Return all configured primary (Groq) API keys"""
return [k for k in [cls.LLM_API_KEY_1, cls.LLM_API_KEY_2, cls.LLM_API_KEY_3, cls.LLM_API_KEY_4] if k]

@classmethod
def get_boost_keys(cls) -> list:
"""Return all configured boost (Gemini) API keys"""
return [k for k in [cls.LLM_BOOST_API_KEY_1, cls.LLM_BOOST_API_KEY_2, cls.LLM_BOOST_API_KEY_3] if k]

@classmethod
def has_boost(cls) -> bool:
"""Check if boost LLM is configured"""
return bool(cls.LLM_BOOST_API_KEY_1 and cls.LLM_BOOST_BASE_URL and cls.LLM_BOOST_MODEL_NAME)

@classmethod
def validate(cls):
"""验证必要配置"""
errors = []
if not cls.LLM_API_KEY:
errors.append("LLM_API_KEY 未配置")
primary_keys = cls.get_primary_keys()
if not primary_keys:
errors.append("LLM_API_KEY_1 未配置")
else:
print(f"✅ Primary LLM: {len(primary_keys)} key(s) configured")
if not cls.ZEP_API_KEY:
errors.append("ZEP_API_KEY 未配置")
return errors

if cls.has_boost():
print(f"✅ Boost LLM: {len(cls.get_boost_keys())} key(s) configured")
else:
print("⚠️ LLM_BOOST not configured - all tasks will use primary LLM")
return errors
Loading