Spaces:
Sleeping
Sleeping
print("=== transcript_text is too long, replace by key_moments_text ===")
Browse files
app.py
CHANGED
|
@@ -1838,7 +1838,7 @@ def poll_run_status(run_id, thread_id, timeout=600, poll_interval=5):
|
|
| 1838 |
|
| 1839 |
return run.status
|
| 1840 |
|
| 1841 |
-
def streaming_chat_with_open_ai(user_message, chat_history, password, thread_id, trascript, content_subject, content_grade):
|
| 1842 |
verify_password(password)
|
| 1843 |
|
| 1844 |
print("===streaming_chat_with_open_ai===")
|
|
@@ -1865,14 +1865,29 @@ def streaming_chat_with_open_ai(user_message, chat_history, password, thread_id,
|
|
| 1865 |
trascript_json = json.loads(trascript)
|
| 1866 |
else:
|
| 1867 |
trascript_json = trascript
|
| 1868 |
-
trascript_text = json.dumps(trascript_json, ensure_ascii=False
|
| 1869 |
# trascript_text 移除 \n, 空白
|
| 1870 |
trascript_text = trascript_text.replace("\n", "").replace(" ", "")
|
| 1871 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1872 |
instructions = f"""
|
| 1873 |
科目:{content_subject}
|
| 1874 |
年級:{content_grade}
|
| 1875 |
-
逐字稿資料:{
|
| 1876 |
-------------------------------------
|
| 1877 |
你是一個專業的{content_subject}老師, user 為{content_grade}的學生
|
| 1878 |
socratic_mode = {socratic_mode}
|
|
|
|
| 1838 |
|
| 1839 |
return run.status
|
| 1840 |
|
| 1841 |
+
def streaming_chat_with_open_ai(user_message, chat_history, password, thread_id, trascript, key_moments, content_subject, content_grade):
|
| 1842 |
verify_password(password)
|
| 1843 |
|
| 1844 |
print("===streaming_chat_with_open_ai===")
|
|
|
|
| 1865 |
trascript_json = json.loads(trascript)
|
| 1866 |
else:
|
| 1867 |
trascript_json = trascript
|
| 1868 |
+
trascript_text = json.dumps(trascript_json, ensure_ascii=False)
|
| 1869 |
# trascript_text 移除 \n, 空白
|
| 1870 |
trascript_text = trascript_text.replace("\n", "").replace(" ", "")
|
| 1871 |
|
| 1872 |
+
if isinstance(key_moments, str):
|
| 1873 |
+
key_moments_json = json.loads(key_moments)
|
| 1874 |
+
else:
|
| 1875 |
+
key_moments_json = key_moments
|
| 1876 |
+
# key_moments_json remove images
|
| 1877 |
+
for moment in key_moments_json:
|
| 1878 |
+
moment.pop('images', None)
|
| 1879 |
+
|
| 1880 |
+
if len(trascript_text) > 25000:
|
| 1881 |
+
content_text = json.dumps(key_moments_json, ensure_ascii=False)
|
| 1882 |
+
print("=== transcript_text is too long, replace by key_moments_text ===")
|
| 1883 |
+
else:
|
| 1884 |
+
content_text = trascript_text
|
| 1885 |
+
print("=== transcript_text is used ===")
|
| 1886 |
+
|
| 1887 |
instructions = f"""
|
| 1888 |
科目:{content_subject}
|
| 1889 |
年級:{content_grade}
|
| 1890 |
+
逐字稿資料:{content_text}
|
| 1891 |
-------------------------------------
|
| 1892 |
你是一個專業的{content_subject}老師, user 為{content_grade}的學生
|
| 1893 |
socratic_mode = {socratic_mode}
|