A Simple and Universal Swarm Intelligence Engine, Predicting Anything. 简洁通用的群体智能引擎,预测万物
Python agent-memoryfinancial-forecastingfuture-predictionknowledge-graphllmsmulti-agent-simulationpublic-opinion-analysispython3social-predictionswarm-intelligence
Update .env.example and enhance create_model function for dual LLM configuration
666ghj39253b3213e6
diff --git a/.env.example b/.env.exampleindex 86d37836..b4b3c0e0 100644--- a/.env.example+++ b/.env.example@@ -1,8 +1,12 @@-# Zep Cloud API Key-# 从 https://app.getzep.com 获取-ZEP_API_KEY=+# ===== ZEP记忆图谱配置 =====+ZEP_API_KEY=your_zep_api_key_here-# LLM API Key-LLM_API_KEY=-LLM_BASE_URL=-LLM_MODEL_NAME=\ No newline at end of file+# ===== 通用 LLM 配置 =====+LLM_API_KEY=your_api_key_here+LLM_BASE_URL=https://api.openai.com/v1+LLM_MODEL_NAME=gpt-4o-mini++# ===== 加速 LLM 配置(可选)=====+LLM_BOOST_API_KEY=your_boost_api_key_here+LLM_BOOST_BASE_URL=https://another-api-provider.com/v1+LLM_BOOST_MODEL_NAME=gpt-4o-mini\ No newline at end of filediff --git a/backend/scripts/run_parallel_simulation.py b/backend/scripts/run_parallel_simulation.pyindex 35fb47c4..446608c4 100644--- a/backend/scripts/run_parallel_simulation.py+++ b/backend/scripts/run_parallel_simulation.py@@ -267,23 +267,41 @@ def fetch_new_actions_from_db(return actions, new_last_rowid-def create_model(config: Dict[str, Any]):+def create_model(config: Dict[str, Any], use_boost: bool = False):"""创建LLM模型- 统一使用项目根目录 .env 文件中的配置(优先级最高):- - LLM_API_KEY: API密钥- - LLM_BASE_URL: API基础URL- - LLM_MODEL_NAME: 模型名称+ 支持双 LLM 配置,用于并行模拟时提速:+ - 通用配置:LLM_API_KEY, LLM_BASE_URL, LLM_MODEL_NAME+ - 加速配置(可选):LLM_BOOST_API_KEY, LLM_BOOST_BASE_URL, LLM_BOOST_MODEL_NAME- OASIS使用camel-ai的ModelFactory,需要设置 OPENAI_API_KEY 和 OPENAI_API_BASE_URL 环境变量+ 如果配置了加速 LLM,并行模拟时可以让不同平台使用不同的 API 服务商,提高并发能力。++ Args:+ config: 模拟配置字典+ use_boost: 是否使用加速 LLM 配置(如果可用)"""- # 优先从 .env 读取配置- llm_api_key = os.environ.get("LLM_API_KEY", "")- llm_base_url = os.environ.get("LLM_BASE_URL", "")- llm_model = os.environ.get("LLM_MODEL_NAME", "")+ # 检查是否有加速配置+ boost_api_key = os.environ.get("LLM_BOOST_API_KEY", "")+ boost_base_url = os.environ.get("LLM_BOOST_BASE_URL", "")+ boost_model = os.environ.get("LLM_BOOST_MODEL_NAME", "")+ has_boost_config = bool(boost_api_key)++ # 根据参数和配置情况选择使用哪个 LLM+ if use_boost and has_boost_config:+ # 使用加速配置+ llm_api_key = boost_api_key+ llm_base_url = boost_base_url+ llm_model = boost_model or os.environ.get("LLM_MODEL_NAME", "")+ config_label = "[加速LLM]"+ else:+ # 使用通用配置+ llm_api_key = os.environ.get("LLM_API_KEY", "")+ llm_base_url = os.environ.get("LLM_BASE_URL", "")+ llm_model = os.environ.get("LLM_MODEL_NAME", "")+ config_label = "[通用LLM]"- # 如果 .env 中没有,则使用 config 作为备用+ # 如果 .env 中没有模型名,则使用 config 作为备用if not llm_model:llm_model = config.get("llm_model", "gpt-4o-mini")@@ -297,7 +315,7 @@ def create_model(config: Dict[str, Any]):if llm_base_url:os.environ["OPENAI_API_BASE_URL"] = llm_base_url- print(f"LLM配置: model={llm_model}, base_url={llm_base_url[:40] if llm_base_url else '默认'}...")+ print(f"{config_label} model={llm_model}, base_url={llm_base_url[:40] if llm_base_url else '默认'}...")return ModelFactory.create(model_platform=ModelPlatformType.OPENAI,@@ -372,7 +390,8 @@ async def run_twitter_simulation(log_info("初始化...")- model = create_model(config)+ # Twitter 使用通用 LLM 配置+ model = create_model(config, use_boost=False)# OASIS Twitter使用CSV格式profile_path = os.path.join(simulation_dir, "twitter_profiles.csv")@@ -517,7 +536,8 @@ async def run_reddit_simulation(log_info("初始化...")- model = create_model(config)+ # Reddit 使用加速 LLM 配置(如果有的话,否则回退到通用配置)+ model = create_model(config, use_boost=True)profile_path = os.path.join(simulation_dir, "reddit_profiles.json")if not os.path.exists(profile_path):