From 1785c6b9fe03e96ca3d7fea4331ed424b0ceab47 Mon Sep 17 00:00:00 2001 From: ai-business-hql Date: Mon, 25 Aug 2025 21:30:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=8A=E4=B8=8B=E6=96=878192?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/agent_factory.py | 8 +++++--- backend/service/workflow_rewrite_agent.py | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/backend/agent_factory.py b/backend/agent_factory.py index 2a8df9b..8c79f02 100644 --- a/backend/agent_factory.py +++ b/backend/agent_factory.py @@ -2,11 +2,11 @@ Author: ai-business-hql qingli.hql@alibaba-inc.com Date: 2025-07-31 19:38:08 LastEditors: ai-business-hql ai.bussiness.hql@gmail.com -LastEditTime: 2025-08-25 17:42:41 +LastEditTime: 2025-08-25 21:23:10 FilePath: /comfyui_copilot/backend/agent_factory.py Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE ''' -from agents import Agent, OpenAIChatCompletionsModel +from agents import Agent, OpenAIChatCompletionsModel, ModelSettings from dotenv import dotenv_values from .utils.globals import LLM_DEFAULT_BASE_URL, LMSTUDIO_DEFAULT_BASE_URL, get_comfyui_copilot_api_key, is_lmstudio_url from openai import AsyncOpenAI @@ -68,5 +68,7 @@ def create_agent(**kwargs) -> Agent: default_model_name = os.environ.get("OPENAI_MODEL", "gemini-2.5-flash") model_name = kwargs.pop("model") or default_model_name model = OpenAIChatCompletionsModel(model_name, openai_client=client) - + + if config.get("max_tokens"): + return Agent(model=model, model_settings=ModelSettings(max_tokens=config.get("max_tokens") or 8192), **kwargs) return Agent(model=model, **kwargs) \ No newline at end of file diff --git a/backend/service/workflow_rewrite_agent.py b/backend/service/workflow_rewrite_agent.py index 3624638..a49301c 100644 --- a/backend/service/workflow_rewrite_agent.py +++ b/backend/service/workflow_rewrite_agent.py @@ -105,6 +105,9 @@ def create_workflow_rewrite_agent(): 始终以用户的实际需求为导向,提供专业、准确、高效的工作流改写服务。 """, tools=[get_rewrite_expert_by_name, get_current_workflow, get_node_info, update_workflow, remove_node], + config={ + "max_tokens": 8192 + } ) # 注意:工作流改写代理现在需要在有session context的环境中创建