pipeline-llm/wwwroot/api/auto_config_popup.dspy

65 lines
4.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# auto_config_popup.dspy — 模型自动配置弹窗(2026-09-07 用户定夺)
# 输入 API 文档与定价信息的链接或正文,内部助手(platform_general)自动完成
# 抓取→提取→落库→定价→测试→记账检查全链,结束后汇报模型状态。
import json as _json
import random
uid = await get_user()
if not uid:
return _json.dumps({
"widgettype": "PopupWindow",
"options": {"title": "提示", "cwidth": 30, "cheight": 8, "auto_open": True},
"subwidgets": [{"widgettype": "Text", "options": {"text": "请先登录", "padding": "20px"}}]
}, ensure_ascii=False)
# 每个弹窗实例独立会话(spec 锚定按 pipeline_id:user_id:session_id 隔离,
# extract→apply 的会话级缓存在同一弹窗内天然可用)
session_id = 'llmauto' + str(random.randint(100000, 999999))
chat_url = entire_url('/pipeline_core/api/agent_chat.dspy') + '?session_id=' + session_id + '&pipeline_id=platform_general'
# 开始自动配置:读两个输入框(UiText.resultValue),组装指令,驱动 AgentIO 发送
# (input_finished 是 AgentInput 原生方法:dispatch('inputed') → AgentIO 走 POST 流)
start_script = (
"var io=bricks.getWidgetById('llm_auto_io',bricks.app);if(!io||!io.inputw)return;"
"var aw=bricks.getWidgetById('llm_auto_api',bricks.app);"
"var pw=bricks.getWidgetById('llm_auto_pricing',bricks.app);"
"var api=aw&&aw.resultValue?String(aw.resultValue()||'').trim():'';"
"var pricing=pw&&pw.resultValue?String(pw.resultValue()||'').trim():'';"
"if(!api){new bricks.Message({title:'缺少输入',message:'请填写 API 文档链接或粘贴文档正文'});return;}"
"var p='请自动配置模型。API 文档(链接或正文)如下:\\n'+api;"
"if(pricing){p+='\\n定价信息(链接或正文,若 API 文档已含定价则以文档为准)如下:\\n'+pricing;}"
"p+='\\n请按模型自动配置全链工作流一口气完成(抓取/提取/落库/定价/测试/记账检查),"
"结束后汇报模型状态(配置/定价/测试/记账四段结果+遗留事项)。';"
"io.inputw.textw.setValue(p);io.inputw.input_finished();")
resp = {
"widgettype": "PopupWindow",
"id": "llm_auto_cfg_pw",
"options": {"title": "🤖 模型自动配置(内部助手)", "width": "85%", "height": "85%", "auto_open": True},
"subwidgets": [{
"widgettype": "VBox",
"options": {"css": "filler", "width": "100%", "height": "100%", "padding": "12px", "gap": "8px"},
"subwidgets": [
{"widgettype": "Text", "options": {
"text": "粘贴 API 文档链接或直接粘贴文档正文;定价可单独给出(链接或正文),未给则从 API 文档提取。点击「开始自动配置」后由内部助手完成全链并汇报模型状态。",
"cfontsize": 0.9, "color": "#64748b", "halign": "left"}},
{"widgettype": "Text", "options": {"text": "API 文档(链接或正文)", "cfontsize": 0.95, "halign": "left"}},
{"widgettype": "UiText", "id": "llm_auto_api",
"options": {"name": "llm_auto_api", "placeholder": "https://help.aliyun.com/... 或直接粘贴文档正文"}},
{"widgettype": "Text", "options": {"text": "定价信息(链接或正文,可空)", "cfontsize": 0.95, "halign": "left"}},
{"widgettype": "UiText", "id": "llm_auto_pricing",
"options": {"name": "llm_auto_pricing", "placeholder": "定价页链接或价格表正文(元/千token、元/秒等,须来自文档原文)"}},
{"widgettype": "Button", "id": "llm_auto_start",
"options": {"label": "开始自动配置", "css": "small"},
"binds": [{"wid": "self", "event": "click", "actiontype": "script",
"target": "self", "script": start_script}]},
{"widgettype": "AgentIO", "id": "llm_auto_io",
"options": {"css": "filler", "url": chat_url,
"model_dataurl": entire_url('/pipeline_core/api/agent_model_options.dspy') + '?session_id=' + session_id + '&pipeline_id=platform_general',
"model_cwidth": 14,
"placeholder": "也可以直接对内部助手说话,例如:通读这份文档并配置模型 <URL> ..."}}
]}]
}
return _json.dumps(resp, ensure_ascii=False)