Closed ShiuanTHC closed 1 month ago
@ShiuanTHC 這樣是你要的效果嗎?
if status_code == 500
我直接把 API 拿到的 Response 顯示回畫面上!
# output format: preview_subject_title, preview_summerized_ticket_content, summerized_ticket_content, token_usage, token_cost
if response.status_code == 200:
data: dict = json.loads(response.text)
elif response.status_code == 400:
response.text
return (
f"<h1>Error: {response.text}</h1>",
"Maybe User input is empty or invalid.",
"Maybe User input is empty or invalid.",
"💰 Token Cost: NULL", "🔒 Token Usage: NULL"
)
elif response.status_code == 500:
response.text
return (
f"<h1>Error: {response.text}</h1>",
"The number of placeholders does not match the number of URLs. or prompt_file not found or Ran out of URLs in the queue before replacing all placeholders. or others",
"The number of placeholders does not match the number of URLs. or prompt_file not found or Ran out of URLs in the queue before replacing all placeholders. or others",
"💰 Token Cost: NULL", "🔒 Token Usage: NULL"
)
else:
return (
"<h1>Error: Something went wrong with the API</h1>",
"We meet error when we call the API",
"We meet error when we call the API",
"💰 Token Cost: NULL", "🔒 Token Usage: NULL"
)
因為我 body 分別會 return 不同的 error message,你可以直接讀 body 裡的內容並顯示出來嗎? 還有我記得原生的 error 好像會更明顯,會有彈窗效果,這部分可能要明天面對面討論比較清除,我預期的效果是有個彈窗效果顯示 error message 。
@ShiuanTHC 原來,原本的彈窗效果是因為我的 Code return 的數量跟預期的不一樣,我可以研究一下彈窗效果,畫面上的內容我也可以直接顯示 Error 訊息就好!那我就顯示在 Subject
的欄位,另外彈窗效果要再研究一下!
好,感謝! 麻煩你了,我要去考按摩了哈哈哈
OK!
@ShiuanTHC 我看官方文件好像這樣加就好了!不過我這邊不知道要怎麼觸發 Error。
if response.status_code == 200:
data: dict = json.loads(response.text)
elif response.status_code == 400:
raise gr.Error(f"Error: {response.text}")
elif response.status_code == 500:
raise gr.Error(f"Error: {response.text}")
else:
raise gr.Error(f"Error: {response.text}")```
好~我看 commit 好像現在還沒有上到 dev 分支 那我明天再去試試效果
因為我還沒 commit 明天一起看成果,同時需要一起做一些假的 Data 測試!
https://github.com/TODAM-tw/todam-ticket-system/blob/a136a489bf37f4ee755cb2ca281a7d418c95c401/app/cases/ticket_summarized.py#L55-L59
Status Code == 400 -> input 格式有誤
Status Code == 500 -> 佔位符數量和儲存網址的 queue 數量不同 (進 model 前)
Status Code == 500 -> 讀不到 prompt file
Status Code == 500 -> 儲存網址的 queue 的數量不夠 replace 佔位符數量 (出 model 後)
Status Code == 500 -> other error