Update app.py
Browse files
app.py
CHANGED
@@ -3,14 +3,13 @@ import time
|
|
3 |
import logging
|
4 |
import requests
|
5 |
import json
|
6 |
-
import random
|
7 |
import uuid
|
8 |
import concurrent.futures
|
9 |
import threading
|
10 |
import base64
|
11 |
import io
|
12 |
from PIL import Image
|
13 |
-
from datetime import datetime
|
14 |
from apscheduler.schedulers.background import BackgroundScheduler
|
15 |
from flask import Flask, request, jsonify, Response, stream_with_context
|
16 |
|
@@ -460,20 +459,6 @@ def list_models():
|
|
460 |
"created": 1678888888,
|
461 |
"owned_by": "openai",
|
462 |
"permission": [
|
463 |
-
{
|
464 |
-
"id": f"modelperm-{uuid.uuid4().hex}",
|
465 |
-
"object": "model_permission",
|
466 |
-
"created": 1678888888,
|
467 |
-
"allow_create_engine": False,
|
468 |
-
"allow_sampling": True,
|
469 |
-
"allow_logprobs": True,
|
470 |
-
"allow_search_indices": False,
|
471 |
-
"allow_view": True,
|
472 |
-
"allow_fine_tuning": False,
|
473 |
-
"organization": "*",
|
474 |
-
"group": None,
|
475 |
-
"is_blocking": False
|
476 |
-
}
|
477 |
],
|
478 |
"root": model,
|
479 |
"parent": None
|
@@ -486,20 +471,6 @@ def list_models():
|
|
486 |
"created": 1678888888,
|
487 |
"owned_by": "openai",
|
488 |
"permission": [
|
489 |
-
{
|
490 |
-
"id": f"modelperm-{uuid.uuid4().hex}",
|
491 |
-
"object": "model_permission",
|
492 |
-
"created": 1678888888,
|
493 |
-
"allow_create_engine": False,
|
494 |
-
"allow_sampling": True,
|
495 |
-
"allow_logprobs": True,
|
496 |
-
"allow_search_indices": False,
|
497 |
-
"allow_view": True,
|
498 |
-
"allow_fine_tuning": False,
|
499 |
-
"organization": "*",
|
500 |
-
"group": None,
|
501 |
-
"is_blocking": False
|
502 |
-
}
|
503 |
],
|
504 |
"root": model,
|
505 |
"parent": None
|
@@ -512,20 +483,6 @@ def list_models():
|
|
512 |
"created": 1678888888,
|
513 |
"owned_by": "openai",
|
514 |
"permission": [
|
515 |
-
{
|
516 |
-
"id": f"modelperm-{uuid.uuid4().hex}",
|
517 |
-
"object": "model_permission",
|
518 |
-
"created": 1678888888,
|
519 |
-
"allow_create_engine": False,
|
520 |
-
"allow_sampling": True,
|
521 |
-
"allow_logprobs": True,
|
522 |
-
"allow_search_indices": False,
|
523 |
-
"allow_view": True,
|
524 |
-
"allow_fine_tuning": False,
|
525 |
-
"organization": "*",
|
526 |
-
"group": None,
|
527 |
-
"is_blocking": False
|
528 |
-
}
|
529 |
],
|
530 |
"root": model,
|
531 |
"parent": None
|
@@ -1005,13 +962,9 @@ def handsome_chat_completions():
|
|
1005 |
|
1006 |
if data.get("stream", False):
|
1007 |
def generate():
|
1008 |
-
first_chunk_time = None
|
1009 |
-
full_response_content = ""
|
1010 |
try:
|
1011 |
response.raise_for_status()
|
1012 |
-
end_time = time.time()
|
1013 |
response_json = response.json()
|
1014 |
-
total_time = end_time - start_time
|
1015 |
|
1016 |
images = response_json.get("images", [])
|
1017 |
|
@@ -1042,7 +995,6 @@ def handsome_chat_completions():
|
|
1042 |
]
|
1043 |
}
|
1044 |
yield f"data: {json.dumps(chunk_data)}\n\n".encode('utf-8')
|
1045 |
-
full_response_content = markdown_image_link
|
1046 |
else:
|
1047 |
chunk_data = {
|
1048 |
"id": f"chatcmpl-{uuid.uuid4()}",
|
@@ -1061,7 +1013,6 @@ def handsome_chat_completions():
|
|
1061 |
]
|
1062 |
}
|
1063 |
yield f"data: {json.dumps(chunk_data)}\n\n".encode('utf-8')
|
1064 |
-
full_response_content = "Failed to generate image"
|
1065 |
|
1066 |
end_chunk_data = {
|
1067 |
"id": f"chatcmpl-{uuid.uuid4()}",
|
|
|
3 |
import logging
|
4 |
import requests
|
5 |
import json
|
|
|
6 |
import uuid
|
7 |
import concurrent.futures
|
8 |
import threading
|
9 |
import base64
|
10 |
import io
|
11 |
from PIL import Image
|
12 |
+
from datetime import datetime
|
13 |
from apscheduler.schedulers.background import BackgroundScheduler
|
14 |
from flask import Flask, request, jsonify, Response, stream_with_context
|
15 |
|
|
|
459 |
"created": 1678888888,
|
460 |
"owned_by": "openai",
|
461 |
"permission": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
462 |
],
|
463 |
"root": model,
|
464 |
"parent": None
|
|
|
471 |
"created": 1678888888,
|
472 |
"owned_by": "openai",
|
473 |
"permission": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
474 |
],
|
475 |
"root": model,
|
476 |
"parent": None
|
|
|
483 |
"created": 1678888888,
|
484 |
"owned_by": "openai",
|
485 |
"permission": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
486 |
],
|
487 |
"root": model,
|
488 |
"parent": None
|
|
|
962 |
|
963 |
if data.get("stream", False):
|
964 |
def generate():
|
|
|
|
|
965 |
try:
|
966 |
response.raise_for_status()
|
|
|
967 |
response_json = response.json()
|
|
|
968 |
|
969 |
images = response_json.get("images", [])
|
970 |
|
|
|
995 |
]
|
996 |
}
|
997 |
yield f"data: {json.dumps(chunk_data)}\n\n".encode('utf-8')
|
|
|
998 |
else:
|
999 |
chunk_data = {
|
1000 |
"id": f"chatcmpl-{uuid.uuid4()}",
|
|
|
1013 |
]
|
1014 |
}
|
1015 |
yield f"data: {json.dumps(chunk_data)}\n\n".encode('utf-8')
|
|
|
1016 |
|
1017 |
end_chunk_data = {
|
1018 |
"id": f"chatcmpl-{uuid.uuid4()}",
|