mirror of
https://github.com/BoardWare-Genius/jarvis-models.git
synced 2025-12-13 16:53:24 +00:00
fix: add bytes parse
This commit is contained in:
@ -12,6 +12,7 @@ import requests
|
|||||||
import base64
|
import base64
|
||||||
import copy
|
import copy
|
||||||
import ast
|
import ast
|
||||||
|
import json
|
||||||
|
|
||||||
import io
|
import io
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
@ -93,7 +94,6 @@ class VLMS(Blackbox):
|
|||||||
response: a string
|
response: a string
|
||||||
history: a list
|
history: a list
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if settings:
|
if settings:
|
||||||
for k in settings:
|
for k in settings:
|
||||||
if k not in self.settings:
|
if k not in self.settings:
|
||||||
@ -260,12 +260,17 @@ class VLMS(Blackbox):
|
|||||||
## TODO: add support for multiple images and support image in form-data format
|
## TODO: add support for multiple images and support image in form-data format
|
||||||
json_request = True
|
json_request = True
|
||||||
try:
|
try:
|
||||||
content_type = request.headers['content-type']
|
content_type = request.headers.get('content-type', '')
|
||||||
|
print(content_type)
|
||||||
if content_type == 'application/json':
|
if content_type == 'application/json':
|
||||||
data = await request.json()
|
data = await request.json()
|
||||||
else:
|
elif 'multipart/form-data' in content_type:
|
||||||
data = await request.form()
|
data = await request.form()
|
||||||
json_request = False
|
json_request = False
|
||||||
|
else:
|
||||||
|
body = await request.body()
|
||||||
|
data = json.loads(body.decode("utf-8"))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return JSONResponse(content={"error": "json parse error"}, status_code=status.HTTP_400_BAD_REQUEST)
|
return JSONResponse(content={"error": "json parse error"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
@ -283,7 +288,7 @@ class VLMS(Blackbox):
|
|||||||
else:
|
else:
|
||||||
return JSONResponse(content={"error": "context format error, should be in format of list or Openai_format"}, status_code=status.HTTP_400_BAD_REQUEST)
|
return JSONResponse(content={"error": "context format error, should be in format of list or Openai_format"}, status_code=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
if json_request:
|
if json_request or 'multipart/form-data' not in content_type:
|
||||||
img_data = data.get("img_data")
|
img_data = data.get("img_data")
|
||||||
else:
|
else:
|
||||||
img_data = await data.get("img_data").read()
|
img_data = await data.get("img_data").read()
|
||||||
|
|||||||
Reference in New Issue
Block a user