mirror of
https://ghfast.top/https://github.com/aeroxw/tick-stock-panel.git
synced 2026-09-12 17:54:15 +08:00
merge: 试验性合并 PR #193 (feat/ai-generate-signal) 到最新 main
This commit is contained in:
@@ -63,6 +63,8 @@ def get_settings() -> dict:
|
||||
current_codex_reasoning_effort,
|
||||
current_openai_model,
|
||||
current_openai_reasoning_effort,
|
||||
current_ai_context_window,
|
||||
current_ai_max_output_tokens,
|
||||
)
|
||||
|
||||
key = secrets_store.get_tickflow_key()
|
||||
@@ -91,6 +93,8 @@ def get_settings() -> dict:
|
||||
"ai_codex_command": current_codex_command(),
|
||||
"ai_codex_reasoning_effort": current_codex_reasoning_effort(),
|
||||
"ai_user_agent": secrets_store.get_ai_config("ai_user_agent", settings.ai_user_agent),
|
||||
"ai_max_output_tokens": current_ai_max_output_tokens(),
|
||||
"ai_context_window": current_ai_context_window(),
|
||||
}
|
||||
|
||||
|
||||
@@ -251,6 +255,8 @@ class AiSettingsIn(BaseModel):
|
||||
codex_command: str = ""
|
||||
codex_reasoning_effort: str = ""
|
||||
user_agent: str = ""
|
||||
max_output_tokens: int | None = None # 输出上限, 钳制所有任务的 max_tokens
|
||||
context_window: int | None = None # 输入上下文窗口上限 (约 token)
|
||||
|
||||
|
||||
@router.post("/ai")
|
||||
@@ -267,6 +273,8 @@ def save_ai_settings(req: AiSettingsIn) -> dict:
|
||||
current_codex_reasoning_effort,
|
||||
current_openai_model,
|
||||
current_openai_reasoning_effort,
|
||||
current_ai_context_window,
|
||||
current_ai_max_output_tokens,
|
||||
normalize_codex_command,
|
||||
normalize_codex_model,
|
||||
normalize_codex_reasoning_effort,
|
||||
@@ -307,6 +315,18 @@ def save_ai_settings(req: AiSettingsIn) -> dict:
|
||||
updates["ai_user_agent"] = req.user_agent
|
||||
settings.ai_user_agent = req.user_agent
|
||||
|
||||
# 输出上限 / 输入上下文窗口 (数值配置, 缺省保持原值)
|
||||
if req.max_output_tokens is not None:
|
||||
if req.max_output_tokens <= 0:
|
||||
raise HTTPException(status_code=400, detail="输出上限必须为正整数")
|
||||
updates["ai_max_output_tokens"] = req.max_output_tokens
|
||||
settings.ai_max_output_tokens = req.max_output_tokens
|
||||
if req.context_window is not None:
|
||||
if req.context_window <= 0:
|
||||
raise HTTPException(status_code=400, detail="上下文窗口必须为正整数")
|
||||
updates["ai_context_window"] = req.context_window
|
||||
settings.ai_context_window = req.context_window
|
||||
|
||||
if updates:
|
||||
secrets_store.save(updates)
|
||||
|
||||
@@ -321,6 +341,8 @@ def save_ai_settings(req: AiSettingsIn) -> dict:
|
||||
"ai_codex_command": current_codex_command(),
|
||||
"ai_codex_reasoning_effort": current_codex_reasoning_effort(),
|
||||
"ai_configured": ai_configured(provider),
|
||||
"ai_max_output_tokens": current_ai_max_output_tokens(),
|
||||
"ai_context_window": current_ai_context_window(),
|
||||
}
|
||||
|
||||
|
||||
@@ -342,6 +364,7 @@ def clear_ai_settings() -> dict:
|
||||
"ai_codex_command",
|
||||
"ai_codex_reasoning_effort",
|
||||
)
|
||||
secrets_store.clear("ai_provider", "ai_base_url", "ai_api_key", "ai_model", "ai_codex_command", "ai_codex_reasoning_effort", "ai_max_output_tokens", "ai_context_window")
|
||||
# 同步重置运行时内存(provider 回默认值,其余置空)
|
||||
settings.ai_provider = "openai_compat"
|
||||
settings.ai_base_url = ""
|
||||
@@ -349,6 +372,8 @@ def clear_ai_settings() -> dict:
|
||||
settings.ai_model = ""
|
||||
settings.ai_codex_command = "codex"
|
||||
settings.ai_codex_reasoning_effort = ""
|
||||
settings.ai_max_output_tokens = 8192
|
||||
settings.ai_context_window = 64000
|
||||
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user