iT邦幫忙

2025 iThome 鐵人賽

DAY 12
0

讓我們先來測試API能否使用
http://localhost:5678
https://ithelp.ithome.com.tw/upload/images/20250926/20177920JivY6pMDFN.png
開啟之後先把註冊的自己打一打,這邊唯一要注意的是密碼一定要記得,本地版的n8n代表著如果要找回你的密碼會有點麻煩,不像網頁版一樣直接在登入畫面按忘記密碼就可以快速找回密碼,這個部分說不定之後會講

總之讓我們快速進行下一步,註冊完、回答他的問卷調查後會看到這個畫面
https://ithelp.ithome.com.tw/upload/images/20250926/20177920xUpE1e4ssz.png
這邊這個是可用可不用的,反正對本地版沒影響

回到首頁,點擊Start from scratch
https://ithelp.ithome.com.tw/upload/images/20250926/20177920xYHTeKl31P.pnghttps://ithelp.ithome.com.tw/upload/images/20250926/20177920kFRcIdeHR6.png
點擊正中間那個add first step後會看到右邊彈出一堆選項,選擇on schedule
https://ithelp.ithome.com.tw/upload/images/20250926/20177920nIOHhPJQVr.png
左半部上至下分別是
Trigger Interval 時間單位(秒、分、時、天、周、月)
Days Between Triggers 每幾個時間單位執行 ex每一天
Trigger at Hour 幾點
Trigger at MInute 幾分
像這樣就是每天的早上八點整執行
https://ithelp.ithome.com.tw/upload/images/20250926/20177920bBHdn9KgUD.png
設定完成後點擊空白處退出該畫面
點擊右方的加號
https://ithelp.ithome.com.tw/upload/images/20250926/20177920pbGgiK3HeB.png
搜尋HTTP選擇HTTP REQUEST,將Send Headers跟Send Body打開,如果位置不夠就add,這邊body給我們所在的城市及想要的資訊,像是溫度之類的
輸入
https://ithelp.ithome.com.tw/upload/images/20250926/201779206Q0g6Lksc8.pnghttps://ithelp.ithome.com.tw/upload/images/20250926/20177920m727oG47gf.png
他的輸出會發現我們根本看不懂,所以後面在加個ai來幫我們解釋
繼續選擇右邊加號,選擇ai
https://ithelp.ithome.com.tw/upload/images/20250926/20177920WLWs9XS70A.png
選擇gemini後,在action中找到text action
https://ithelp.ithome.com.tw/upload/images/20250926/20177920AjTdIrM228.png
看到這個畫面,先選最上方的Credential to connect with,這邊要放自己的gemini api key
https://ithelp.ithome.com.tw/upload/images/20250926/20177920UVagPvQKcZ.png
把中間的填上去,其他不用管
https://ithelp.ithome.com.tw/upload/images/20250926/20177920yoJ2YmSmya.png
model隨意選,筆者選擇最常用的2.5flash
https://ithelp.ithome.com.tw/upload/images/20250926/20177920SjYVFh5uaF.png
prompt的部分,看向左方input中有一個Schema,點擊它,這些就是給的資料的變數名稱,在對話時把你要求的拖曳進去就好了
https://ithelp.ithome.com.tw/upload/images/20250926/20177920X6QjXzZgBl.png
這邊給我使用的

{
  "contents": [
    {
      "role": "system",
      "parts": [
        {
          "text": "你是氣象助理,會幫使用者整理天氣資訊並給穿衣或活動建議。"
        }
      ]
    },
    {
      "role": "user",
      "parts": [
        {
          "text": "請根據以下天氣資料,整理成 Gmail 郵件可直接使用的 HTML 格式,包含穿衣與活動建議:\n\n地點:{{ $json.data.Locations[0].Location[19].LocationName }}\n日期:{{ $json.data.Locations[0].Location[19].WeatherElement[0].Time[0].StartTime }}\n項目:{{ $json.data.Locations[0].Location[19].WeatherElement[0].ElementName }}\n數值:{{ $json.data.Locations[0].Location[19].WeatherElement[0].Time[0].ElementValue[0].Temperature }}°C"
        }
      ]
    }
  ],
  "temperature": 0.7,
  "maxOutputTokens": 300
}


contects:Gemini API 的規定欄位,用來放 prompt 內容
role:
system ; 給系統的格式要求
user :「使用者」的輸入,Gemini 會把它當成 prompt 來生成回答
parts: 裡面每個 item 都是一段文字,用來支援複數段文字的訊息
好了之後點擊右上方的execute step來測試,有問題就在prompt那邊自己修改
temperature:ai的創意性0~1,越低越死板
maxOutPutTokens:回答最高字

這樣如果有出現output就代表完成了,讓我們明天再讓它可以傳gmail給我們吧


上一篇
d11
下一篇
d13 在n8n中使用Gmail寄信
系列文
這是一個一個一個 Python API 與 Gemini 整合、n8n入門指南14
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言