feat: Add support for custom embedding providers

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-02-09 23:52:10 +00:00
parent 318a3ad3e7
commit c9260b9bb1

View File

@@ -17,6 +17,7 @@ class EmbeddingConfigurator:
"bedrock": self._configure_bedrock,
"huggingface": self._configure_huggingface,
"watson": self._configure_watson,
"custom": self._configure_custom,
}
def configure_embedder(
@@ -182,6 +183,31 @@ class EmbeddingConfigurator:
url=config.get("api_url"),
)
@staticmethod
def _configure_custom(config, model_name):
"""Configure a custom embedding function.
Args:
config: Configuration dictionary containing:
- embedder: Custom EmbeddingFunction instance
model_name: Not used for custom embedders
Returns:
EmbeddingFunction: The validated custom embedding function
Raises:
ValueError: If embedder is missing or invalid
"""
embedder = config.get("embedder")
if not embedder or not isinstance(embedder, EmbeddingFunction):
raise ValueError("Custom provider requires a valid EmbeddingFunction instance")
try:
validate_embedding_function(embedder)
return embedder
except Exception as e:
raise ValueError(f"Invalid custom embedding function: {str(e)}")
@staticmethod
def _configure_watson(config, model_name):
try: