Update app.py
Browse files
app.py
CHANGED
|
@@ -653,29 +653,46 @@ def handsome_chat_completions():
|
|
| 653 |
logging.error(f"无效的图片数据: {item}")
|
| 654 |
openai_images.append({"url": item})
|
| 655 |
|
| 656 |
-
# Construct the expected JSON output
|
| 657 |
response_data = {
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 663 |
}
|
| 664 |
-
|
| 665 |
-
response_data["seed"] = response_json["seed"]
|
| 666 |
-
if "shared_id" in response_json:
|
| 667 |
-
response_data["shared_id"] = response_json["shared_id"]
|
| 668 |
-
if "data" in response_json:
|
| 669 |
-
response_data["data"] = response_json["data"]
|
| 670 |
-
|
| 671 |
except (KeyError, ValueError, IndexError) as e:
|
| 672 |
logging.error(
|
| 673 |
f"解析响应 JSON 失败: {e}, "
|
| 674 |
f"完整内容: {response_json}"
|
| 675 |
)
|
| 676 |
response_data = {
|
| 677 |
-
|
| 678 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 679 |
}
|
| 680 |
|
| 681 |
logging.info(
|
|
|
|
| 653 |
logging.error(f"无效的图片数据: {item}")
|
| 654 |
openai_images.append({"url": item})
|
| 655 |
|
| 656 |
+
# Construct the expected JSON output - Mimicking OpenAI
|
| 657 |
response_data = {
|
| 658 |
+
"id": f"chatcmpl-{uuid.uuid4()}",
|
| 659 |
+
"object": "chat.completion",
|
| 660 |
+
"created": int(time.time()),
|
| 661 |
+
"model": model_name,
|
| 662 |
+
"choices": [
|
| 663 |
+
{
|
| 664 |
+
"index": 0,
|
| 665 |
+
"message": {
|
| 666 |
+
"role": "assistant",
|
| 667 |
+
"content": None,
|
| 668 |
+
"images": openai_images # This field should be named images instead of data or others
|
| 669 |
+
},
|
| 670 |
+
"finish_reason": "stop",
|
| 671 |
+
}
|
| 672 |
+
],
|
| 673 |
}
|
| 674 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 675 |
except (KeyError, ValueError, IndexError) as e:
|
| 676 |
logging.error(
|
| 677 |
f"解析响应 JSON 失败: {e}, "
|
| 678 |
f"完整内容: {response_json}"
|
| 679 |
)
|
| 680 |
response_data = {
|
| 681 |
+
"id": f"chatcmpl-{uuid.uuid4()}",
|
| 682 |
+
"object": "chat.completion",
|
| 683 |
+
"created": int(time.time()),
|
| 684 |
+
"model": model_name,
|
| 685 |
+
"choices": [
|
| 686 |
+
{
|
| 687 |
+
"index": 0,
|
| 688 |
+
"message": {
|
| 689 |
+
"role": "assistant",
|
| 690 |
+
"content": None,
|
| 691 |
+
"images": []
|
| 692 |
+
},
|
| 693 |
+
"finish_reason": "stop",
|
| 694 |
+
}
|
| 695 |
+
],
|
| 696 |
}
|
| 697 |
|
| 698 |
logging.info(
|