Spaces:
Running
Running
socratic_mode_btn
Browse files
app.py
CHANGED
@@ -2074,17 +2074,22 @@ def download_exam_result(content):
|
|
2074 |
return word_path
|
2075 |
|
2076 |
# ---- Chatbot ----
|
2077 |
-
def get_instructions(content_subject, content_grade, key_moments):
|
|
|
|
|
|
|
|
|
|
|
2078 |
instructions = f"""
|
2079 |
subject: {content_subject}
|
2080 |
grade: {content_grade}
|
2081 |
context: {key_moments}
|
2082 |
Assistant Role: you are a {content_subject} assistant. you can call yourself as {content_subject} 學伴
|
2083 |
User Role: {content_grade} th-grade student.
|
2084 |
-
Method:
|
2085 |
Language: Traditional Chinese ZH-TW (it's very important), suitable for {content_grade} th-grade level.
|
2086 |
Response:
|
2087 |
-
- if user say hi or hello or any greeting, just say hi back and introduce yourself. Then
|
2088 |
- Single question, under 100 characters
|
2089 |
- include math symbols (use LaTeX $ to cover before and after, ex: $x^2$)
|
2090 |
- hint with video timestamp which format 【參考:00:00:00】.
|
@@ -2185,7 +2190,7 @@ def chat_with_ai(ai_name, password, video_id, user_data, trascript_state, key_mo
|
|
2185 |
moment.pop('transcript', None)
|
2186 |
key_moments_text = json.dumps(key_moments_json, ensure_ascii=False)
|
2187 |
|
2188 |
-
instructions = get_instructions(content_subject, content_grade, key_moments_text)
|
2189 |
|
2190 |
chatbot_config = {
|
2191 |
"video_id": video_id,
|
@@ -2258,7 +2263,7 @@ def chat_with_opan_ai_assistant(password, youtube_id, user_data, thread_id, tras
|
|
2258 |
moment.pop('end', None)
|
2259 |
moment.pop('transcript', None)
|
2260 |
key_moments_text = json.dumps(key_moments_json, ensure_ascii=False)
|
2261 |
-
instructions = get_instructions(content_subject, content_grade, key_moments_text)
|
2262 |
print(f"=== instructions:{instructions} ===")
|
2263 |
metadata={
|
2264 |
"video_id": youtube_id,
|
@@ -2534,7 +2539,7 @@ def poll_run_status(run_id, thread_id, timeout=600, poll_interval=5):
|
|
2534 |
|
2535 |
return run.status
|
2536 |
|
2537 |
-
def chat_with_opan_ai_assistant_streaming(user_message, chat_history, password, video_id, user_data, thread_id, trascript, key_moments, content_subject, content_grade):
|
2538 |
verify_password(password)
|
2539 |
|
2540 |
print("=====user_data=====")
|
@@ -2578,7 +2583,7 @@ def chat_with_opan_ai_assistant_streaming(user_message, chat_history, password,
|
|
2578 |
moment.pop('transcript', None)
|
2579 |
key_moments_text = json.dumps(key_moments_json, ensure_ascii=False)
|
2580 |
|
2581 |
-
instructions = get_instructions(content_subject, content_grade, key_moments_text)
|
2582 |
# 创建线程
|
2583 |
if not thread_id:
|
2584 |
thread = client.beta.threads.create()
|
@@ -2711,6 +2716,9 @@ def init_params(text, request: gr.Request):
|
|
2711 |
chatbot_open_ai = gr.update(visible=False)
|
2712 |
chatbot_open_ai_streaming = gr.update(visible=False)
|
2713 |
chatbot_jutor = gr.update(visible=False)
|
|
|
|
|
|
|
2714 |
|
2715 |
# if youtube_link in query_params
|
2716 |
if "youtube_id" in request.query_params:
|
@@ -2729,11 +2737,15 @@ def init_params(text, request: gr.Request):
|
|
2729 |
worksheet_accordion = gr.update(visible=False)
|
2730 |
lesson_plan_accordion = gr.update(visible=False)
|
2731 |
exit_ticket_accordion = gr.update(visible=False)
|
|
|
|
|
|
|
2732 |
|
2733 |
return admin, reading_passage_admin, summary_admin, see_detail, \
|
2734 |
worksheet_accordion, lesson_plan_accordion, exit_ticket_accordion, \
|
2735 |
password_text, youtube_link, \
|
2736 |
-
chatbot_open_ai, chatbot_open_ai_streaming, chatbot_jutor
|
|
|
2737 |
|
2738 |
def update_state(content_subject, content_grade, trascript, key_moments, questions_answers):
|
2739 |
# inputs=[content_subject, content_grade, df_string_output],
|
@@ -2918,13 +2930,14 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
2918 |
send_feedback_btn = gr.Button("提問力回饋", variant="primary", scale=1, visible=False)
|
2919 |
with gr.Row("飛特音速") as chatbot_open_ai_streaming:
|
2920 |
with gr.Column():
|
|
|
2921 |
streaming_chat_greeting = """
|
2922 |
Hi,我是【飛特音速】,說話比較快,但有什麼問題都可以問我喔! \n
|
2923 |
🚀 我沒有預設問題、也沒有語音輸入,適合快問快答的你 \n
|
2924 |
🔠 鍵盤輸入你的問題,我會盡力回答你的問題喔!\n
|
2925 |
💤 我還在成長,體力有限,每一次學習只能回答十個問題,請讓我休息一下再問問題喔!
|
2926 |
"""
|
2927 |
-
additional_inputs = [password, video_id, user_data, streaming_chat_thread_id_state, trascript_state, key_moments_state, content_subject_state, content_grade_state]
|
2928 |
streaming_chat = gr.ChatInterface(
|
2929 |
fn=chat_with_opan_ai_assistant_streaming,
|
2930 |
additional_inputs=additional_inputs,
|
@@ -3637,7 +3650,9 @@ with gr.Blocks(theme=gr.themes.Base(primary_hue=gr.themes.colors.orange, seconda
|
|
3637 |
youtube_link,
|
3638 |
chatbot_open_ai,
|
3639 |
chatbot_open_ai_streaming,
|
3640 |
-
chatbot_jutor
|
|
|
|
|
3641 |
]
|
3642 |
demo.load(
|
3643 |
init_params,
|
|
|
2074 |
return word_path
|
2075 |
|
2076 |
# ---- Chatbot ----
|
2077 |
+
def get_instructions(content_subject, content_grade, key_moments, socratic_mode=True):
|
2078 |
+
if socratic_mode:
|
2079 |
+
method = "Socratic style, guide thinking, no direct answers. this is very important, please be seriously following."
|
2080 |
+
else:
|
2081 |
+
method = "direct answers, but encourage user to think more."
|
2082 |
+
|
2083 |
instructions = f"""
|
2084 |
subject: {content_subject}
|
2085 |
grade: {content_grade}
|
2086 |
context: {key_moments}
|
2087 |
Assistant Role: you are a {content_subject} assistant. you can call yourself as {content_subject} 學伴
|
2088 |
User Role: {content_grade} th-grade student.
|
2089 |
+
Method: {method}
|
2090 |
Language: Traditional Chinese ZH-TW (it's very important), suitable for {content_grade} th-grade level.
|
2091 |
Response:
|
2092 |
+
- if user say hi or hello or any greeting, just say hi back and introduce yourself. Then tell user to ask question in context.
|
2093 |
- Single question, under 100 characters
|
2094 |
- include math symbols (use LaTeX $ to cover before and after, ex: $x^2$)
|
2095 |
- hint with video timestamp which format 【參考:00:00:00】.
|
|
|
2190 |
moment.pop('transcript', None)
|
2191 |
key_moments_text = json.dumps(key_moments_json, ensure_ascii=False)
|
2192 |
|
2193 |
+
instructions = get_instructions(content_subject, content_grade, key_moments_text, socratic_mode)
|
2194 |
|
2195 |
chatbot_config = {
|
2196 |
"video_id": video_id,
|
|
|
2263 |
moment.pop('end', None)
|
2264 |
moment.pop('transcript', None)
|
2265 |
key_moments_text = json.dumps(key_moments_json, ensure_ascii=False)
|
2266 |
+
instructions = get_instructions(content_subject, content_grade, key_moments_text, socratic_mode)
|
2267 |
print(f"=== instructions:{instructions} ===")
|
2268 |
metadata={
|
2269 |
"video_id": youtube_id,
|
|
|
2539 |
|
2540 |
return run.status
|
2541 |
|
2542 |
+
def chat_with_opan_ai_assistant_streaming(user_message, chat_history, password, video_id, user_data, thread_id, trascript, key_moments, content_subject, content_grade, socratic_mode=True):
|
2543 |
verify_password(password)
|
2544 |
|
2545 |
print("=====user_data=====")
|
|
|
2583 |
moment.pop('transcript', None)
|
2584 |
key_moments_text = json.dumps(key_moments_json, ensure_ascii=False)
|
2585 |
|
2586 |
+
instructions = get_instructions(content_subject, content_grade, key_moments_text, socratic_mode)
|
2587 |
# 创建线程
|
2588 |
if not thread_id:
|
2589 |
thread = client.beta.threads.create()
|
|
|
2716 |
chatbot_open_ai = gr.update(visible=False)
|
2717 |
chatbot_open_ai_streaming = gr.update(visible=False)
|
2718 |
chatbot_jutor = gr.update(visible=False)
|
2719 |
+
socratic_mode_btn = gr.update(visible=True)
|
2720 |
+
ai_chatbot_socratic_mode_btn = gr.update(visible=True)
|
2721 |
+
streaming_chat_socratic_mode_btn = gr.update(visible=True)
|
2722 |
|
2723 |
# if youtube_link in query_params
|
2724 |
if "youtube_id" in request.query_params:
|
|
|
2737 |
worksheet_accordion = gr.update(visible=False)
|
2738 |
lesson_plan_accordion = gr.update(visible=False)
|
2739 |
exit_ticket_accordion = gr.update(visible=False)
|
2740 |
+
socratic_mode_btn = gr.update(visible=False)
|
2741 |
+
ai_chatbot_socratic_mode_btn = gr.update(visible=False)
|
2742 |
+
streaming_chat_socratic_mode_btn = gr.update(visible=False)
|
2743 |
|
2744 |
return admin, reading_passage_admin, summary_admin, see_detail, \
|
2745 |
worksheet_accordion, lesson_plan_accordion, exit_ticket_accordion, \
|
2746 |
password_text, youtube_link, \
|
2747 |
+
chatbot_open_ai, chatbot_open_ai_streaming, chatbot_jutor, \
|
2748 |
+
socratic_mode_btn, ai_chatbot_socratic_mode_btn, streaming_chat_socratic_mode_btn
|
2749 |
|
2750 |
def update_state(content_subject, content_grade, trascript, key_moments, questions_answers):
|
2751 |
# inputs=[content_subject, content_grade, df_string_output],
|
|
|
2930 |
send_feedback_btn = gr.Button("提問力回饋", variant="primary", scale=1, visible=False)
|
2931 |
with gr.Row("飛特音速") as chatbot_open_ai_streaming:
|
2932 |
with gr.Column():
|
2933 |
+
streaming_chat_socratic_mode_btn = gr.Checkbox(label="蘇格拉底家教助理模式", value=True, visible=True)
|
2934 |
streaming_chat_greeting = """
|
2935 |
Hi,我是【飛特音速】,說話比較快,但有什麼問題都可以問我喔! \n
|
2936 |
🚀 我沒有預設問題、也沒有語音輸入,適合快問快答的你 \n
|
2937 |
🔠 鍵盤輸入你的問題,我會盡力回答你的問題喔!\n
|
2938 |
💤 我還在成長,體力有限,每一次學習只能回答十個問題,請讓我休息一下再問問題喔!
|
2939 |
"""
|
2940 |
+
additional_inputs = [password, video_id, user_data, streaming_chat_thread_id_state, trascript_state, key_moments_state, content_subject_state, content_grade_state, streaming_chat_socratic_mode_btn]
|
2941 |
streaming_chat = gr.ChatInterface(
|
2942 |
fn=chat_with_opan_ai_assistant_streaming,
|
2943 |
additional_inputs=additional_inputs,
|
|
|
3650 |
youtube_link,
|
3651 |
chatbot_open_ai,
|
3652 |
chatbot_open_ai_streaming,
|
3653 |
+
chatbot_jutor,
|
3654 |
+
socratic_mode_btn,
|
3655 |
+
ai_chatbot_socratic_mode_btn,
|
3656 |
]
|
3657 |
demo.load(
|
3658 |
init_params,
|