Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: Add model_uid validation for model_uid in Xinference models (#2468)

Yeuolyca4aa340f690
diff --git a/api/core/model_runtime/model_providers/xinference/llm/llm.py b/api/core/model_runtime/model_providers/xinference/llm/llm.py
index 83c003d0514..ffb4a0328ce 100644
--- a/api/core/model_runtime/model_providers/xinference/llm/llm.py
+++ b/api/core/model_runtime/model_providers/xinference/llm/llm.py
@@ -97,6 +97,9 @@ class XinferenceAILargeLanguageModel(LargeLanguageModel):
}
"""
try:
+ if "/" in credentials['model_uid'] or "?" in credentials['model_uid'] or "#" in credentials['model_uid']:
+ raise CredentialsValidateFailedError("model_uid should not contain /, ?, or #")
+
extra_param = XinferenceHelper.get_xinference_extra_parameter(
server_url=credentials['server_url'],
model_uid=credentials['model_uid']
diff --git a/api/core/model_runtime/model_providers/xinference/rerank/rerank.py b/api/core/model_runtime/model_providers/xinference/rerank/rerank.py
index f1f87d47df8..1399e9ccd2f 100644
--- a/api/core/model_runtime/model_providers/xinference/rerank/rerank.py
+++ b/api/core/model_runtime/model_providers/xinference/rerank/rerank.py
@@ -92,6 +92,9 @@ class XinferenceRerankModel(RerankModel):
:return:
"""
try:
+ if "/" in credentials['model_uid'] or "?" in credentials['model_uid'] or "#" in credentials['model_uid']:
+ raise CredentialsValidateFailedError("model_uid should not contain /, ?, or #")
+
self.invoke(
model=model,
credentials=credentials,
diff --git a/api/core/model_runtime/model_providers/xinference/text_embedding/text_embedding.py b/api/core/model_runtime/model_providers/xinference/text_embedding/text_embedding.py
index a68bc999763..32d2b1516d3 100644
--- a/api/core/model_runtime/model_providers/xinference/text_embedding/text_embedding.py
+++ b/api/core/model_runtime/model_providers/xinference/text_embedding/text_embedding.py
@@ -113,6 +113,9 @@ class XinferenceTextEmbeddingModel(TextEmbeddingModel):
:return:
"""
try:
+ if "/" in credentials['model_uid'] or "?" in credentials['model_uid'] or "#" in credentials['model_uid']:
+ raise CredentialsValidateFailedError("model_uid should not contain /, ?, or #")
+
server_url = credentials['server_url']
model_uid = credentials['model_uid']
extra_args = XinferenceHelper.get_xinference_extra_parameter(server_url=server_url, model_uid=model_uid)