22Author: ai-business-hql [email protected] 33Date: 2025-07-31 19:38:08
44LastEditors: ai-business-hql [email protected] 5- LastEditTime: 2025-09-03 11:00:57
5+ LastEditTime: 2025-11-20 17:51:33
66FilePath: /comfyui_copilot/backend/agent_factory.py
77Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
88'''
9- import os
9+
1010try :
11- from agents import Agent , OpenAIChatCompletionsModel , ModelSettings
11+ from agents import Agent , OpenAIChatCompletionsModel , ModelSettings , Runner , set_trace_processors , set_tracing_disabled , set_default_openai_api
1212 if not hasattr (__import__ ('agents' ), 'Agent' ):
1313 raise ImportError
1414except Exception :
2828
2929from agents ._config import set_default_openai_api
3030from agents .tracing import set_tracing_disabled
31+ import asyncio
3132# from .utils.logger import log
3233
3334# def load_env_config():
4647# load_env_config()
4748
4849set_default_openai_api ("chat_completions" )
49- set_tracing_disabled (True )
50+ set_tracing_disabled (False )
51+
52+
5053def create_agent (** kwargs ) -> Agent :
5154 # 通过用户配置拿/环境变量
5255 config = kwargs .pop ("config" ) if "config" in kwargs else {}
@@ -59,13 +62,13 @@ def create_agent(**kwargs) -> Agent:
5962 # Determine base URL and API key
6063 base_url = LLM_DEFAULT_BASE_URL
6164 api_key = get_comfyui_copilot_api_key () or ""
62-
65+
6366 if config :
6467 if config .get ("openai_base_url" ) and config .get ("openai_base_url" ) != "" :
6568 base_url = config .get ("openai_base_url" )
6669 if config .get ("openai_api_key" ) and config .get ("openai_api_key" ) != "" :
6770 api_key = config .get ("openai_api_key" )
68-
71+
6972 # Check if this is LMStudio and adjust API key handling
7073 is_lmstudio = is_lmstudio_url (base_url )
7174 if is_lmstudio and not api_key :
0 commit comments