Spaces:
Running
Running
def chat_with_opan_ai_assistant(password, youtube_id, thread_id, trascript, user_message, chat_history, socratic_mode=False):
Browse files
app.py
CHANGED
@@ -1421,7 +1421,7 @@ def chat_with_groq(password, user_message, data, chat_history, socratic_mode=Fal
|
|
1421 |
# 返回聊天历史和空字符串清空输入框
|
1422 |
return "", chat_history
|
1423 |
|
1424 |
-
def chat_with_opan_ai_assistant(password, youtube_id, thread_id, trascript, user_message, chat_history, socratic_mode=False):
|
1425 |
verify_password(password)
|
1426 |
|
1427 |
# 先計算 user_message 是否超過 500 個字
|
@@ -1471,9 +1471,11 @@ def chat_with_opan_ai_assistant(password, youtube_id, thread_id, trascript, user
|
|
1471 |
trascript_text = json.dumps(trascript_json, ensure_ascii=False, indent=2)
|
1472 |
|
1473 |
instructions = f"""
|
|
|
|
|
1474 |
逐字稿資料:{trascript_text}
|
1475 |
-------------------------------------
|
1476 |
-
你是一個擅長資料分析跟影片教學的老師,user
|
1477 |
如果是影片類型,不用解釋逐字稿格式,直接回答學生問題
|
1478 |
socratic_mode = {socratic_mode}
|
1479 |
if socratic_mode is True,
|
@@ -1494,6 +1496,7 @@ def chat_with_opan_ai_assistant(password, youtube_id, thread_id, trascript, user
|
|
1494 |
請一定要用繁體中文回答 zh-TW,並用台灣人的口語表達
|
1495 |
回答範圍一定要在逐字稿資料內,不要引用其他資料,請嚴格執行
|
1496 |
並在重複問句後給予學生鼓勵,讓學生有學習的動力
|
|
|
1497 |
"""
|
1498 |
|
1499 |
# 创建线程
|
@@ -1847,7 +1850,7 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
1847 |
# OPENAI 模式
|
1848 |
send_button.click(
|
1849 |
chat_with_opan_ai_assistant,
|
1850 |
-
inputs=[password, video_id, thread_id, df_string_output, msg, chatbot, socratic_mode_btn],
|
1851 |
outputs=[msg, chatbot, thread_id]
|
1852 |
)
|
1853 |
openai_chatbot_audio_input.change(
|
@@ -1869,19 +1872,20 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
1869 |
)
|
1870 |
|
1871 |
# 连接按钮点击事件
|
|
|
1872 |
btn_1.click(
|
1873 |
chat_with_opan_ai_assistant,
|
1874 |
-
inputs=
|
1875 |
outputs=[msg, chatbot, thread_id]
|
1876 |
)
|
1877 |
btn_2.click(
|
1878 |
chat_with_opan_ai_assistant,
|
1879 |
-
inputs=
|
1880 |
outputs=[msg, chatbot, thread_id]
|
1881 |
)
|
1882 |
btn_3.click(
|
1883 |
chat_with_opan_ai_assistant,
|
1884 |
-
inputs=
|
1885 |
outputs=[msg, chatbot, thread_id]
|
1886 |
)
|
1887 |
|
|
|
1421 |
# 返回聊天历史和空字符串清空输入框
|
1422 |
return "", chat_history
|
1423 |
|
1424 |
+
def chat_with_opan_ai_assistant(password, youtube_id, thread_id, trascript, user_message, chat_history, content_subject, content_grade, socratic_mode=False):
|
1425 |
verify_password(password)
|
1426 |
|
1427 |
# 先計算 user_message 是否超過 500 個字
|
|
|
1471 |
trascript_text = json.dumps(trascript_json, ensure_ascii=False, indent=2)
|
1472 |
|
1473 |
instructions = f"""
|
1474 |
+
科目:{content_subject}
|
1475 |
+
年級:{content_grade}
|
1476 |
逐字稿資料:{trascript_text}
|
1477 |
-------------------------------------
|
1478 |
+
你是一個擅長資料分析跟影片教學的老師, user 為{content_grade}的學生
|
1479 |
如果是影片類型,不用解釋逐字稿格式,直接回答學生問題
|
1480 |
socratic_mode = {socratic_mode}
|
1481 |
if socratic_mode is True,
|
|
|
1496 |
請一定要用繁體中文回答 zh-TW,並用台灣人的口語表達
|
1497 |
回答範圍一定要在逐字稿資料內,不要引用其他資料,請嚴格執行
|
1498 |
並在重複問句後給予學生鼓勵,讓學生有學習的動力
|
1499 |
+
請用 {content_grade} 的學生能懂的方式回答
|
1500 |
"""
|
1501 |
|
1502 |
# 创建线程
|
|
|
1850 |
# OPENAI 模式
|
1851 |
send_button.click(
|
1852 |
chat_with_opan_ai_assistant,
|
1853 |
+
inputs=[password, video_id, thread_id, df_string_output, msg, chatbot, content_subject, content_grade, socratic_mode_btn],
|
1854 |
outputs=[msg, chatbot, thread_id]
|
1855 |
)
|
1856 |
openai_chatbot_audio_input.change(
|
|
|
1872 |
)
|
1873 |
|
1874 |
# 连接按钮点击事件
|
1875 |
+
chat_with_opan_ai_assistant_input =[password, video_id, thread_id, df_string_output, btn_1, chatbot, content_subject, content_grade, socratic_mode_btn]
|
1876 |
btn_1.click(
|
1877 |
chat_with_opan_ai_assistant,
|
1878 |
+
inputs=chat_with_opan_ai_assistant_input,
|
1879 |
outputs=[msg, chatbot, thread_id]
|
1880 |
)
|
1881 |
btn_2.click(
|
1882 |
chat_with_opan_ai_assistant,
|
1883 |
+
inputs=chat_with_opan_ai_assistant_input,
|
1884 |
outputs=[msg, chatbot, thread_id]
|
1885 |
)
|
1886 |
btn_3.click(
|
1887 |
chat_with_opan_ai_assistant,
|
1888 |
+
inputs=chat_with_opan_ai_assistant_input,
|
1889 |
outputs=[msg, chatbot, thread_id]
|
1890 |
)
|
1891 |
|