一樣沒想法,所以今天乾脆來加強之前的dc機器人,不然他只能用天氣跟地震有點爛,但由於我目前懶得再去找api了,所以這邊乾脆讓他mcp server有的功能就呼叫mcp,沒有就上網查。
先在之前的discord trigger後面新增一個gemini跟code還有一個if node,在第一個gemini node中的prompt這樣寫
{
{
"contents": [
{
"role": "system",
"parts": [
{
"text": "你是一個訊息分類助理,專門判斷使用者訊息應該呼叫的工具。請只輸出 JSON,不要任何文字或程式碼區塊。格式如下:\n{\n \"tool\": \"weather\" | \"earthquake\" | \"other\",\n \"location\": <地點名稱或null>\n}\n\n分類規則:\n1. 訊息中包含「天氣」、「氣溫」、「下雨」、「晴天」、「降雨」、「颱風」、「氣象」等字眼,即使是短句,也視為 tool = \"weather\"。\n2. 訊息中包含「地震」、「震度」、「安全」、「災害」等字眼,即使是短句,也視為 tool = \"earthquake\"。\n3. 其他情況視為 tool = \"other\"。\n\n請務必遵守規則,輸出只有 JSON。"
}
]
},
{
"role": "user",
"parts": [
{
"text": "{{ $json.content }}"
}
]
}
],
"generationConfig": {
"temperature": 0,
"maxOutputTokens": 150
}
}
在code node中放置
const raw = $json["content"]["parts"][0]["text"];
const clean = raw.replace(/```json\s*|```/g, '');
const parsed = JSON.parse(clean);
return { json: parsed };
最後在IF node中放置
{{ $json.tool }}
is equal to
"weather"
OR
{{ $json.tool }}
is equal to
"earthquake"
這樣
最後將true接再原本的ai agent,false直接接gemini,然後再原本的ai agent中把原本的json.context改成{{ $('Discord Trigger').item.json.content }},gemini那邊則是直接放{{ $('Discord Trigger').item.json.content }}
最後加一個SENT discord