Spaces:
Sleeping
Sleeping
Download omagent_core/models/encoders/azure_encoder.py from omlab/OmAgentVideoUnderstanding: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/spaces/omlab/OmAgentVideoUnderstanding/resolve/main/omagent_core/models/encoders/azure_encoder.py
- Command line
-
hf download hf://spaces/omlab/OmAgentVideoUnderstanding/omagent_core/models/encoders/azure_encoder.py
-
curl -L -o azure_encoder.py https://huggingface.co/spaces/omlab/OmAgentVideoUnderstanding/resolve/main/omagent_core/models/encoders/azure_encoder.py
1.2 kB
| from typing import Any, List | |
| from openai import AsyncAzureOpenAI, AzureOpenAI | |
| from ...utils.registry import registry | |
| from .base import EncoderBase | |
| class AzureTextEmbeddingV3(EncoderBase): | |
| model_id: str = "text-embedding-3-large" | |
| api_key: str | |
| dim: int = 3072 | |
| api_version: str | |
| class Config: | |
| """Configuration for this pydantic object.""" | |
| protected_namespaces = () | |
| extra = "allow" | |
| def __init__(self, /, **data: Any) -> None: | |
| super().__init__(**data) | |
| self.client = AzureOpenAI(azure_endpoint=self.endpoint, api_key=self.api_key, api_version=self.api_version) | |
| self.aclient = AsyncAzureOpenAI(azure_endpoint=self.endpoint, api_key=self.api_key, api_version=self.api_version) | |
| def _infer(self, data: List[str], **kwargs) -> List[List[float]]: | |
| res = self.client.embeddings.create(input=data, model=self.model_id) | |
| return [item.embedding for item in res.data] | |
| async def _ainfer(self, data: List[str], **kwargs) -> List[List[float]]: | |
| res = await self.aclient.embeddings.create(input=data, model=self.model_id) | |
| return [item.embedding for item in res.data] | |