fix: reduce LLM timeouts — truncate docs to 8k/6k chars, cut num_predict 16k→4k, tighten prompts, trim anti-hallucination rules
This commit is contained in:
@@ -183,22 +183,15 @@ def get_event_json_schema() -> dict[str, Any]:
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
_SYSTEM_PROMPT = """\
|
||||
You classify global news articles into structured macro event intelligence. \
|
||||
Read the article carefully and extract the event classification. \
|
||||
Return ONLY valid JSON matching the schema. No commentary, no markdown, no explanation."""
|
||||
You classify global news into structured macro event JSON. \
|
||||
Return ONLY a single JSON object. No markdown, no explanation. \
|
||||
Every field is required. Keep key_facts to 3-5 items. Keep summary under 3 sentences."""
|
||||
|
||||
_ANTI_HALLUCINATION_RULES = """\
|
||||
CRITICAL RULES — read carefully:
|
||||
1. Only extract information EXPLICITLY stated in the article text.
|
||||
2. Do NOT infer, speculate, or fabricate facts, regions, sectors, or commodities.
|
||||
3. If the article mentions multiple distinct impact types, include ALL of them in event_types.
|
||||
4. For affected_regions, only include regions explicitly mentioned or clearly implied by the event.
|
||||
5. For affected_sectors, only include sectors with a clear causal link to the event.
|
||||
6. For affected_commodities, only include commodities directly referenced or obviously impacted.
|
||||
7. For key_facts, each fact must be directly supported by a specific passage in the text.
|
||||
8. If the article is vague or speculative, set confidence LOW (below 0.4).
|
||||
9. Do NOT treat journalist speculation or opinion as confirmed fact.
|
||||
10. Distinguish between announced policy and proposed/rumored policy."""
|
||||
RULES:
|
||||
- Only extract facts EXPLICITLY stated in the text. Do NOT fabricate.
|
||||
- If vague or speculative, set confidence below 0.4.
|
||||
- Distinguish announced policy from rumored policy."""
|
||||
|
||||
|
||||
def build_event_classification_prompt(text: str) -> dict[str, str]:
|
||||
@@ -210,6 +203,11 @@ def build_event_classification_prompt(text: str) -> dict[str, str]:
|
||||
Returns:
|
||||
Dict with 'system' and 'user' prompt strings.
|
||||
"""
|
||||
# Truncate long articles to reduce inference time
|
||||
max_chars = 6000
|
||||
if len(text) > max_chars:
|
||||
text = text[:max_chars] + "\n[... truncated ...]"
|
||||
|
||||
user_prompt = f"""\
|
||||
Classify this global news article as a macro event. Fill every field.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user