Kevin Hu
commited on
Commit
·
a042063
1
Parent(s):
4beec7d
Replace image2text model check with internal image. (#4250)
Browse files### What problem does this PR solve?
#4243
### Type of change
- [x] Bug Fix (non-breaking change which fixes an issue)
- api/apps/llm_app.py +4 -10
- api/utils/api_utils.py +3 -14
api/apps/llm_app.py
CHANGED
|
@@ -15,7 +15,7 @@
|
|
| 15 |
#
|
| 16 |
import logging
|
| 17 |
import json
|
| 18 |
-
|
| 19 |
from flask import request
|
| 20 |
from flask_login import login_required, current_user
|
| 21 |
from api.db.services.llm_service import LLMFactoriesService, TenantLLMService, LLMService
|
|
@@ -24,8 +24,8 @@ from api.utils.api_utils import server_error_response, get_data_error_result, va
|
|
| 24 |
from api.db import StatusEnum, LLMType
|
| 25 |
from api.db.db_models import TenantLLM
|
| 26 |
from api.utils.api_utils import get_json_result
|
|
|
|
| 27 |
from rag.llm import EmbeddingModel, ChatModel, RerankModel, CvModel, TTSModel
|
| 28 |
-
import requests
|
| 29 |
|
| 30 |
|
| 31 |
@manager.route('/factories', methods=['GET']) # noqa: F821
|
|
@@ -254,16 +254,10 @@ def add_llm():
|
|
| 254 |
base_url=llm["api_base"]
|
| 255 |
)
|
| 256 |
try:
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
)
|
| 260 |
-
res = requests.get(img_url)
|
| 261 |
-
if res.status_code == 200:
|
| 262 |
-
m, tc = mdl.describe(res.content)
|
| 263 |
if not tc:
|
| 264 |
raise Exception(m)
|
| 265 |
-
else:
|
| 266 |
-
pass
|
| 267 |
except Exception as e:
|
| 268 |
msg += f"\nFail to access model({llm['llm_name']})." + str(e)
|
| 269 |
elif llm["model_type"] == LLMType.TTS:
|
|
|
|
| 15 |
#
|
| 16 |
import logging
|
| 17 |
import json
|
| 18 |
+
import os
|
| 19 |
from flask import request
|
| 20 |
from flask_login import login_required, current_user
|
| 21 |
from api.db.services.llm_service import LLMFactoriesService, TenantLLMService, LLMService
|
|
|
|
| 24 |
from api.db import StatusEnum, LLMType
|
| 25 |
from api.db.db_models import TenantLLM
|
| 26 |
from api.utils.api_utils import get_json_result
|
| 27 |
+
from api.utils.file_utils import get_project_base_directory
|
| 28 |
from rag.llm import EmbeddingModel, ChatModel, RerankModel, CvModel, TTSModel
|
|
|
|
| 29 |
|
| 30 |
|
| 31 |
@manager.route('/factories', methods=['GET']) # noqa: F821
|
|
|
|
| 254 |
base_url=llm["api_base"]
|
| 255 |
)
|
| 256 |
try:
|
| 257 |
+
with open(os.path.join(get_project_base_directory(), "web/src/assets/yay.jpg"), "rb") as f:
|
| 258 |
+
m, tc = mdl.describe(f.read())
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
if not tc:
|
| 260 |
raise Exception(m)
|
|
|
|
|
|
|
| 261 |
except Exception as e:
|
| 262 |
msg += f"\nFail to access model({llm['llm_name']})." + str(e)
|
| 263 |
elif llm["model_type"] == LLMType.TTS:
|
api/utils/api_utils.py
CHANGED
|
@@ -98,14 +98,9 @@ def get_exponential_backoff_interval(retries, full_jitter=False):
|
|
| 98 |
|
| 99 |
def get_data_error_result(code=settings.RetCode.DATA_ERROR,
|
| 100 |
message='Sorry! Data missing!'):
|
| 101 |
-
import re
|
| 102 |
result_dict = {
|
| 103 |
"code": code,
|
| 104 |
-
"message":
|
| 105 |
-
r"rag",
|
| 106 |
-
"seceum",
|
| 107 |
-
message,
|
| 108 |
-
flags=re.IGNORECASE)}
|
| 109 |
response = {}
|
| 110 |
for key, value in result_dict.items():
|
| 111 |
if value is None and key != "code":
|
|
@@ -250,8 +245,7 @@ def construct_response(code=settings.RetCode.SUCCESS,
|
|
| 250 |
|
| 251 |
|
| 252 |
def construct_result(code=settings.RetCode.DATA_ERROR, message='data is missing'):
|
| 253 |
-
|
| 254 |
-
result_dict = {"code": code, "message": re.sub(r"rag", "seceum", message, flags=re.IGNORECASE)}
|
| 255 |
response = {}
|
| 256 |
for key, value in result_dict.items():
|
| 257 |
if value is None and key != "code":
|
|
@@ -314,14 +308,9 @@ def get_result(code=settings.RetCode.SUCCESS, message="", data=None):
|
|
| 314 |
|
| 315 |
def get_error_data_result(message='Sorry! Data missing!', code=settings.RetCode.DATA_ERROR,
|
| 316 |
):
|
| 317 |
-
import re
|
| 318 |
result_dict = {
|
| 319 |
"code": code,
|
| 320 |
-
"message":
|
| 321 |
-
r"rag",
|
| 322 |
-
"seceum",
|
| 323 |
-
message,
|
| 324 |
-
flags=re.IGNORECASE)}
|
| 325 |
response = {}
|
| 326 |
for key, value in result_dict.items():
|
| 327 |
if value is None and key != "code":
|
|
|
|
| 98 |
|
| 99 |
def get_data_error_result(code=settings.RetCode.DATA_ERROR,
|
| 100 |
message='Sorry! Data missing!'):
|
|
|
|
| 101 |
result_dict = {
|
| 102 |
"code": code,
|
| 103 |
+
"message": message}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
response = {}
|
| 105 |
for key, value in result_dict.items():
|
| 106 |
if value is None and key != "code":
|
|
|
|
| 245 |
|
| 246 |
|
| 247 |
def construct_result(code=settings.RetCode.DATA_ERROR, message='data is missing'):
|
| 248 |
+
result_dict = {"code": code, "message": message}
|
|
|
|
| 249 |
response = {}
|
| 250 |
for key, value in result_dict.items():
|
| 251 |
if value is None and key != "code":
|
|
|
|
| 308 |
|
| 309 |
def get_error_data_result(message='Sorry! Data missing!', code=settings.RetCode.DATA_ERROR,
|
| 310 |
):
|
|
|
|
| 311 |
result_dict = {
|
| 312 |
"code": code,
|
| 313 |
+
"message": message}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
response = {}
|
| 315 |
for key, value in result_dict.items():
|
| 316 |
if value is None and key != "code":
|