|
|
|
@ -1,7 +1,5 @@
|
|
|
|
from typing import Optional
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
|
|
|
|
from yarl import URL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from core.entities.embedding_type import EmbeddingInputType
|
|
|
|
from core.entities.embedding_type import EmbeddingInputType
|
|
|
|
from core.model_runtime.entities.text_embedding_entities import (
|
|
|
|
from core.model_runtime.entities.text_embedding_entities import (
|
|
|
|
TextEmbeddingResult,
|
|
|
|
TextEmbeddingResult,
|
|
|
|
@ -24,12 +22,15 @@ class GPUStackTextEmbeddingModel(OAICompatEmbeddingModel):
|
|
|
|
user: Optional[str] = None,
|
|
|
|
user: Optional[str] = None,
|
|
|
|
input_type: EmbeddingInputType = EmbeddingInputType.DOCUMENT,
|
|
|
|
input_type: EmbeddingInputType = EmbeddingInputType.DOCUMENT,
|
|
|
|
) -> TextEmbeddingResult:
|
|
|
|
) -> TextEmbeddingResult:
|
|
|
|
return super()._invoke(model, credentials, texts, user, input_type)
|
|
|
|
compatible_credentials = self._get_compatible_credentials(credentials)
|
|
|
|
|
|
|
|
return super()._invoke(model, compatible_credentials, texts, user, input_type)
|
|
|
|
|
|
|
|
|
|
|
|
def validate_credentials(self, model: str, credentials: dict) -> None:
|
|
|
|
def validate_credentials(self, model: str, credentials: dict) -> None:
|
|
|
|
self._add_custom_parameters(credentials)
|
|
|
|
compatible_credentials = self._get_compatible_credentials(credentials)
|
|
|
|
super().validate_credentials(model, credentials)
|
|
|
|
super().validate_credentials(model, compatible_credentials)
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _get_compatible_credentials(self, credentials: dict) -> dict:
|
|
|
|
def _add_custom_parameters(credentials: dict) -> None:
|
|
|
|
credentials = credentials.copy()
|
|
|
|
credentials["endpoint_url"] = str(URL(credentials["endpoint_url"]) / "v1-openai")
|
|
|
|
base_url = credentials["endpoint_url"].rstrip("/").removesuffix("/v1-openai")
|
|
|
|
|
|
|
|
credentials["endpoint_url"] = f"{base_url}/v1-openai"
|
|
|
|
|
|
|
|
return credentials
|
|
|
|
|