This commit is contained in:
2025-08-20 14:23:33 +08:00
parent 8e799f8d55
commit a59c956a2c
6 changed files with 69 additions and 8 deletions

View File

@@ -23,16 +23,19 @@ MIN_QUERY_INTERVAL = 1
last_query_time = 0
# type_id = data.get('type_id', '1') # 1-教学模式2-对话模式
# yunxiao_sample = data.get('yunxiao_sample', False) # 是不是给长春云校做例子
def send_message(query):
"""发送消息到聊天API并接收流式响应"""
global last_query_time
current_time = time.time()
# 检查查询间隔
if current_time - last_query_time < MIN_QUERY_INTERVAL:
print(f"\n请等待 {MIN_QUERY_INTERVAL} 秒后再发送消息")
return
last_query_time = current_time
headers = {
"Content-Type": "application/json"
@@ -42,6 +45,8 @@ def send_message(query):
"user_id": USER_ID,
"query": query,
"session_id": SESSION_ID,
"type_id": 2,
"yunxiao_sample": True,
"include_history": True # 包含历史记录
}
@@ -60,14 +65,14 @@ def send_message(query):
line_str = line.decode('utf-8').strip()
if line_str.startswith('data:'):
line_str = line_str.replace('data:', '')
# 处理[DONE]标记
if line_str == '[DONE]':
break
if not line_str: # 跳过空行
continue
try:
# 解析JSON
data = json.loads(line_str)
@@ -132,4 +137,4 @@ def main():
if __name__ == "__main__":
main()
main()