12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- from typing import Optional
- import numpy as np
- from dify_plugin.entities.model import EmbeddingInputType
- from dify_plugin.errors.model import CredentialsValidateFailedError
- from dify_plugin.entities.model.text_embedding import (
- TextEmbeddingResult,
- )
- class {{ .PluginName | SnakeToCamel }}TextEmbeddingModel(TextEmbeddingModel):
- """
- Model class for {{ .PluginName }} text embedding model.
- """
- def _invoke(
- self,
- model: str,
- credentials: dict,
- texts: list[str],
- user: Optional[str] = None,
- input_type: EmbeddingInputType = EmbeddingInputType.DOCUMENT,
- ) -> TextEmbeddingResult:
- """
- Invoke text embedding model
- :param model: model name
- :param credentials: model credentials
- :param texts: texts to embed
- :param user: unique user id
- :return: embeddings result
- """
- pass
- def get_num_tokens(self, model: str, credentials: dict, texts: list[str]) -> int:
- """
- Get number of tokens for given prompt messages
- :param model: model name
- :param credentials: model credentials
- :param texts: texts to embed
- :return:
- """
- return 0
- def validate_credentials(self, model: str, credentials: dict) -> None:
- """
- Validate model credentials
- :param model: model name
- :param credentials: model credentials
- :return:
- """
- try:
- pass
- except Exception as ex:
- raise CredentialsValidateFailedError(str(ex))
|