Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/dify_plugin/core/entities/plugin/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,10 @@ class ModelGetLLMNumTokens(PluginAccessModelRequest, PromptMessageMixin):

class ModelInvokeTextEmbeddingRequest(PluginAccessModelRequest):
action: ModelActions = ModelActions.InvokeTextEmbedding
model_type: ModelType = ModelType.TEXT_EMBEDDING

texts: list[str]
input_type: EmbeddingInputType = EmbeddingInputType.DOCUMENT
Comment on lines 208 to +212

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with ModelInvokeMultimodalEmbeddingRequest and to simplify usage, model_type should have a default value of ModelType.TEXT_EMBEDDING. This avoids requiring callers to explicitly provide the model type for an action that is specific to text embeddings.

Suggested change
action: ModelActions = ModelActions.InvokeTextEmbedding
texts: list[str]
input_type: EmbeddingInputType = EmbeddingInputType.DOCUMENT
action: ModelActions = ModelActions.InvokeTextEmbedding
model_type: ModelType = ModelType.TEXT_EMBEDDING
texts: list[str]
input_type: EmbeddingInputType = EmbeddingInputType.DOCUMENT



class ModelInvokeMultimodalEmbeddingRequest(PluginAccessModelRequest):
Expand Down
3 changes: 2 additions & 1 deletion src/dify_plugin/core/plugin_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ def invoke_text_embedding(
data.model,
data.credentials,
data.texts,
data.user_id,
user=data.user_id,
input_type=data.input_type,
)
msg = f"Model `{data.model_type}` not found for provider `{data.provider}`"
raise ValueError(
Expand Down
33 changes: 33 additions & 0 deletions tests/entities/plugin/test_model_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from dify_plugin.core.entities.plugin.request import ModelActions, ModelInvokeTextEmbeddingRequest, PluginInvokeType
from dify_plugin.entities.model import EmbeddingInputType, ModelType


def test_text_embedding_request_accepts_input_type() -> None:
request = ModelInvokeTextEmbeddingRequest(
type=PluginInvokeType.Model,
action=ModelActions.InvokeTextEmbedding,
user_id="user-id",
provider="provider",
model_type=ModelType.TEXT_EMBEDDING,
model="embedding-model",
credentials={},
texts=["query text"],
input_type=EmbeddingInputType.QUERY,
)

assert request.input_type == EmbeddingInputType.QUERY


def test_text_embedding_request_defaults_input_type_to_document() -> None:
request = ModelInvokeTextEmbeddingRequest(
type=PluginInvokeType.Model,
action=ModelActions.InvokeTextEmbedding,
user_id="user-id",
provider="provider",
model="embedding-model",
credentials={},
texts=["document text"],
)

assert request.model_type == ModelType.TEXT_EMBEDDING
assert request.input_type == EmbeddingInputType.DOCUMENT