mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-13 16:38:26 +08:00
refa: resolve tenant model refs consistently (#16744)
This commit is contained in:
@@ -498,7 +498,7 @@ def check_duplicate_ids(ids, id_type="item"):
|
||||
|
||||
|
||||
def verify_embedding_availability(embd_id: str, tenant_id: str) -> tuple[bool, str | None]:
|
||||
from api.db.joint_services.tenant_model_service import get_model_config_from_provider_instance
|
||||
from api.db.joint_services.tenant_model_service import resolve_model_config
|
||||
|
||||
"""
|
||||
Verifies availability of an embedding model for a specific tenant.
|
||||
@@ -534,7 +534,7 @@ def verify_embedding_availability(embd_id: str, tenant_id: str) -> tuple[bool, s
|
||||
(False, {'code': 101, 'message': "Unsupported model: <invalid_model>"})
|
||||
"""
|
||||
try:
|
||||
get_model_config_from_provider_instance(tenant_id, LLMType.EMBEDDING, embd_id)
|
||||
resolve_model_config(tenant_id, LLMType.EMBEDDING, embd_id)
|
||||
except LookupError as e:
|
||||
return False, str(e)
|
||||
except OperationalError as e:
|
||||
|
||||
@@ -617,13 +617,14 @@ class CreateDatasetReq(Base):
|
||||
Validation pipeline:
|
||||
1. Structural format verification
|
||||
2. Component non-empty check
|
||||
3. Value normalization
|
||||
3. Tenant model id passthrough
|
||||
4. Value normalization
|
||||
|
||||
Args:
|
||||
v (str): Raw model identifier
|
||||
|
||||
Returns:
|
||||
str: Validated <model_name>@<provider> format
|
||||
str: Validated <model_name>@<provider> format or tenant_model id
|
||||
|
||||
Raises:
|
||||
PydanticCustomError: For these violations:
|
||||
@@ -633,11 +634,15 @@ class CreateDatasetReq(Base):
|
||||
|
||||
Examples:
|
||||
Valid: "text-embedding-3-large@openai"
|
||||
Valid: "2f3c0f9c7b1d11f0a1b2c3d4e5f67890" # tenant_model.id
|
||||
Invalid: "invalid_model" (no @)
|
||||
Invalid: "@openai" (empty model_name)
|
||||
Invalid: "text-embedding-3-large@" (empty provider)
|
||||
"""
|
||||
if isinstance(v, str):
|
||||
if re.fullmatch(r"[0-9a-fA-F]{32}", v):
|
||||
return v
|
||||
|
||||
if "@" not in v:
|
||||
raise PydanticCustomError("format_invalid", "Embedding model identifier must follow <model_name>@<provider> format")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user