feat:限制必须api-key或登录5

v3.2
panyy 2026-06-29 17:36:26 +08:00
parent f2c8387e97
commit e6efa1a074
2 changed files with 9 additions and 2 deletions

View File

@ -6,6 +6,7 @@
@date2025/11/5 15:26
@desc:
"""
import os
from typing import Dict
from langchain_huggingface import HuggingFaceEmbeddings
@ -20,7 +21,13 @@ class LocalEmbedding(MaxKBBaseModel, HuggingFaceEmbeddings):
@staticmethod
def new_instance(model_type, model_name, model_credential: Dict[str, object], **model_kwargs):
return LocalEmbedding(model_name=model_name, cache_folder=model_credential.get('cache_folder'),
cache_folder = model_credential.get('cache_folder')
model_path = model_name
if cache_folder and not os.path.isabs(model_name):
local_model_path = os.path.join(cache_folder, model_name)
if os.path.isdir(local_model_path):
model_path = local_model_path
return LocalEmbedding(model_name=model_path, cache_folder=cache_folder,
model_kwargs={'device': model_credential.get('device')},
encode_kwargs={'normalize_embeddings': True}
)

View File

@ -46,7 +46,7 @@ class LocalEmbedding(MaxKBBaseModel, BaseModel, Embeddings):
bind = f'{CONFIG.get("LOCAL_MODEL_HOST")}:{CONFIG.get("LOCAL_MODEL_PORT")}'
prefix = CONFIG.get_admin_path()
res = requests.post(
f'{CONFIG.get("LOCAL_MODEL_PROTOCOL")}://{bind}/{prefix}/api/model/{self.model_id}/embed_documents',
f'{CONFIG.get("LOCAL_MODEL_PROTOCOL")}://{bind}{prefix}/api/model/{self.model_id}/embed_documents',
{'texts': texts})
result = res.json()
if result.get('code', 500) == 200: