youngtsai commited on
Commit
475a393
·
1 Parent(s): a176369

instructions

Browse files
Files changed (2) hide show
  1. app.py +25 -50
  2. chatbot.py +7 -7
app.py CHANGED
@@ -1735,36 +1735,20 @@ def chat_with_opan_ai_assistant(password, youtube_id, thread_id, trascript_state
1735
  moment.pop('end', None)
1736
  moment.pop('text', None)
1737
  key_moments_text = json.dumps(key_moments_json, ensure_ascii=False)
1738
-
1739
- if len(trascript_text) > 25000:
1740
- content_text = key_moments_text
1741
- print("=== transcript_text is too long, replace by key_moments_text ===")
1742
- else:
1743
- content_text = trascript_text
1744
- print("=== transcript_text is used ===")
1745
-
1746
  instructions = f"""
1747
- 科目:{content_subject}
1748
- 年級:{content_grade}
1749
- 逐字稿資料:{content_text}
1750
- -------------------------------------
1751
- 你是一個專業的{content_subject}老師, user {content_grade}的學生
1752
- socratic_mode = {socratic_mode}
1753
- if socratic_mode is True,
1754
- - 請用蘇格拉底式的提問方式,引導學生思考,並且給予學生一些提示
1755
- - 一次只問一個問題,字數在100字以內
1756
- - 不要直接給予答案,讓學生自己思考
1757
- - 但可以給予一些提示跟引導,例如給予影片的時間軸,讓學生自己去找答案
1758
- rule:
1759
- - 請一定要用繁體中文回答 zh-TW,並用台灣人的口語表達,回答時不用特別說明這是台灣人的語氣,也不用說這是「台語的說法」
1760
- - 請用 {content_grade} 的學生能懂的方式回答,不用提到「逐字稿」這個詞
1761
- - 如果學生問了一些問題你無法判斷,請告訴學生你無法判斷,並建議學生可以問其他問題
1762
- - 或者你可以反問學生一些問題,幫助學生更好的理解資料,字數在100字以內
1763
- - 如果學生的問題與資料文本無關,請告訴學生你「無法回答超出影片範圍的問題」,並告訴他可以怎麼問什麼樣的問題(一個就好)
1764
- - 回答範圍一定要在逐字稿資料內,不要引用其他資料,請嚴格執行
1765
- - 並在重複問句後給予學生鼓勵,讓學生有學習的動力
1766
- - 回答時數學式請用數學符號代替文字(Latex 用 $ 字號 render)
1767
- - 只要是參考逐字稿資料,please use the timestamp format, example:【參考資料:00:00:00】
1768
  """
1769
 
1770
  print("=== instructions ===")
@@ -1940,27 +1924,18 @@ def streaming_chat_with_open_ai(user_message, chat_history, password, thread_id,
1940
  print("=== transcript_text is used ===")
1941
 
1942
  instructions = f"""
1943
- 科目:{content_subject}
1944
- 年級:{content_grade}
1945
- 逐字稿資料:{content_text}
1946
- -------------------------------------
1947
- 你是一個專業的{content_subject}老師, user {content_grade}的學生
1948
- socratic_mode = {socratic_mode}
1949
- if socratic_mode is True,
1950
- - 請用蘇格拉底式的提問方式,引導學生思考,並且給予學生一些提示
1951
- - 一次只問一個問題,字數在100字以內
1952
- - 不要直接給予答案,讓學生自己思考
1953
- - 但可以給予一些提示跟引導,例如給予影片的時間軸,讓學生自己去找答案
1954
- rule:
1955
- - 請一定要用繁體中文回答 zh-TW,並用台灣人的口語表達,回答時不用特別說明這是台灣人的語氣,也不用說這是「台語的說法」
1956
- - 請用 {content_grade} 的學生能懂的方式回答,不用提到「逐字稿」這個詞
1957
- - 如果學生問了一些問題你無法判斷,請告訴學生你無法判斷,並建議學生可以問其他問題
1958
- - 或者你可以反問學生一些問題,幫助學生更好的理解資料,字數在100字以內
1959
- - 如果學生的問題與資料文本無關,請告訴學生你「無法回答超出影片範圍的問題」,並告訴他可以怎麼問什麼樣的問題(一個就好)
1960
- - 回答範圍一定要在逐字稿資料內,不要引用其他資料,請嚴格執行
1961
- - 並在重複問句後給予學生鼓勵,讓學生有學習的動力
1962
- - 回答時數學式請用數學符號代替文字(Latex 用 $ 字號 render)
1963
- - 只要是參考逐字稿資料,please use the timestamp format, example:【參考資料:00:00:00】
1964
  """
1965
 
1966
  # 创建线程
 
1735
  moment.pop('end', None)
1736
  moment.pop('text', None)
1737
  key_moments_text = json.dumps(key_moments_json, ensure_ascii=False)
1738
+
 
 
 
 
 
 
 
1739
  instructions = f"""
1740
+ subject: {content_subject}
1741
+ grade: {content_grade}
1742
+ context: {key_moments_text}
1743
+ Assistant Role: you are a {content_subject} teacher
1744
+ User Role: {content_grade} th-grade student.
1745
+ Method: Socratic style, guide thinking, no direct answers. this is very important, please be seriously following.
1746
+ Language: Traditional Chinese ZH-TW (it's very important), suitable for {content_grade} th-grade level.
1747
+ Response: Single question, under 100 characters, include math symbols (use LaTeX $), hint with video timestamp which format【參考:00:00:00】.
1748
+ Sometimes encourage user by Taiwanese style.
1749
+ if user ask questions not include in context,
1750
+ just tell them to ask the question in context and give them example question.
1751
+ Restrictions: Answer within video content, no external references
 
 
 
 
 
 
 
 
 
1752
  """
1753
 
1754
  print("=== instructions ===")
 
1924
  print("=== transcript_text is used ===")
1925
 
1926
  instructions = f"""
1927
+ subject: {content_subject}
1928
+ grade: {content_grade}
1929
+ context: {key_moments_text}
1930
+ Assistant Role: you are a {content_subject} teacher
1931
+ User Role: {content_grade} th-grade student.
1932
+ Method: Socratic style, guide thinking, no direct answers. this is very important, please be seriously following.
1933
+ Language: Traditional Chinese ZH-TW (it's very important), suitable for {content_grade} th-grade level.
1934
+ Response: Single question, under 100 characters, include math symbols (use LaTeX $), hint with video timestamp which format 【參考:00:00:00】.
1935
+ Sometimes encourage user by Taiwanese style.
1936
+ if user ask questions not include in context,
1937
+ just tell them to ask the question in context and give them example question.
1938
+ Restrictions: Answer within video content, no external references
 
 
 
 
 
 
 
 
 
1939
  """
1940
 
1941
  # 创建线程
chatbot.py CHANGED
@@ -60,13 +60,13 @@ class Chatbot:
60
  subject: {content_subject}
61
  grade: {content_grade}
62
  context: {key_moments_text}
63
- -------------------------------------
64
- Role: {content_subject} teacher, {content_grade} th-grade student.
65
  Method: Socratic style, guide thinking, no direct answers. this is very important, please be seriously following.
66
  Language: Traditional Chinese ZH-TW (it's very important), suitable for {content_grade} th-grade level.
67
- Response: Single question, under 100 characters, include math symbols (use LaTeX $), hint with video timestamp which format 00:00:00】.
68
- Sometimes encourage user by Taiwanese tone.
69
- if user ask questions not include in key_moments_text,
70
  just tell them to ask the question in context and give them example question.
71
  Restrictions: Answer within video content, no external references
72
  """
@@ -109,8 +109,8 @@ class Chatbot:
109
  "Content-Type": "application/json",
110
  "x-api-key": self.jutor_chat_key,
111
  }
112
- # model = "gpt-4-1106-preview"
113
- model = "gpt-3.5-turbo-0125"
114
  data = {
115
  "data": {
116
  "messages": messages,
 
60
  subject: {content_subject}
61
  grade: {content_grade}
62
  context: {key_moments_text}
63
+ Assistant Role: you are a {content_subject} teacher
64
+ User Role: {content_grade} th-grade student.
65
  Method: Socratic style, guide thinking, no direct answers. this is very important, please be seriously following.
66
  Language: Traditional Chinese ZH-TW (it's very important), suitable for {content_grade} th-grade level.
67
+ Response: Single question, under 100 characters, include math symbols (use LaTeX $), hint with video timestamp which format 【參考:00:00:00】.
68
+ Sometimes encourage user by Taiwanese style.
69
+ if user ask questions not include in context,
70
  just tell them to ask the question in context and give them example question.
71
  Restrictions: Answer within video content, no external references
72
  """
 
109
  "Content-Type": "application/json",
110
  "x-api-key": self.jutor_chat_key,
111
  }
112
+ model = "gpt-4-1106-preview"
113
+ # model = "gpt-3.5-turbo-0125"
114
  data = {
115
  "data": {
116
  "messages": messages,