Skip to content

Commit 37c7b7b

Browse files
feat: 开放所有apikey
1 parent 46f88cd commit 37c7b7b

17 files changed

+448
-346
lines changed

backend/controller/conversation_api.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ async def invoke_chat(request):
239239
"workflow_checkpoint_id": workflow_checkpoint_id,
240240
"openai_api_key": request.headers.get('Openai-Api-Key'),
241241
"openai_base_url": request.headers.get('Openai-Base-Url'),
242+
# Workflow LLM settings (optional, used by tools/agents that need a different LLM)
243+
"workflow_llm_api_key": request.headers.get('Workflow-LLM-Api-Key'),
244+
"workflow_llm_base_url": request.headers.get('Workflow-LLM-Base-Url'),
242245
"model_select": next((x['data'][0] for x in ext if x['type'] == 'model_select' and x.get('data')), None)
243246
}
244247

@@ -504,7 +507,10 @@ async def invoke_debug(request):
504507
"session_id": session_id,
505508
"model": "gemini-2.5-flash", # Default model for debug agents
506509
"openai_api_key": request.headers.get('Openai-Api-Key'),
507-
"openai_base_url": request.headers.get('Openai-Base-Url', 'https://api.openai.com/v1'),
510+
"openai_base_url": request.headers.get('Openai-Base-Url'),
511+
# Workflow LLM settings (optional)
512+
"workflow_llm_api_key": request.headers.get('Workflow-LLM-Api-Key'),
513+
"workflow_llm_base_url": request.headers.get('Workflow-LLM-Base-Url'),
508514
}
509515

510516
# 获取当前语言

backend/service/debug_agent.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'''
22
Debug Agent for ComfyUI Workflow Error Analysis
33
'''
4+
from ..utils.key_utils import workflow_config_adapt
45
from ..agent_factory import create_agent
56
from agents.items import ItemHelpers
67
from agents.run import Runner
@@ -205,6 +206,7 @@ async def debug_workflow_errors(workflow_data: Dict[str, Any]):
205206
# Get session_id and config from request context
206207
session_id = get_session_id()
207208
config = get_config()
209+
workflow_config_adapt(config)
208210

209211
if not session_id:
210212
session_id = str(uuid.uuid4()) # Fallback if no context
@@ -253,7 +255,8 @@ async def debug_workflow_errors(workflow_data: Dict[str, Any]):
253255
model=WORKFLOW_MODEL_NAME,
254256
tools=[run_workflow, analyze_error_type, save_current_workflow],
255257
config={
256-
"max_tokens": 8192
258+
"max_tokens": 8192,
259+
**config
257260
}
258261
)
259262

@@ -302,7 +305,8 @@ async def debug_workflow_errors(workflow_data: Dict[str, Any]):
302305
tools=[get_current_workflow, get_node_info, update_workflow],
303306
handoffs=[agent],
304307
config={
305-
"max_tokens": 8192
308+
"max_tokens": 8192,
309+
**config
306310
}
307311
)
308312

@@ -393,7 +397,8 @@ async def debug_workflow_errors(workflow_data: Dict[str, Any]):
393397
get_current_workflow, get_node_info],
394398
handoffs=[agent],
395399
config={
396-
"max_tokens": 8192
400+
"max_tokens": 8192,
401+
**config
397402
}
398403
)
399404

@@ -487,7 +492,8 @@ async def debug_workflow_errors(workflow_data: Dict[str, Any]):
487492
suggest_model_download, update_workflow_parameter, get_current_workflow],
488493
handoffs=[agent],
489494
config={
490-
"max_tokens": 8192
495+
"max_tokens": 8192,
496+
**config
491497
}
492498
)
493499

@@ -692,16 +698,9 @@ async def debug_workflow_errors(workflow_data: Dict[str, Any]):
692698

693699
except Exception as e:
694700
log.error(f"Error in debug_workflow_errors: {str(e)}")
695-
error_message = current_text + f"\n\n× Error occurred during debugging: {str(e)}\n\n"
701+
error_message = f"\n\n× Error occurred during debugging: {str(e)}\n\n"
696702

697-
# Include workflow_update ext if captured from tools before the error
698-
final_error_ext = None
699-
if 'workflow_update_ext' in locals() and workflow_update_ext:
700-
final_error_ext = [workflow_update_ext]
701-
log.info(f"-- Including latest workflow_update ext in error response")
702-
703703
ext_with_finished = {
704-
"data": final_error_ext,
705704
"finished": True
706705
}
707706
yield (error_message, ext_with_finished)

backend/service/workflow_rewrite_agent.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Author: ai-business-hql qingli.hql@alibaba-inc.com
33
Date: 2025-07-24 17:10:23
44
LastEditors: ai-business-hql ai.bussiness.hql@gmail.com
5-
LastEditTime: 2025-08-28 11:15:49
5+
LastEditTime: 2025-09-30 11:03:37
66
FilePath: /comfyui_copilot/backend/service/workflow_rewrite_agent.py
77
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
88
'''
@@ -14,11 +14,13 @@
1414
import os
1515
from typing import Dict, Any
1616

17+
from ..utils.key_utils import workflow_config_adapt
18+
1719
from ..dao.expert_table import list_rewrite_experts_short, get_rewrite_expert_by_name_list
1820

1921
from ..agent_factory import create_agent
2022
from ..utils.globals import WORKFLOW_MODEL_NAME, get_language
21-
from ..utils.request_context import get_session_id
23+
from ..utils.request_context import get_config, get_session_id
2224

2325
from ..service.workflow_rewrite_tools import *
2426

@@ -42,7 +44,9 @@ def create_workflow_rewrite_agent():
4244

4345
language = get_language()
4446
session_id = get_session_id() or "unknown_session"
45-
47+
config = get_config()
48+
workflow_config_adapt(config)
49+
4650
return create_agent(
4751
name="Workflow Rewrite Agent",
4852
model=WORKFLOW_MODEL_NAME,

backend/service/workflow_rewrite_agent_simple.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
from typing import Dict, Any, Optional
1212
import asyncio
1313
from pydantic import BaseModel
14+
from ..utils.key_utils import workflow_config_adapt
1415
from openai import OpenAI
1516

1617
from ..agent_factory import create_agent
1718
from ..utils.globals import WORKFLOW_MODEL_NAME, get_comfyui_copilot_api_key, LLM_DEFAULT_BASE_URL
18-
from ..utils.request_context import get_rewrite_context, RewriteContext
19+
from ..utils.request_context import get_config, get_rewrite_context, RewriteContext
1920
from ..utils.logger import log
2021

2122

@@ -81,11 +82,12 @@ def rewrite_workflow_simple(rewrite_context: RewriteContext) -> str:
8182
"workflow_data": "这里是完整的工作流JSON字符串"
8283
}
8384
"""
84-
85+
config = get_config()
86+
workflow_config_adapt(config)
8587
# 创建OpenAI客户端
8688
client = OpenAI(
87-
base_url = LLM_DEFAULT_BASE_URL,
88-
api_key = get_comfyui_copilot_api_key() or ""
89+
base_url = config.get("openai_base_url") or LLM_DEFAULT_BASE_URL,
90+
api_key = config.get("openai_api_key") or get_comfyui_copilot_api_key() or ""
8991
)
9092

9193
# 调用LLM

backend/utils/globals.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
Author: ai-business-hql qingli.hql@alibaba-inc.com
33
Date: 2025-08-08 17:14:52
44
LastEditors: ai-business-hql ai.bussiness.hql@gmail.com
5-
<<<<<<< HEAD
6-
LastEditTime: 2025-08-25 17:41:14
7-
=======
8-
LastEditTime: 2025-08-29 11:25:52
9-
>>>>>>> mcp
5+
LastEditTime: 2025-09-30 10:18:44
106
FilePath: /comfyui_copilot/backend/utils/globals.py
117
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
128
'''
@@ -15,8 +11,16 @@
1511
Global utilities for managing application-wide state and configuration.
1612
"""
1713

14+
import os
1815
import threading
1916
from typing import Optional, Dict, Any
17+
from pathlib import Path
18+
from dotenv import load_dotenv
19+
20+
# Load .env file if it exists
21+
env_path = Path(__file__).parent.parent.parent / '.env'
22+
if env_path.exists():
23+
load_dotenv(env_path)
2024

2125
class GlobalState:
2226
"""Thread-safe global state manager for application-wide configuration."""
@@ -95,11 +99,11 @@ def set_comfyui_copilot_api_key(api_key: str) -> None:
9599
_global_state.set('comfyui_copilot_api_key', api_key)
96100

97101

98-
BACKEND_BASE_URL = "https://comfyui-copilot-server.onrender.com"
102+
BACKEND_BASE_URL = os.getenv("BACKEND_BASE_URL", "https://comfyui-copilot-server.onrender.com")
99103
LMSTUDIO_DEFAULT_BASE_URL = "http://localhost:1234/v1"
100-
WORKFLOW_MODEL_NAME = "us.anthropic.claude-sonnet-4-20250514-v1:0"
104+
WORKFLOW_MODEL_NAME = os.getenv("WORKFLOW_MODEL_NAME", "us.anthropic.claude-sonnet-4-20250514-v1:0")
101105
# WORKFLOW_MODEL_NAME = "gpt-5-2025-08-07-GlobalStandard"
102-
LLM_DEFAULT_BASE_URL = BACKEND_BASE_URL + "/v1"
106+
LLM_DEFAULT_BASE_URL = os.getenv("LLM_DEFAULT_BASE_URL", BACKEND_BASE_URL + "/v1")
103107

104108

105109
def is_lmstudio_url(base_url: str) -> bool:

backend/utils/key_utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
3+
def workflow_config_adapt(config: dict):
4+
if config:
5+
if config.get("workflow_llm_api_key"):
6+
config["openai_api_key"] = config.get("workflow_llm_api_key")
7+
config["workflow_llm_api_key"] = None
8+
if config.get("workflow_llm_base_url"):
9+
config["openai_base_url"] = config.get("workflow_llm_base_url")
10+
config["workflow_llm_base_url"] = None

dist/copilot_web/App-SJGu_4x8.js renamed to dist/copilot_web/App-BpKMzle9.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/copilot_web/DebugGuide-DRSP8c-I.js renamed to dist/copilot_web/DebugGuide-C8uHhkvR.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)