mirror of
https://github.com/primedigitaltech/market-assistant.git
synced 2026-07-22 08:01:34 +08:00
fix(pipeline): cap LLM brief size on report regen; enrich chat HTTP errors
Regenerate-report (llm) used compact_brief_for_llm default 350k chars, unlike other LLM steps (80k–100k), which can cause gateway timeouts or 5xx surfacing as 502. chat_completion_text now attaches response body snippet to HTTPError for easier diagnosis. Made-with: Cursor
This commit is contained in:
parent
a8210ec933
commit
9797796f2e
@ -281,7 +281,19 @@ def chat_completion_text(
|
||||
json=body,
|
||||
timeout=timeout,
|
||||
)
|
||||
r.raise_for_status()
|
||||
try:
|
||||
r.raise_for_status()
|
||||
except requests.HTTPError as e:
|
||||
snippet = ""
|
||||
if e.response is not None:
|
||||
snippet = (e.response.text or "")[:1200].replace("\r\n", "\n").replace("\n", " ")
|
||||
if snippet:
|
||||
raise requests.HTTPError(
|
||||
f"{e!s} | body: {snippet}",
|
||||
response=e.response,
|
||||
request=e.request,
|
||||
) from e
|
||||
raise
|
||||
data = r.json()
|
||||
msg = (data.get("choices") or [{}])[0].get("message") or {}
|
||||
return _normalize_chat_content(msg.get("content"))
|
||||
|
||||
@ -60,7 +60,8 @@ REPORT_USER_PREFIX = """请根据以下 JSON 撰写上文所述 §8.5 嵌入段
|
||||
|
||||
|
||||
def generate_competitor_report_markdown_llm(brief: dict[str, Any], keyword: str) -> str:
|
||||
compact = compact_brief_for_llm(brief)
|
||||
# 与章节衔接等 LLM 步骤一致控制体积;默认 350k 易触发网关超时/拒收导致 502
|
||||
compact = compact_brief_for_llm(brief, max_chars=100_000)
|
||||
payload = {
|
||||
"keyword": keyword,
|
||||
"competitor_brief": compact,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user