中期成果提交:PPT自动生成 Agent(感知-规划-行动-记忆闭环 + aura-ppt 渲染引擎 + Web 交互界面 + 测试用例 + AI 使用日志)
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""候选免费模型基准测试:大纲任务耗时 + JSON 有效性。"""
|
||||
import io
|
||||
import json
|
||||
import sys
|
||||
import time
|
||||
import urllib.request
|
||||
|
||||
sys.path.insert(0, r"D:\00.张华丹\VS专用\04.PPT自动生成\ppt-agent")
|
||||
|
||||
BASE = "http://127.0.0.1:4096"
|
||||
SAMPLE = """# 项目背景
|
||||
为提升知识周转效率启动平台建设,前期调研两个月
|
||||
# 本期成果
|
||||
部署完成基础服务,导入文档120份
|
||||
混合检索准确率较基线提升明显
|
||||
完成三个部门试点接入
|
||||
# 下一步
|
||||
扩大试点范围,建立运营机制
|
||||
"""
|
||||
|
||||
PROMPT = """请把下面的内容规划成一份 PPT 的页面大纲。
|
||||
要求:
|
||||
1. 页面总数 6~9 页(含封面、目录、结尾)
|
||||
2. 输出语言:中文
|
||||
3. 页面类型只能用:cover / toc / section / content / two_column / end
|
||||
4. 第一页 cover,最后一页 end
|
||||
5. content 页的 content 数组为要点(每条一句话,4~6 条)
|
||||
6. 每页写 notes:2~3 句口语化演讲备注
|
||||
7. 标题要有信息量
|
||||
输出格式:{"slides": [{"type": "...", "title": "...", "content": ["..."], "notes": "..."}]}
|
||||
|
||||
【用户标题】知识平台周报
|
||||
【用户内容】
|
||||
""" + SAMPLE
|
||||
|
||||
|
||||
def post(path, payload, timeout):
|
||||
req = urllib.request.Request(
|
||||
BASE + path, data=json.dumps(payload).encode("utf-8"), method="POST",
|
||||
headers={"Content-Type": "application/json"})
|
||||
with urllib.request.urlopen(req, timeout=timeout) as r:
|
||||
return json.loads(r.read() or b"{}")
|
||||
|
||||
|
||||
def run_model(model_id):
|
||||
t0 = time.time()
|
||||
try:
|
||||
sess = post("/session", {"title": "bench"}, 30)
|
||||
sid = sess["id"]
|
||||
provider, _, model = model_id.partition("/")
|
||||
result = post(f"/session/{sid}/message", {
|
||||
"model": {"providerID": provider, "modelID": model},
|
||||
"parts": [{"type": "text", "text": PROMPT}],
|
||||
}, 300)
|
||||
dt = time.time() - t0
|
||||
text = "\n".join(p.get("text", "") for p in result.get("parts", [])
|
||||
if p.get("type") == "text")
|
||||
s, e = text.find("{"), text.rfind("}")
|
||||
ok = False
|
||||
n = 0
|
||||
if 0 <= s < e:
|
||||
try:
|
||||
data = json.loads(text[s:e + 1])
|
||||
slides = data.get("slides", [])
|
||||
n = len(slides)
|
||||
ok = 4 <= n <= 12 and all("title" in x for x in slides)
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
print(f"{model_id:45s} {dt:6.1f}s pages={n:2d} valid={ok}")
|
||||
return dt, ok
|
||||
except Exception as exc: # noqa: BLE001
|
||||
print(f"{model_id:45s} FAIL {str(exc)[:60]}")
|
||||
return 999, False
|
||||
|
||||
|
||||
for m in sys.argv[1:] or ["opencode/nemotron-3.5-lightning-free",
|
||||
"opencode/mimo-v2.5-free",
|
||||
"opencode/hy3-free"]:
|
||||
run_model(m)
|
||||
Reference in New Issue
Block a user