mirror of
https://github.com/primedigitaltech/market-assistant.git
synced 2026-07-21 23:41:39 +08:00
demo: 全量报告侧车文件含模型名与耗时
competitor_analysis__fulltest_<slug>_时间戳;stdout 输出 model 与 elapsed_sec。 Made-with: Cursor
This commit is contained in:
parent
e2c0d3289d
commit
7b33af8a37
@ -1,8 +1,10 @@
|
|||||||
"""
|
"""
|
||||||
在已有流水线目录上重生成报告,**将产出的 Markdown 以测试文件名落盘**,不长期覆盖 ``competitor_analysis.md``。
|
在已有流水线目录上重生成报告,**将产出的 Markdown 以测试文件名落盘**,不长期覆盖 ``competitor_analysis.md``。
|
||||||
|
|
||||||
- 若目录下已有 ``competitor_analysis.md``:先复制为 ``competitor_analysis__pre_test_<时间戳>.md``,再重生成,再把**新生成**内容复制为 ``competitor_analysis__llmtest_<时间戳>.md``,最后把**原内容**写回 ``competitor_analysis.md``。
|
- 若目录下已有 ``competitor_analysis.md``:先复制为 ``competitor_analysis__pre_test_<时间戳>.md``,再重生成,再把**新生成**内容复制为 ``competitor_analysis__fulltest_<模型简写>_<时间戳>.md``(简写来自当前环境 ``OPENAI_TEXT_MODEL``,若未设则回退 ``OPENAI_VISION_MODEL``),最后把**原内容**写回 ``competitor_analysis.md``。
|
||||||
- 若原本没有主报告:重生成后复制一份为 ``...__llmtest_...``,主文件即新生成结果。
|
- 若原本没有主报告:重生成后复制一份为 ``...__fulltest_...``,主文件即新生成结果。
|
||||||
|
|
||||||
|
对比两种纯文本模型时,可在**启动进程前**在 shell 中设置 ``OPENAI_TEXT_MODEL=...``(优先于 .env 同项),全量重跑两次,用文件名中的模型段区分;stderr 会打印 ``elapsed_sec``、所用模型名。
|
||||||
|
|
||||||
用法(在 backend 下,已配置 Django 与 .env)::
|
用法(在 backend 下,已配置 Django 与 .env)::
|
||||||
|
|
||||||
@ -15,8 +17,10 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@ -33,6 +37,21 @@ django.setup()
|
|||||||
from pipeline.jd.runner import regenerate_competitor_report # noqa: E402
|
from pipeline.jd.runner import regenerate_competitor_report # noqa: E402
|
||||||
|
|
||||||
|
|
||||||
|
def _model_label_for_env() -> str:
|
||||||
|
return (
|
||||||
|
(os.environ.get("OPENAI_TEXT_MODEL") or os.environ.get("OPENAI_VISION_MODEL") or "default")
|
||||||
|
.strip()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _model_slug_for_filename() -> str:
|
||||||
|
raw = _model_label_for_env()
|
||||||
|
s = raw.replace("/", "__").replace("\\", "_")
|
||||||
|
s = re.sub(r'[<>:"|?*]+', "_", s)
|
||||||
|
s = re.sub(r"[^\w.\-]+", "_", s).strip("._-") or "model"
|
||||||
|
return s[:100]
|
||||||
|
|
||||||
|
|
||||||
def _default_run_dir() -> Path:
|
def _default_run_dir() -> Path:
|
||||||
custom = (os.environ.get("MA_TEST_RUN_DIR") or "").strip()
|
custom = (os.environ.get("MA_TEST_RUN_DIR") or "").strip()
|
||||||
if custom:
|
if custom:
|
||||||
@ -85,19 +104,25 @@ def main() -> int:
|
|||||||
else:
|
else:
|
||||||
report_config = None
|
report_config = None
|
||||||
ts = datetime.now().strftime("%Y%m%d_%H%M%S")
|
ts = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||||
|
slug = _model_slug_for_filename()
|
||||||
|
mlabel = _model_label_for_env()
|
||||||
main = run_dir / "competitor_analysis.md"
|
main = run_dir / "competitor_analysis.md"
|
||||||
pre_bak = run_dir / f"competitor_analysis__pre_test_{ts}.md"
|
pre_bak = run_dir / f"competitor_analysis__pre_test_{ts}.md"
|
||||||
out_test = run_dir / f"competitor_analysis__llmtest_{ts}.md"
|
out_test = run_dir / f"competitor_analysis__fulltest_{slug}_{ts}.md"
|
||||||
had_main = main.is_file()
|
had_main = main.is_file()
|
||||||
if had_main:
|
if had_main:
|
||||||
shutil.copy2(main, pre_bak)
|
shutil.copy2(main, pre_bak)
|
||||||
print("run_dir:", run_dir, file=sys.stderr)
|
print("run_dir:", run_dir, file=sys.stderr)
|
||||||
print("keyword:", kw, file=sys.stderr)
|
print("keyword:", kw, file=sys.stderr)
|
||||||
|
print("OPENAI_TEXT_MODEL (effective for text):", mlabel, file=sys.stderr)
|
||||||
print(
|
print(
|
||||||
"regenerating (full config, may take long; set MA_TEST_REPORT_FAST=1 for quick) ...",
|
"regenerating (full config, may take long; set MA_TEST_REPORT_FAST=1 for quick) ...",
|
||||||
file=sys.stderr,
|
file=sys.stderr,
|
||||||
)
|
)
|
||||||
|
t0 = time.perf_counter()
|
||||||
regenerate_competitor_report(str(run_dir), kw, report_config=report_config)
|
regenerate_competitor_report(str(run_dir), kw, report_config=report_config)
|
||||||
|
elapsed = time.perf_counter() - t0
|
||||||
|
print("elapsed_sec:", round(elapsed, 2), file=sys.stderr)
|
||||||
if not main.is_file():
|
if not main.is_file():
|
||||||
print("未生成 competitor_analysis.md", file=sys.stderr)
|
print("未生成 competitor_analysis.md", file=sys.stderr)
|
||||||
return 2
|
return 2
|
||||||
@ -105,6 +130,8 @@ def main() -> int:
|
|||||||
if had_main and pre_bak.is_file():
|
if had_main and pre_bak.is_file():
|
||||||
shutil.copy2(pre_bak, main)
|
shutil.copy2(pre_bak, main)
|
||||||
print("test_output:", out_test)
|
print("test_output:", out_test)
|
||||||
|
print("elapsed_sec:", round(elapsed, 2))
|
||||||
|
print("model:", mlabel)
|
||||||
if had_main:
|
if had_main:
|
||||||
print("restored:", main, "from", pre_bak, file=sys.stderr)
|
print("restored:", main, "from", pre_bak, file=sys.stderr)
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user