Upload api.py
Browse files
api.py
CHANGED
|
@@ -291,16 +291,19 @@ def chat_completions():
|
|
| 291 |
return jsonify({"error": "消息内容为空:所有消息均不包含有效内容,请检查消息格式"}), 400
|
| 292 |
|
| 293 |
# 生成2个随机字符(可以是英文大小写、数字或特殊字符)
|
| 294 |
-
def generate_random_chars(length=
|
| 295 |
# 所有可能的字符:大小写字母、数字和特殊字符
|
| 296 |
all_chars = string.ascii_letters + string.digits + string.punctuation
|
| 297 |
# 随机选择指定数量的字符
|
| 298 |
random_chars = ''.join(random.choice(all_chars) for _ in range(length))
|
| 299 |
return random_chars
|
|
|
|
| 300 |
|
| 301 |
# 在查询前添加随机字符
|
| 302 |
random_prefix = generate_random_chars()
|
| 303 |
-
|
|
|
|
|
|
|
| 304 |
|
| 305 |
# 处理请求,添加重试逻辑
|
| 306 |
max_retries = 5
|
|
|
|
| 291 |
return jsonify({"error": "消息内容为空:所有消息均不包含有效内容,请检查消息格式"}), 400
|
| 292 |
|
| 293 |
# 生成2个随机字符(可以是英文大小写、数字或特殊字符)
|
| 294 |
+
def generate_random_chars(length=3):
|
| 295 |
# 所有可能的字符:大小写字母、数字和特殊字符
|
| 296 |
all_chars = string.ascii_letters + string.digits + string.punctuation
|
| 297 |
# 随机选择指定数量的字符
|
| 298 |
random_chars = ''.join(random.choice(all_chars) for _ in range(length))
|
| 299 |
return random_chars
|
| 300 |
+
|
| 301 |
|
| 302 |
# 在查询前添加随机字符
|
| 303 |
random_prefix = generate_random_chars()
|
| 304 |
+
logging.info(f"生成的随机前缀:{random_prefix}")
|
| 305 |
+
|
| 306 |
+
query = random_prefix + "\n\n".join(formatted_messages)
|
| 307 |
|
| 308 |
# 处理请求,添加重试逻辑
|
| 309 |
max_retries = 5
|