feat:限制必须api-key或登录5
parent
f2c8387e97
commit
e6efa1a074
|
|
@ -6,6 +6,7 @@
|
||||||
@date:2025/11/5 15:26
|
@date:2025/11/5 15:26
|
||||||
@desc:
|
@desc:
|
||||||
"""
|
"""
|
||||||
|
import os
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from langchain_huggingface import HuggingFaceEmbeddings
|
from langchain_huggingface import HuggingFaceEmbeddings
|
||||||
|
|
@ -20,7 +21,13 @@ class LocalEmbedding(MaxKBBaseModel, HuggingFaceEmbeddings):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def new_instance(model_type, model_name, model_credential: Dict[str, object], **model_kwargs):
|
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')},
|
model_kwargs={'device': model_credential.get('device')},
|
||||||
encode_kwargs={'normalize_embeddings': True}
|
encode_kwargs={'normalize_embeddings': True}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ class LocalEmbedding(MaxKBBaseModel, BaseModel, Embeddings):
|
||||||
bind = f'{CONFIG.get("LOCAL_MODEL_HOST")}:{CONFIG.get("LOCAL_MODEL_PORT")}'
|
bind = f'{CONFIG.get("LOCAL_MODEL_HOST")}:{CONFIG.get("LOCAL_MODEL_PORT")}'
|
||||||
prefix = CONFIG.get_admin_path()
|
prefix = CONFIG.get_admin_path()
|
||||||
res = requests.post(
|
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})
|
{'texts': texts})
|
||||||
result = res.json()
|
result = res.json()
|
||||||
if result.get('code', 500) == 200:
|
if result.get('code', 500) == 200:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue