iT邦幫忙

2024 iThome 鐵人賽

0

為什麼需要 function calling 前面章節有講過,這裡就不贅述了 直接看實作的步驟
https://ithelp.ithome.com.tw/upload/images/20240903/20046160LzMwlxcthh.png

步驟

https://ithelp.ithome.com.tw/upload/images/20240903/20046160RCwjUYH0yl.png

  1. 直接拉到最下面有一個functions 的地方
  2. 點 +Functions
    https://ithelp.ithome.com.tw/upload/images/20240903/20046160XMGpiGjgFa.png
  3. 要你填入定義 function 的 Definition
  4. 左邊有一些參考,可以看
  5. 大概就是要告訴有哪些參數需要輸入?
  6. 如果不太會寫的話,同樣也可以請 LLMs 幫你寫
參考以下的資料結構
{
  "name": "get_weather",
  "description": "Determine weather in my location",
  "strict": true,
  "parameters": {
    "type": "object",
    "properties": {
      "location": {
        "type": "string",
        "description": "The city and state e.g. San Francisco, CA"
      },
      "unit": {
        "type": "string",
        "enum": [
          "c",
          "f"
        ]
      }
    },
    "additionalProperties": false,
    "required": [
      "location",
      "unit"
    ]
  }
}
  1. 試一試

https://ithelp.ithome.com.tw/upload/images/20240903/200461606zIMoOwkhE.png

問題

https://ithelp.ithome.com.tw/upload/images/20240903/20046160KwfHGRcC0D.png

在這裡你可以看到,LLMs 在识别到地點时,会自动呼叫天氣資訊。

要避免這個問題,關鍵在於正確設定 instructions。

https://ithelp.ithome.com.tw/upload/images/20240903/20046160v2xHg2vbPT.png
我只是在 instructions 加了

Functions
- get_weather : used to call weather information

就可以避免 Assistant API 無腦去呼叫 get_weather

不過這個問題好像只存在 gpt-3.5-trubo

gpt-4 以後 似乎比較不會 OK觸發這個問題

關於我

我是 Wolke。我是一名專業程式開發者,專長是開發 AI 和程式解決方案。

我投入了不少時間在專業發展上。我是多本書的作者,其中包括《LINE聊天機器人+AI+雲端+開源+程式:輕鬆入門到完整學習》《ChatGPT來襲,未來人人都需具備的運算思維!應用詠唱工程來釋放程式生產力—程式學習/開發篇》。也有出版線上課程,我熱衷於分享我的經驗和技術,幫助其他開發者更好地利用 AI 工具。

也在許多知名大學、論壇、社團擔任講者,如果貴方有需要也歡迎與我聯繫。
2023年 講座 紀錄

最後這篇文章若有切合你的需求,敬請訂閱按讚分享


上一篇
9-3 Assistant API RAG 向量資料庫訓練
下一篇
12-1 人人都要會寫的 Backend 解決方案——以 GAS 和 Google Sheets 為例
系列文
運用生成式 AI 服務 所提供的API 實做應用開發(以Gemini及ChatGPT為例)42
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言