Spaces:
Running
Running
def update_send_and_feedback_buttons(chat_history, chat_limit):
Browse files
app.py
CHANGED
@@ -2251,17 +2251,9 @@ def chat_with_opan_ai_assistant(password, youtube_id, user_data, thread_id, tras
|
|
2251 |
|
2252 |
# 等待 3 秒
|
2253 |
time.sleep(3)
|
2254 |
-
|
2255 |
-
if len(chat_history) > CHAT_LIMIT:
|
2256 |
-
send_btn_value = f"對話已達上限 ({send_count}/{CHAT_LIMIT})"
|
2257 |
-
send_btn = gr.update(value=send_btn_value, interactive=False)
|
2258 |
-
send_feedback_btn_update = gr.update(visible=True)
|
2259 |
-
else:
|
2260 |
-
send_btn_value = f"發送 ({send_count}/{CHAT_LIMIT})"
|
2261 |
-
send_btn = gr.update(value=send_btn_value, interactive=True)
|
2262 |
-
send_feedback_btn_update = send_feedback_btn
|
2263 |
|
2264 |
-
return "", chat_history, thread_id,
|
2265 |
|
2266 |
|
2267 |
# 如果 chat_history 超過 10 則訊息,直接 return "對話超過上限"
|
@@ -2356,19 +2348,11 @@ def chat_with_opan_ai_assistant(password, youtube_id, user_data, thread_id, tras
|
|
2356 |
print(f"Error: {e}")
|
2357 |
raise gr.Error(f"Error: {e}")
|
2358 |
|
2359 |
-
|
2360 |
-
if len(chat_history) > CHAT_LIMIT:
|
2361 |
-
send_btn_value = f"對話已達上限 ({send_count}/{CHAT_LIMIT})"
|
2362 |
-
send_btn = gr.update(value=send_btn_value, interactive=False)
|
2363 |
-
send_feedback_btn_update = gr.update(visible=True)
|
2364 |
-
else:
|
2365 |
-
send_btn_value = f"發送 ({send_count}/{CHAT_LIMIT})"
|
2366 |
-
send_btn = gr.update(value=send_btn_value, interactive=True)
|
2367 |
-
send_feedback_btn_update = send_feedback_btn
|
2368 |
|
2369 |
|
2370 |
# 返回聊天历史和空字符串清空输入框
|
2371 |
-
return "", chat_history, thread.id,
|
2372 |
|
2373 |
def feedback_with_opan_ai_assistant(thread_id, chat_history):
|
2374 |
# prompt: 請依據以上的對話(chat_history),總結我的「提問力」,並給予我是否有「問對問題」的回饋和建議
|
@@ -2376,8 +2360,8 @@ def feedback_with_opan_ai_assistant(thread_id, chat_history):
|
|
2376 |
你是一個擅長引導問答素養的老師,user 為學生的提問跟回答,請精讀對話過程,針對 user 給予回饋就好,根據以下 Rule:
|
2377 |
- 請使用繁體中文 zh-TW 總結 user 的提問力,並給予是否有問對問題的回饋和建議
|
2378 |
- 不採計【預設提問】的問題,如果 user 的提問都來自【預設提問】,表達用戶善於使用系統,請給予回饋並鼓勵 user 親自提問更具體的問題
|
2379 |
-
-
|
2380 |
-
-
|
2381 |
- 如果用戶提問內容有色情、暴力、仇恨、不當言論等,請給予嚴厲的回饋並建議 user 提問更具體的問題
|
2382 |
- 並用第二人稱「你」來代表 user
|
2383 |
- 請禮貌,並給予鼓勵
|
@@ -2464,6 +2448,22 @@ def feedback_with_opan_ai_assistant(thread_id, chat_history):
|
|
2464 |
|
2465 |
return chat_history, feedback_btn_update
|
2466 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2467 |
def process_open_ai_audio_to_chatbot(password, audio_url):
|
2468 |
verify_password(password)
|
2469 |
if audio_url:
|
|
|
2251 |
|
2252 |
# 等待 3 秒
|
2253 |
time.sleep(3)
|
2254 |
+
send_btn_update, send_feedback_btn_update = update_send_and_feedback_buttons(chat_history, CHAT_LIMIT)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2255 |
|
2256 |
+
return "", chat_history, thread_id, send_btn_update, send_feedback_btn_update
|
2257 |
|
2258 |
|
2259 |
# 如果 chat_history 超過 10 則訊息,直接 return "對話超過上限"
|
|
|
2348 |
print(f"Error: {e}")
|
2349 |
raise gr.Error(f"Error: {e}")
|
2350 |
|
2351 |
+
send_btn_update, send_feedback_btn_update = update_send_and_feedback_buttons(chat_history, CHAT_LIMIT)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2352 |
|
2353 |
|
2354 |
# 返回聊天历史和空字符串清空输入框
|
2355 |
+
return "", chat_history, thread.id, send_btn_update, send_feedback_btn_update
|
2356 |
|
2357 |
def feedback_with_opan_ai_assistant(thread_id, chat_history):
|
2358 |
# prompt: 請依據以上的對話(chat_history),總結我的「提問力」,並給予我是否有「問對問題」的回饋和建議
|
|
|
2360 |
你是一個擅長引導問答素養的老師,user 為學生的提問跟回答,請精讀對話過程,針對 user 給予回饋就好,根據以下 Rule:
|
2361 |
- 請使用繁體中文 zh-TW 總結 user 的提問力,並給予是否有問對問題的回饋和建議
|
2362 |
- 不採計【預設提問】的問題,如果 user 的提問都來自【預設提問】,表達用戶善於使用系統,請給予回饋並鼓勵 user 親自提問更具體的問題
|
2363 |
+
- 如果用戶提問都相當簡短,甚至就是一個字或都是一個數字(像是 user: 1, user:2),請給予回饋並建議 user 提問更具體的問題
|
2364 |
+
- 如果用戶提問內容只有符號或是亂碼,像是?,!, ..., 3bhwbqhfw2vve2 等,請給予回饋並建議 user 提問更具體的問題
|
2365 |
- 如果用戶提問內容有色情、暴力、仇恨、不當言論等,請給予嚴厲的回饋並建議 user 提問更具體的問題
|
2366 |
- 並用第二人稱「你」來代表 user
|
2367 |
- 請禮貌,並給予鼓勵
|
|
|
2448 |
|
2449 |
return chat_history, feedback_btn_update
|
2450 |
|
2451 |
+
def update_send_and_feedback_buttons(chat_history, chat_limit):
|
2452 |
+
# 计算发送次数
|
2453 |
+
send_count = len(chat_history) - 1
|
2454 |
+
|
2455 |
+
# 根据聊天历史长度更新发送按钮和反馈按钮
|
2456 |
+
if len(chat_history) > chat_limit:
|
2457 |
+
send_btn_value = f"對話上限 ({send_count}/{chat_limit})"
|
2458 |
+
send_btn_update = gr.update(value=send_btn_value, interactive=False)
|
2459 |
+
send_feedback_btn_update = gr.update(visible=True)
|
2460 |
+
else:
|
2461 |
+
send_btn_value = f"發送 ({send_count}/{chat_limit})"
|
2462 |
+
send_btn_update = gr.update(value=send_btn_value, interactive=True)
|
2463 |
+
send_feedback_btn_update = gr.update(visible=False)
|
2464 |
+
|
2465 |
+
return send_btn_update, send_feedback_btn_update
|
2466 |
+
|
2467 |
def process_open_ai_audio_to_chatbot(password, audio_url):
|
2468 |
verify_password(password)
|
2469 |
if audio_url:
|