Spaces:
Sleeping
Sleeping
韩宇 commited on
Commit ·
8746c2a
1
Parent(s): 2841423
opt
Browse files
configs/llms/text_encoder.yml
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
-
name:
|
| 2 |
endpoint: ${env| custom_openai_endpoint, https://api.openai.com/v1}
|
| 3 |
api_key: ${env| custom_openai_key, openai_api_key}
|
|
|
|
| 1 |
+
name: AzureTextEmbeddingV3
|
| 2 |
endpoint: ${env| custom_openai_endpoint, https://api.openai.com/v1}
|
| 3 |
api_key: ${env| custom_openai_key, openai_api_key}
|
omagent_core/models/encoders/azure_encoder.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, List
|
| 2 |
+
|
| 3 |
+
from openai import AsyncAzureOpenAI, AzureOpenAI
|
| 4 |
+
|
| 5 |
+
from ...utils.registry import registry
|
| 6 |
+
from .base import EncoderBase
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
@registry.register_encoder()
|
| 10 |
+
class AzureTextEmbeddingV3(EncoderBase):
|
| 11 |
+
model_id: str = "text-embedding-3-large"
|
| 12 |
+
api_key: str
|
| 13 |
+
dim: int = 3072
|
| 14 |
+
|
| 15 |
+
class Config:
|
| 16 |
+
"""Configuration for this pydantic object."""
|
| 17 |
+
|
| 18 |
+
protected_namespaces = ()
|
| 19 |
+
extra = "allow"
|
| 20 |
+
|
| 21 |
+
def __init__(self, /, **data: Any) -> None:
|
| 22 |
+
super().__init__(**data)
|
| 23 |
+
self.client = AzureOpenAI(base_url=self.endpoint, api_key=self.api_key)
|
| 24 |
+
self.aclient = AsyncAzureOpenAI(base_url=self.endpoint, api_key=self.api_key)
|
| 25 |
+
|
| 26 |
+
def _infer(self, data: List[str], **kwargs) -> List[List[float]]:
|
| 27 |
+
res = self.client.embeddings.create(input=data, model=self.model_id)
|
| 28 |
+
return [item.embedding for item in res.data]
|
| 29 |
+
|
| 30 |
+
async def _ainfer(self, data: List[str], **kwargs) -> List[List[float]]:
|
| 31 |
+
res = await self.aclient.embeddings.create(input=data, model=self.model_id)
|
| 32 |
+
return [item.embedding for item in res.data]
|
webpage_configs/llms/text_encoder.yml
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
-
name:
|
| 2 |
endpoint: ${env| custom_openai_endpoint, https://api.openai.com/v1}
|
| 3 |
api_key: ${env| custom_openai_key, openai_api_key}
|
|
|
|
| 1 |
+
name: AzureTextEmbeddingV3
|
| 2 |
endpoint: ${env| custom_openai_endpoint, https://api.openai.com/v1}
|
| 3 |
api_key: ${env| custom_openai_key, openai_api_key}
|