Spaces:
Paused
Paused
Upload 3 files
Browse files
app.py
CHANGED
|
@@ -707,18 +707,27 @@ def generate_trace_id():
|
|
| 707 |
def send_message(message, model, think=False):
|
| 708 |
"""Flua traktado kaj plusendo de mesaĝoj"""
|
| 709 |
global DELETE_CHAT, LAST_CONVERSATION_IDS
|
|
|
|
|
|
|
|
|
|
|
|
|
| 710 |
(session, cookies, session_token, conversation_id, model_map, user_index) = get_user_data()
|
|
|
|
| 711 |
|
| 712 |
# 获取并保存当前的conversation_id(可能是旧的,用于稍后删除)
|
| 713 |
last_conversation_id = conversation_id
|
| 714 |
|
| 715 |
# 确保有有效的会话ID
|
| 716 |
conversation_id = get_or_create_conversation(session, cookies, session_token, conversation_id, model_map, model, user_index)
|
|
|
|
| 717 |
|
| 718 |
trace_id, sentry_trace = generate_trace_id()
|
| 719 |
|
| 720 |
# 计算输入token
|
|
|
|
| 721 |
prompt_tokens, calculation_method = num_tokens_from_string(message, model)
|
|
|
|
|
|
|
| 722 |
completion_buffer = io.StringIO() # 收集所有输出用于计算token
|
| 723 |
|
| 724 |
headers = {
|
|
@@ -851,18 +860,27 @@ def send_message(message, model, think=False):
|
|
| 851 |
def send_message_non_stream(message, model, think=False):
|
| 852 |
"""Ne-flua traktado de mesaĝoj"""
|
| 853 |
global DELETE_CHAT, LAST_CONVERSATION_IDS
|
|
|
|
|
|
|
|
|
|
|
|
|
| 854 |
(session, cookies, session_token, conversation_id, model_map, user_index) = get_user_data()
|
|
|
|
| 855 |
|
| 856 |
# 获取并保存当前的conversation_id(可能是旧的,用于稍后删除)
|
| 857 |
last_conversation_id = conversation_id
|
| 858 |
|
| 859 |
# 确保有有效的会话ID
|
| 860 |
conversation_id = get_or_create_conversation(session, cookies, session_token, conversation_id, model_map, model, user_index)
|
|
|
|
| 861 |
|
| 862 |
trace_id, sentry_trace = generate_trace_id()
|
| 863 |
|
| 864 |
# 计算输入token
|
|
|
|
| 865 |
prompt_tokens, calculation_method = num_tokens_from_string(message, model)
|
|
|
|
|
|
|
| 866 |
|
| 867 |
headers = {
|
| 868 |
"accept": "text/event-stream",
|
|
|
|
| 707 |
def send_message(message, model, think=False):
|
| 708 |
"""Flua traktado kaj plusendo de mesaĝoj"""
|
| 709 |
global DELETE_CHAT, LAST_CONVERSATION_IDS
|
| 710 |
+
print("\n===== 开始处理消息 =====")
|
| 711 |
+
print(f"模型: {model}")
|
| 712 |
+
print(f"思考模式: {think}")
|
| 713 |
+
|
| 714 |
(session, cookies, session_token, conversation_id, model_map, user_index) = get_user_data()
|
| 715 |
+
print(f"使用用户配置: {user_index + 1}")
|
| 716 |
|
| 717 |
# 获取并保存当前的conversation_id(可能是旧的,用于稍后删除)
|
| 718 |
last_conversation_id = conversation_id
|
| 719 |
|
| 720 |
# 确保有有效的会话ID
|
| 721 |
conversation_id = get_or_create_conversation(session, cookies, session_token, conversation_id, model_map, model, user_index)
|
| 722 |
+
print(f"会话ID: {conversation_id}")
|
| 723 |
|
| 724 |
trace_id, sentry_trace = generate_trace_id()
|
| 725 |
|
| 726 |
# 计算输入token
|
| 727 |
+
print("\n----- 计算输入token -----")
|
| 728 |
prompt_tokens, calculation_method = num_tokens_from_string(message, model)
|
| 729 |
+
print(f"输入token数: {prompt_tokens}")
|
| 730 |
+
print(f"计算方法: {calculation_method}")
|
| 731 |
completion_buffer = io.StringIO() # 收集所有输出用于计算token
|
| 732 |
|
| 733 |
headers = {
|
|
|
|
| 860 |
def send_message_non_stream(message, model, think=False):
|
| 861 |
"""Ne-flua traktado de mesaĝoj"""
|
| 862 |
global DELETE_CHAT, LAST_CONVERSATION_IDS
|
| 863 |
+
print("\n===== 开始处理消息(非流式) =====")
|
| 864 |
+
print(f"模型: {model}")
|
| 865 |
+
print(f"思考模式: {think}")
|
| 866 |
+
|
| 867 |
(session, cookies, session_token, conversation_id, model_map, user_index) = get_user_data()
|
| 868 |
+
print(f"使用用户配置: {user_index + 1}")
|
| 869 |
|
| 870 |
# 获取并保存当前的conversation_id(可能是旧的,用于稍后删除)
|
| 871 |
last_conversation_id = conversation_id
|
| 872 |
|
| 873 |
# 确保有有效的会话ID
|
| 874 |
conversation_id = get_or_create_conversation(session, cookies, session_token, conversation_id, model_map, model, user_index)
|
| 875 |
+
print(f"会话ID: {conversation_id}")
|
| 876 |
|
| 877 |
trace_id, sentry_trace = generate_trace_id()
|
| 878 |
|
| 879 |
# 计算输入token
|
| 880 |
+
print("\n----- 计算输入token -----")
|
| 881 |
prompt_tokens, calculation_method = num_tokens_from_string(message, model)
|
| 882 |
+
print(f"输入token数: {prompt_tokens}")
|
| 883 |
+
print(f"计算方法: {calculation_method}")
|
| 884 |
|
| 885 |
headers = {
|
| 886 |
"accept": "text/event-stream",
|