Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -390,10 +390,14 @@ def handsome_chat_completions():
|
|
390 |
if message["role"] == "user" and isinstance(message["content"], str):
|
391 |
user_content += message["content"] + " "
|
392 |
user_content = user_content.strip()
|
393 |
-
|
394 |
# 记录日志,将换行符替换为 \n
|
|
|
|
|
|
|
|
|
395 |
logging.info(
|
396 |
-
f"使用的key: {api_key}, 提示token: {prompt_tokens}, 输出token: {completion_tokens}, 首字用时: {first_token_time:.4f}秒, 总共用时: {total_time:.4f}秒, 使用的模型: {model_name}, 用户的内容: {
|
397 |
)
|
398 |
return Response(stream_with_context(generate()), content_type=response.headers['Content-Type'])
|
399 |
else:
|
@@ -415,17 +419,21 @@ def handsome_chat_completions():
|
|
415 |
response_content = ""
|
416 |
|
417 |
# 提取用户输入的内容,忽略非文本内容
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
|
|
|
|
|
|
|
|
429 |
return jsonify(response_json)
|
430 |
|
431 |
except requests.exceptions.RequestException as e:
|
|
|
390 |
if message["role"] == "user" and isinstance(message["content"], str):
|
391 |
user_content += message["content"] + " "
|
392 |
user_content = user_content.strip()
|
393 |
+
|
394 |
# 记录日志,将换行符替换为 \n
|
395 |
+
# Create temporary variables to hold the replaced strings
|
396 |
+
user_content_replaced = user_content.replace('\n', '\\n').replace('\r', '\\n')
|
397 |
+
response_content_replaced = response_content.replace('\n', '\\n').replace('\r', '\\n')
|
398 |
+
|
399 |
logging.info(
|
400 |
+
f"使用的key: {api_key}, 提示token: {prompt_tokens}, 输出token: {completion_tokens}, 首字用时: {first_token_time:.4f}秒, 总共用时: {total_time:.4f}秒, 使用的模型: {model_name}, 用户的内容: {user_content_replaced}, 输出的内容: {response_content_replaced}"
|
401 |
)
|
402 |
return Response(stream_with_context(generate()), content_type=response.headers['Content-Type'])
|
403 |
else:
|
|
|
419 |
response_content = ""
|
420 |
|
421 |
# 提取用户输入的内容,忽略非文本内容
|
422 |
+
user_content = ""
|
423 |
+
messages = data.get("messages", [])
|
424 |
+
for message in messages:
|
425 |
+
if message["role"] == "user" and isinstance(message["content"], str):
|
426 |
+
user_content += message["content"] + " "
|
427 |
+
user_content = user_content.strip()
|
428 |
+
|
429 |
+
# 记录日志,将换行符替换为 \n
|
430 |
+
# Create temporary variables to hold the replaced strings
|
431 |
+
user_content_replaced = user_content.replace('\n', '\\n').replace('\r', '\\n')
|
432 |
+
response_content_replaced = response_content.replace('\n', '\\n').replace('\r', '\\n')
|
433 |
+
|
434 |
+
logging.info(
|
435 |
+
f"使用的key: {api_key}, 提示token: {prompt_tokens}, 输出token: {completion_tokens}, 首字用时: 0, 总共用时: {total_time:.4f}秒, 使用的模型: {model_name}, 用户的内容: {user_content_replaced}, 输出的内容: {response_content_replaced}"
|
436 |
+
)
|
437 |
return jsonify(response_json)
|
438 |
|
439 |
except requests.exceptions.RequestException as e:
|