fix: ElephantAlpha crash, AiderHeal Ollama host, MCP integration for Hermes/NemoTron, and MCP hallucination
All checks were successful
CD Pipeline / deploy (push) Successful in 1m18s

This commit is contained in:
OoO
2026-04-28 12:11:33 +08:00
parent 30fc7609df
commit bc7113bc86
5 changed files with 46 additions and 29 deletions

View File

@@ -42,8 +42,8 @@ HEALTH_CHECK_URL: str = (
os.getenv("MOMO_BASE_URL", "https://mo.wooo.work").rstrip("/") + "/health"
)
OLLAMA_API_BASE: str = os.getenv("OLLAMA_API_BASE", "http://192.168.0.188:11434")
AIDER_MODEL: str = os.getenv("AIDER_MODEL", "ollama/qwen3-coder-next")
OLLAMA_API_BASE: str = os.getenv("OLLAMA_API_BASE", "http://192.168.0.111:11434")
AIDER_MODEL: str = os.getenv("AIDER_MODEL", "ollama/qwen2.5-coder:7b")
MAX_DIFF_LINES: int = int(os.getenv("AIDER_MAX_DIFF_LINES", "50"))
MAX_HOURLY_FIX: int = int(os.getenv("AIDER_MAX_HOURLY_FIX", "5"))

View File

@@ -739,9 +739,12 @@ class ElephantAlphaAutonomousEngine:
elif load < 50 and q < 5:
self.max_autonomous_decisions_per_hour = 15
# Singleton instance
autonomous_engine = ElephantAlphaAutonomousEngine()
__all__ = [
"ElephantAlphaAutonomousEngine",
"autonomous_engine",
"AutonomousTrigger",
"DecisionType",
"DecisionOutcome",

View File

@@ -22,6 +22,7 @@ from typing import Optional
import requests
from sqlalchemy import text
from services.mcp_context_service import build_mcp_context
logger = logging.getLogger(__name__)
@@ -382,7 +383,10 @@ class HermesAnalystService:
if not items:
return [], []
mcp_ctx = build_mcp_context(topics=["market_trends", "holiday_calendar", "seasonal_insights"])
prompt = (
f"【市場外部情報 (MCP)】\n{mcp_ctx}\n\n"
f"分析以下 {len(items)} 支商品的競價威脅,回傳前 {TOP_N} 個最高風險商品。\n\n"
f"資料:{json.dumps(items, ensure_ascii=False)}\n\n"
f"輸出格式JSON 陣列,每筆含):\n"

View File

@@ -33,19 +33,19 @@ MCP_MODEL = os.getenv("MCP_GEMINI_MODEL", "gemini-2.5-flash-preview-05-20")
# ── 查詢主題定義 ────────────────────────────────────────────────────────────
_SEARCH_TOPICS = {
"market_trends": (
"台灣電商 momo購物網 2025年熱銷商品趨勢 消費者行為 美妝保養 家電 生活用品"
"台灣電商 momo購物網 2026年熱銷商品趨勢 消費者行為 美妝保養 家電 生活用品"
),
"holiday_calendar": (
"2025年台灣重要節日促銷行事曆 母親節 618購物節 雙11 雙12 中秋 跨年 電商大促"
"2026年台灣重要節日促銷行事曆 母親節 618購物節 雙11 雙12 中秋 跨年 電商大促"
),
"seasonal_insights": (
"台灣電商季節性銷售趨勢 換季商品 夏季防曬 冬季保暖 Q3 Q4 消費高峰"
),
"competitor_intel": (
"momo購物網 PChome 蝦皮 Yahoo購物 2025年競爭策略 促銷活動 物流比較"
"momo購物網 PChome 蝦皮 Yahoo購物 2026年競爭策略 促銷活動 物流比較"
),
"consumer_sentiment": (
"台灣消費者 2025 購物偏好 低價高CP 品牌忠誠度 直播購物 社群電商 KOL影響"
"台灣消費者 2026 購物偏好 低價高CP 品牌忠誠度 直播購物 社群電商 KOL影響"
),
"pricing_strategy": (
"台灣電商定價策略 動態定價 競品比價 心理定價 促銷折扣最佳時機"
@@ -178,33 +178,39 @@ class MCPCollectorService:
"""取得節日行事曆(供 Prompt 注入)"""
now = datetime.now()
month = now.month
day = now.day
# 靜態台灣電商節日知識庫(無需 API 呼叫)
# 靜態台灣電商節日知識庫
static_calendar = {
1: "元旦促銷、農曆新年備貨期1/20前後開始",
2: "農曆新年(年貨、禮盒熱賣)、情人節2/14,保養/禮品衝量",
3: "婦女節3/8春季換季保養、開學季",
4: "清明連假、春季大促、換季服飾高峰",
5: "母親節5/2週前後美妝/保健/家電最高峰、520情人節",
6: "618購物節最大中年促銷,全平台衝量)、父親節備檔",
7: "父親節7/4週前後、暑假家電/3C/旅遊用品高峰",
8: "七夕情人節8/10前後、暑假尾聲出清",
9: "中秋節(禮盒/食品衝量、開學季3C/文具",
10: "雙10國慶、品牌週年慶(百貨、電商 10月旺季",
11: "雙11光棍節全年最大促銷)、品牌大促備貨",
12: "雙12年終慶、聖誕節12/25、跨年元旦備貨",
1: "元旦促銷、農曆新年備貨期",
2: "農曆新年、情人節2/14",
3: "婦女節3/8、開學季",
4: "清明連假4月初、春季大促、換季服飾高峰",
5: "母親節5月第2週年度大促、520情人節、勞動節5/1",
6: "618購物節年中最大促銷)、端午節",
7: "暑假開端、父親節前哨站",
8: "父親節8/8七夕情人節",
9: "中秋節、開學季、百貨週年慶預熱",
10: "雙10國慶、百貨週年慶高峰期",
11: "雙11光棍節全年最強電商季)、黑五大促",
12: "雙12年終慶、聖誕節、跨年備貨",
}
base = static_calendar.get(month, "")
# 加入下個月預告
current_focus = static_calendar.get(month, "")
next_month = (month % 12) + 1
next_base = static_calendar.get(next_month, "")
next_focus = static_calendar.get(next_month, "")
# 月底優化:若超過 20 號自動將焦點轉向「下月預告」避免產生如「4月底還在過清明節」的幻覺
if day > 20:
header = f"當前日期:{now.strftime('%Y/%m/%d')} (月底轉場期)"
body = f"本月即將結束,目前重點已轉向:{next_focus}"
footer = f"下月詳細預告:{next_focus}"
else:
header = f"當前日期:{now.strftime('%Y/%m/%d')}"
body = f"本月電商重點:{current_focus}"
footer = f"下月預告:{next_focus}"
return (
f"當前月份:{now.strftime('%Y年%m月')}\n"
f"本月電商重點:{base}\n"
f"下月預告:{next_base}"
)
return f"{header}\n{body}\n{footer}"
def get_seasonal_context(self) -> str:
"""季節性消費情境"""

View File

@@ -23,8 +23,8 @@ import os
import re
from datetime import datetime
from typing import Optional
import requests
from services.mcp_context_service import build_mcp_context
logger = logging.getLogger(__name__)
@@ -384,11 +384,15 @@ class NemotronDispatcher:
ensure_ascii=False,
)
# 注入 MCP 市場上下文
mcp_ctx = build_mcp_context()
messages = [
{
"role": "system",
"content": (
"你是台灣電商競價情報的行動派發器。"
f"當前市場背景 (MCP)\n{mcp_ctx}\n\n"
"根據 Hermes 分析師提供的威脅清單,決定對每支商品呼叫哪個工具。\n"
"路由鐵律(依序判斷,命中即停):\n"
"1. gap_pct < 5% 且 sales_delta < -30% → 非價格異常,呼叫 flag_for_human_review"