File tree Expand file tree Collapse file tree
linebot/app/services/handlers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,12 +25,20 @@ def handle_image_message(event):
2525 temp_image_file .write (chunk )
2626
2727 # 使用 vision 函式處理圖片
28- response = process_image (
29- temp_file_path , "圖片內容有什麼? "
30- ) # TODO: 設定圖片處理的 prompt
28+ response_image_text = process_image (
29+ temp_file_path , "請分析圖片內容有什麼,並且提醒使用者,這個功能是實驗性質的,可能會有錯誤或不準確的情況,不會套用到 Dify API 中,所以單純只是分析圖片內容而已。如果覺得有趣我們可以更新這一部分!不要使用 markdown 語法,可以用表情符號 "
30+ )
3131 # 刪除臨時檔案
3232 os .remove (temp_file_path )
33- return [TextSendMessage (text = response , quick_reply = create_quick_reply ())]
33+ if not response_image_text :
34+ return [
35+ TextSendMessage (
36+ text = "抱歉,無法處理圖片內容,我好像壞掉了" ,
37+ quick_reply = create_quick_reply (),
38+ )
39+ ]
40+ # 使用 Dify API 進行推論
41+ return [TextSendMessage (text = response_image_text , quick_reply = create_quick_reply ())]
3442 except Exception as e :
3543 logger .error (f"處理圖片訊息時發生錯誤: { str (e )} " , exc_info = True )
3644 return [
You can’t perform that action at this time.
0 commit comments