This commit is contained in:
Jason 2026-05-28 17:28:29 -04:00 committed by GitHub
commit f5fcff479d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 71 additions and 6 deletions

View File

@ -14,3 +14,6 @@ ZEP_API_KEY=your_zep_api_key_here
LLM_BOOST_API_KEY=your_api_key_here LLM_BOOST_API_KEY=your_api_key_here
LLM_BOOST_BASE_URL=your_base_url_here LLM_BOOST_BASE_URL=your_base_url_here
LLM_BOOST_MODEL_NAME=your_model_name_here LLM_BOOST_MODEL_NAME=your_model_name_here
# ===== 前端API超时配置可选=====
# 本地大模型响应较慢时可以增加此值(毫秒)
# VITE_API_TIMEOUT=600000 # 10分钟

View File

@ -43,6 +43,56 @@ def optimize_interview_prompt(prompt: str) -> str:
return f"{INTERVIEW_PROMPT_PREFIX}{prompt}" return f"{INTERVIEW_PROMPT_PREFIX}{prompt}"
def detect_platform_from_simulation(simulation_id: str) -> str:
"""
Detect which platform(s) were used in a simulation by checking for database files.
Args:
simulation_id: The simulation ID to check
Returns:
Platform name ('reddit' or 'twitter'), defaulting to 'reddit' if neither exists
"""
import os
from pathlib import Path
base_path = Path(os.environ.get('SIMULATION_DATA_PATH', 'data')) / simulation_id
# Check for actual database files
has_reddit = (base_path / 'reddit_simulation.db').exists()
has_twitter = (base_path / 'twitter_simulation.db').exists()
# Return the platform that actually has data
if has_twitter and not has_reddit:
return 'twitter'
elif has_reddit and not has_twitter:
return 'reddit'
elif has_twitter and has_reddit:
# Both exist - prefer reddit for backward compatibility
return 'reddit'
else:
# Neither exists - default to reddit
return 'reddit'
def get_platform_with_fallback(simulation_id: str, requested_platform: str | None = None) -> str:
"""
Get platform with intelligent fallback to prevent silent data loss.
Args:
simulation_id: The simulation ID
requested_platform: Platform explicitly requested by user (optional)
Returns:
Platform to use for the query
"""
if requested_platform:
return requested_platform
# Auto-detect from simulation data
return detect_platform_from_simulation(simulation_id)
# ============== 实体读取接口 ============== # ============== 实体读取接口 ==============
@simulation_bp.route('/entities/<graph_id>', methods=['GET']) @simulation_bp.route('/entities/<graph_id>', methods=['GET'])
@ -993,10 +1043,14 @@ def get_simulation_profiles(simulation_id: str):
获取模拟的Agent Profile 获取模拟的Agent Profile
Query参数 Query参数
platform: 平台类型reddit/twitter默认reddit platform: 平台类型reddit/twitter默认自动检测
""" """
try: try:
platform = request.args.get('platform', 'reddit') # Auto-detect platform from simulation data if not specified
platform = get_platform_with_fallback(
simulation_id,
request.args.get('platform')
)
manager = SimulationManager() manager = SimulationManager()
profiles = manager.get_profiles(simulation_id, platform=platform) profiles = manager.get_profiles(simulation_id, platform=platform)
@ -1058,7 +1112,11 @@ def get_simulation_profiles_realtime(simulation_id: str):
from datetime import datetime from datetime import datetime
try: try:
platform = request.args.get('platform', 'reddit') # Auto-detect platform from simulation data if not specified
platform = get_platform_with_fallback(
simulation_id,
request.args.get('platform')
)
# 获取模拟目录 # 获取模拟目录
sim_dir = os.path.join(Config.OASIS_SIMULATION_DATA_DIR, simulation_id) sim_dir = os.path.join(Config.OASIS_SIMULATION_DATA_DIR, simulation_id)
@ -1997,7 +2055,11 @@ def get_simulation_posts(simulation_id: str):
返回帖子列表从SQLite数据库读取 返回帖子列表从SQLite数据库读取
""" """
try: try:
platform = request.args.get('platform', 'reddit') # Auto-detect platform from simulation data if not specified
platform = get_platform_with_fallback(
simulation_id,
request.args.get('platform')
)
limit = request.args.get('limit', 50, type=int) limit = request.args.get('limit', 50, type=int)
offset = request.args.get('offset', 0, type=int) offset = request.args.get('offset', 0, type=int)

View File

@ -4,7 +4,7 @@ import i18n from '../i18n'
// 创建axios实例 // 创建axios实例
const service = axios.create({ const service = axios.create({
baseURL: import.meta.env.VITE_API_BASE_URL || 'http://localhost:5001', baseURL: import.meta.env.VITE_API_BASE_URL || 'http://localhost:5001',
timeout: 300000, // 5分钟超时本体生成可能需要较长时间) timeout: parseInt(import.meta.env.VITE_API_TIMEOUT) || 300000, // 可配置超时时间默认5分钟本地大模型可能需要更长时间)
headers: { headers: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }