gllm-inference-binary 0.5.9__cp312-cp312-win_amd64.whl → 0.5.9b1__cp312-cp312-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of gllm-inference-binary might be problematic. Click here for more details.
- gllm_inference/builder/build_em_invoker.pyi +17 -2
- gllm_inference/builder/build_lm_invoker.pyi +13 -2
- gllm_inference/constants.pyi +2 -2
- gllm_inference/em_invoker/__init__.pyi +2 -1
- gllm_inference/em_invoker/azure_openai_em_invoker.pyi +7 -5
- gllm_inference/em_invoker/bedrock_em_invoker.pyi +106 -0
- gllm_inference/em_invoker/em_invoker.pyi +11 -4
- gllm_inference/em_invoker/google_em_invoker.pyi +8 -3
- gllm_inference/em_invoker/langchain/em_invoker_embeddings.pyi +25 -3
- gllm_inference/em_invoker/langchain_em_invoker.pyi +7 -2
- gllm_inference/em_invoker/openai_compatible_em_invoker.pyi +6 -2
- gllm_inference/em_invoker/openai_em_invoker.pyi +5 -1
- gllm_inference/em_invoker/schema/bedrock.pyi +22 -0
- gllm_inference/em_invoker/schema/google.pyi +2 -0
- gllm_inference/em_invoker/schema/langchain.pyi +1 -0
- gllm_inference/em_invoker/twelevelabs_em_invoker.pyi +5 -3
- gllm_inference/em_invoker/voyage_em_invoker.pyi +5 -2
- gllm_inference/exceptions/__init__.pyi +3 -3
- gllm_inference/exceptions/error_parser.pyi +26 -33
- gllm_inference/exceptions/exceptions.pyi +40 -28
- gllm_inference/exceptions/provider_error_map.pyi +23 -0
- gllm_inference/lm_invoker/__init__.pyi +2 -1
- gllm_inference/lm_invoker/azure_openai_lm_invoker.pyi +12 -13
- gllm_inference/lm_invoker/bedrock_lm_invoker.pyi +2 -0
- gllm_inference/lm_invoker/google_lm_invoker.pyi +8 -1
- gllm_inference/lm_invoker/langchain_lm_invoker.pyi +2 -0
- gllm_inference/lm_invoker/lm_invoker.pyi +7 -6
- gllm_inference/lm_invoker/openai_compatible_lm_invoker.pyi +1 -1
- gllm_inference/lm_invoker/openai_lm_invoker.pyi +7 -6
- gllm_inference/lm_invoker/schema/bedrock.pyi +5 -0
- gllm_inference/lm_invoker/schema/langchain.pyi +1 -0
- gllm_inference/lm_invoker/schema/openai.pyi +1 -0
- gllm_inference/lm_invoker/schema/openai_compatible.pyi +4 -0
- gllm_inference/lm_invoker/schema/xai.pyi +31 -0
- gllm_inference/lm_invoker/xai_lm_invoker.pyi +305 -0
- gllm_inference/request_processor/lm_request_processor.pyi +12 -3
- gllm_inference/request_processor/uses_lm_mixin.pyi +109 -29
- gllm_inference/schema/__init__.pyi +5 -4
- gllm_inference/schema/config.pyi +15 -0
- gllm_inference/schema/enums.pyi +5 -0
- gllm_inference/schema/model_id.pyi +10 -1
- gllm_inference/schema/token_usage.pyi +66 -2
- gllm_inference/schema/type_alias.pyi +1 -5
- gllm_inference/utils/__init__.pyi +2 -1
- gllm_inference/utils/io_utils.pyi +26 -0
- gllm_inference.cp312-win_amd64.pyd +0 -0
- gllm_inference.pyi +25 -12
- {gllm_inference_binary-0.5.9.dist-info → gllm_inference_binary-0.5.9b1.dist-info}/METADATA +71 -108
- {gllm_inference_binary-0.5.9.dist-info → gllm_inference_binary-0.5.9b1.dist-info}/RECORD +51 -43
- {gllm_inference_binary-0.5.9.dist-info → gllm_inference_binary-0.5.9b1.dist-info}/WHEEL +2 -1
- gllm_inference_binary-0.5.9b1.dist-info/top_level.txt +1 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from _typeshed import Incomplete
|
|
2
|
-
from gllm_inference.em_invoker import AzureOpenAIEMInvoker as AzureOpenAIEMInvoker, GoogleEMInvoker as GoogleEMInvoker, LangChainEMInvoker as LangChainEMInvoker, OpenAICompatibleEMInvoker as OpenAICompatibleEMInvoker, OpenAIEMInvoker as OpenAIEMInvoker, TwelveLabsEMInvoker as TwelveLabsEMInvoker, VoyageEMInvoker as VoyageEMInvoker
|
|
2
|
+
from gllm_inference.em_invoker import AzureOpenAIEMInvoker as AzureOpenAIEMInvoker, BedrockEMInvoker as BedrockEMInvoker, GoogleEMInvoker as GoogleEMInvoker, LangChainEMInvoker as LangChainEMInvoker, OpenAICompatibleEMInvoker as OpenAICompatibleEMInvoker, OpenAIEMInvoker as OpenAIEMInvoker, TwelveLabsEMInvoker as TwelveLabsEMInvoker, VoyageEMInvoker as VoyageEMInvoker
|
|
3
3
|
from gllm_inference.em_invoker.em_invoker import BaseEMInvoker as BaseEMInvoker
|
|
4
4
|
from gllm_inference.schema.model_id import ModelId as ModelId, ModelProvider as ModelProvider
|
|
5
5
|
from typing import Any
|
|
@@ -9,6 +9,7 @@ logger: Incomplete
|
|
|
9
9
|
|
|
10
10
|
class Key:
|
|
11
11
|
"""Defines valid keys in the config."""
|
|
12
|
+
ACCESS_KEY_ID: str
|
|
12
13
|
API_KEY: str
|
|
13
14
|
AZURE_DEPLOYMENT: str
|
|
14
15
|
AZURE_ENDPOINT: str
|
|
@@ -17,6 +18,7 @@ class Key:
|
|
|
17
18
|
MODEL_KWARGS: str
|
|
18
19
|
MODEL_NAME: str
|
|
19
20
|
MODEL_CLASS_PATH: str
|
|
21
|
+
SECRET_ACCESS_KEY: str
|
|
20
22
|
|
|
21
23
|
def build_em_invoker(model_id: str | ModelId, credentials: str | dict[str, Any] | None = None, config: dict[str, Any] | None = None) -> BaseEMInvoker:
|
|
22
24
|
'''Build an embedding model invoker based on the provided configurations.
|
|
@@ -41,6 +43,19 @@ def build_em_invoker(model_id: str | ModelId, credentials: str | dict[str, Any]
|
|
|
41
43
|
ValueError: If the provider is invalid.
|
|
42
44
|
|
|
43
45
|
Usage examples:
|
|
46
|
+
# Using Bedrock
|
|
47
|
+
```python
|
|
48
|
+
em_invoker = build_em_invoker(
|
|
49
|
+
model_id="bedrock/cohere.embed-english-v3",
|
|
50
|
+
credentials={
|
|
51
|
+
"access_key_id": "Abc123...",
|
|
52
|
+
"secret_access_key": "Xyz123...",
|
|
53
|
+
},
|
|
54
|
+
)
|
|
55
|
+
```
|
|
56
|
+
The credentials can also be provided through the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`
|
|
57
|
+
environment variables.
|
|
58
|
+
|
|
44
59
|
# Using Google Gen AI (via API key)
|
|
45
60
|
```python
|
|
46
61
|
em_invoker = build_em_invoker(
|
|
@@ -71,7 +86,7 @@ def build_em_invoker(model_id: str | ModelId, credentials: str | dict[str, Any]
|
|
|
71
86
|
# Using Azure OpenAI
|
|
72
87
|
```python
|
|
73
88
|
em_invoker = build_em_invoker(
|
|
74
|
-
model_id="azure-openai/https://my-resource.openai.azure.com:my-deployment",
|
|
89
|
+
model_id="azure-openai/https://my-resource.openai.azure.com/openai/v1:my-deployment",
|
|
75
90
|
credentials="azure-api-key"
|
|
76
91
|
)
|
|
77
92
|
```
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from _typeshed import Incomplete
|
|
2
|
-
from gllm_inference.lm_invoker import AnthropicLMInvoker as AnthropicLMInvoker, AzureOpenAILMInvoker as AzureOpenAILMInvoker, BedrockLMInvoker as BedrockLMInvoker, DatasaurLMInvoker as DatasaurLMInvoker, GoogleLMInvoker as GoogleLMInvoker, LangChainLMInvoker as LangChainLMInvoker, LiteLLMLMInvoker as LiteLLMLMInvoker, OpenAICompatibleLMInvoker as OpenAICompatibleLMInvoker, OpenAILMInvoker as OpenAILMInvoker
|
|
2
|
+
from gllm_inference.lm_invoker import AnthropicLMInvoker as AnthropicLMInvoker, AzureOpenAILMInvoker as AzureOpenAILMInvoker, BedrockLMInvoker as BedrockLMInvoker, DatasaurLMInvoker as DatasaurLMInvoker, GoogleLMInvoker as GoogleLMInvoker, LangChainLMInvoker as LangChainLMInvoker, LiteLLMLMInvoker as LiteLLMLMInvoker, OpenAICompatibleLMInvoker as OpenAICompatibleLMInvoker, OpenAILMInvoker as OpenAILMInvoker, XAILMInvoker as XAILMInvoker
|
|
3
3
|
from gllm_inference.lm_invoker.lm_invoker import BaseLMInvoker as BaseLMInvoker
|
|
4
4
|
from gllm_inference.schema.model_id import ModelId as ModelId, ModelProvider as ModelProvider
|
|
5
5
|
from typing import Any
|
|
@@ -107,7 +107,7 @@ def build_lm_invoker(model_id: str | ModelId, credentials: str | dict[str, Any]
|
|
|
107
107
|
# Using Azure OpenAI
|
|
108
108
|
```python
|
|
109
109
|
lm_invoker = build_lm_invoker(
|
|
110
|
-
model_id="azure-openai/https://my-resource.openai.azure.com:my-deployment",
|
|
110
|
+
model_id="azure-openai/https://my-resource.openai.azure.com/openai/v1:my-deployment",
|
|
111
111
|
credentials="azure-api-key"
|
|
112
112
|
)
|
|
113
113
|
```
|
|
@@ -144,6 +144,17 @@ def build_lm_invoker(model_id: str | ModelId, credentials: str | dict[str, Any]
|
|
|
144
144
|
For the list of supported providers, please refer to the following page:
|
|
145
145
|
https://docs.litellm.ai/docs/providers/
|
|
146
146
|
|
|
147
|
+
# Using xAI
|
|
148
|
+
```python
|
|
149
|
+
lm_invoker = build_lm_invoker(
|
|
150
|
+
model_id="xai/grok-3",
|
|
151
|
+
credentials="xai-..."
|
|
152
|
+
)
|
|
153
|
+
```
|
|
154
|
+
The credentials can also be provided through the `XAI_API_KEY` environment variable.
|
|
155
|
+
For the list of supported models, please refer to the following page:
|
|
156
|
+
https://docs.x.ai/docs/models
|
|
157
|
+
|
|
147
158
|
Security warning:
|
|
148
159
|
Please provide the LM invoker credentials ONLY to the `credentials` parameter. Do not put any kind of
|
|
149
160
|
credentials in the `config` parameter as the content of the `config` parameter will be logged.
|
gllm_inference/constants.pyi
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
from _typeshed import Incomplete
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
AZURE_OPENAI_URL_SUFFIX: str
|
|
4
4
|
DOCUMENT_MIME_TYPES: Incomplete
|
|
5
5
|
GOOGLE_SCOPES: Incomplete
|
|
6
|
+
GRPC_ENABLE_RETRIES_KEY: str
|
|
6
7
|
INVOKER_PROPAGATED_MAX_RETRIES: int
|
|
7
8
|
INVOKER_DEFAULT_TIMEOUT: float
|
|
8
9
|
HEX_REPR_LENGTH: int
|
|
9
|
-
HTTP_STATUS_CODE_PATTERNS: Incomplete
|
|
10
10
|
SECONDS_TO_MILLISECONDS: int
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from gllm_inference.em_invoker.azure_openai_em_invoker import AzureOpenAIEMInvoker as AzureOpenAIEMInvoker
|
|
2
|
+
from gllm_inference.em_invoker.bedrock_em_invoker import BedrockEMInvoker as BedrockEMInvoker
|
|
2
3
|
from gllm_inference.em_invoker.google_em_invoker import GoogleEMInvoker as GoogleEMInvoker
|
|
3
4
|
from gllm_inference.em_invoker.langchain_em_invoker import LangChainEMInvoker as LangChainEMInvoker
|
|
4
5
|
from gllm_inference.em_invoker.openai_compatible_em_invoker import OpenAICompatibleEMInvoker as OpenAICompatibleEMInvoker
|
|
@@ -6,4 +7,4 @@ from gllm_inference.em_invoker.openai_em_invoker import OpenAIEMInvoker as OpenA
|
|
|
6
7
|
from gllm_inference.em_invoker.twelevelabs_em_invoker import TwelveLabsEMInvoker as TwelveLabsEMInvoker
|
|
7
8
|
from gllm_inference.em_invoker.voyage_em_invoker import VoyageEMInvoker as VoyageEMInvoker
|
|
8
9
|
|
|
9
|
-
__all__ = ['AzureOpenAIEMInvoker', 'GoogleEMInvoker', 'LangChainEMInvoker', 'OpenAIEMInvoker', 'OpenAICompatibleEMInvoker', 'TwelveLabsEMInvoker', 'VoyageEMInvoker']
|
|
10
|
+
__all__ = ['AzureOpenAIEMInvoker', 'BedrockEMInvoker', 'GoogleEMInvoker', 'LangChainEMInvoker', 'OpenAIEMInvoker', 'OpenAICompatibleEMInvoker', 'TwelveLabsEMInvoker', 'VoyageEMInvoker']
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
from _typeshed import Incomplete
|
|
2
2
|
from gllm_core.utils.retry import RetryConfig as RetryConfig
|
|
3
|
-
from gllm_inference.constants import
|
|
3
|
+
from gllm_inference.constants import AZURE_OPENAI_URL_SUFFIX as AZURE_OPENAI_URL_SUFFIX, INVOKER_PROPAGATED_MAX_RETRIES as INVOKER_PROPAGATED_MAX_RETRIES
|
|
4
4
|
from gllm_inference.em_invoker.openai_em_invoker import OpenAIEMInvoker as OpenAIEMInvoker
|
|
5
5
|
from gllm_inference.em_invoker.schema.openai import Key as Key
|
|
6
|
-
from gllm_inference.schema import ModelId as ModelId, ModelProvider as ModelProvider
|
|
6
|
+
from gllm_inference.schema import ModelId as ModelId, ModelProvider as ModelProvider, TruncationConfig as TruncationConfig
|
|
7
7
|
from typing import Any
|
|
8
8
|
|
|
9
9
|
class AzureOpenAIEMInvoker(OpenAIEMInvoker):
|
|
@@ -16,6 +16,7 @@ class AzureOpenAIEMInvoker(OpenAIEMInvoker):
|
|
|
16
16
|
client (AsyncAzureOpenAI): The client for the Azure OpenAI API.
|
|
17
17
|
default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the embedding model.
|
|
18
18
|
retry_config (RetryConfig): The retry configuration for the embedding model.
|
|
19
|
+
truncation_config (TruncationConfig | None): The truncation configuration for the embedding model.
|
|
19
20
|
|
|
20
21
|
Input types:
|
|
21
22
|
The `AzureOpenAIEMInvoker` only supports text inputs.
|
|
@@ -68,7 +69,7 @@ class AzureOpenAIEMInvoker(OpenAIEMInvoker):
|
|
|
68
69
|
```
|
|
69
70
|
'''
|
|
70
71
|
client: Incomplete
|
|
71
|
-
def __init__(self, azure_endpoint: str, azure_deployment: str, api_key: str | None = None, api_version: str =
|
|
72
|
+
def __init__(self, azure_endpoint: str, azure_deployment: str, api_key: str | None = None, api_version: str | None = None, model_kwargs: dict[str, Any] | None = None, default_hyperparameters: dict[str, Any] | None = None, retry_config: RetryConfig | None = None, truncation_config: TruncationConfig | None = None) -> None:
|
|
72
73
|
"""Initializes a new instance of the AzureOpenAIEMInvoker class.
|
|
73
74
|
|
|
74
75
|
Args:
|
|
@@ -76,11 +77,12 @@ class AzureOpenAIEMInvoker(OpenAIEMInvoker):
|
|
|
76
77
|
azure_deployment (str): The deployment name of the Azure OpenAI service.
|
|
77
78
|
api_key (str | None, optional): The API key for authenticating with Azure OpenAI. Defaults to None, in
|
|
78
79
|
which case the `AZURE_OPENAI_API_KEY` environment variable will be used.
|
|
79
|
-
api_version (str, optional):
|
|
80
|
-
`DEFAULT_AZURE_OPENAI_API_VERSION`.
|
|
80
|
+
api_version (str | None, optional): Deprecated parameter to be removed in v0.6. Defaults to None.
|
|
81
81
|
model_kwargs (dict[str, Any] | None, optional): Additional model parameters. Defaults to None.
|
|
82
82
|
default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
|
|
83
83
|
Defaults to None.
|
|
84
84
|
retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
|
|
85
85
|
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
86
|
+
truncation_config (TruncationConfig | None, optional): Configuration for text truncation behavior.
|
|
87
|
+
Defaults to None, in which case no truncation is applied.
|
|
86
88
|
"""
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from enum import StrEnum
|
|
3
|
+
from gllm_core.utils.retry import RetryConfig as RetryConfig
|
|
4
|
+
from gllm_inference.em_invoker.em_invoker import BaseEMInvoker as BaseEMInvoker
|
|
5
|
+
from gllm_inference.em_invoker.schema.bedrock import InputType as InputType, Key as Key, OutputType as OutputType
|
|
6
|
+
from gllm_inference.exceptions import BaseInvokerError as BaseInvokerError, convert_http_status_to_base_invoker_error as convert_http_status_to_base_invoker_error
|
|
7
|
+
from gllm_inference.exceptions.provider_error_map import BEDROCK_ERROR_MAPPING as BEDROCK_ERROR_MAPPING
|
|
8
|
+
from gllm_inference.schema import ModelId as ModelId, ModelProvider as ModelProvider, TruncationConfig as TruncationConfig, Vector as Vector
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
class ModelType(StrEnum):
|
|
12
|
+
"""Defines the type of the Bedrock embedding model."""
|
|
13
|
+
COHERE = 'cohere'
|
|
14
|
+
TITAN = 'titan'
|
|
15
|
+
|
|
16
|
+
SUPPORTED_ATTACHMENTS: Incomplete
|
|
17
|
+
|
|
18
|
+
class BedrockEMInvoker(BaseEMInvoker):
|
|
19
|
+
'''An embedding model invoker to interact with AWS Bedrock embedding models.
|
|
20
|
+
|
|
21
|
+
Attributes:
|
|
22
|
+
model_id (str): The model ID of the embedding model.
|
|
23
|
+
model_provider (str): The provider of the embedding model.
|
|
24
|
+
model_name (str): The name of the embedding model.
|
|
25
|
+
session (Session): The Bedrock client session.
|
|
26
|
+
client_kwargs (dict[str, Any]): The Bedrock client kwargs.
|
|
27
|
+
default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the embedding model.
|
|
28
|
+
retry_config (RetryConfig): The retry configuration for the embedding model.
|
|
29
|
+
truncation_config (TruncationConfig | None): The truncation configuration for the embedding model.
|
|
30
|
+
|
|
31
|
+
Input types:
|
|
32
|
+
The `BedrockEMInvoker` only supports text inputs.
|
|
33
|
+
|
|
34
|
+
Output format:
|
|
35
|
+
The `BedrockEMInvoker` can embed either:
|
|
36
|
+
1. A single content.
|
|
37
|
+
1. A single content is a single text.
|
|
38
|
+
2. The output will be a `Vector`, representing the embedding of the content.
|
|
39
|
+
|
|
40
|
+
# Example 1: Embedding a text content.
|
|
41
|
+
```python
|
|
42
|
+
text = "This is a text"
|
|
43
|
+
result = await em_invoker.invoke(text)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The above examples will return a `Vector` with a size of (embedding_size,).
|
|
47
|
+
|
|
48
|
+
2. A list of contents.
|
|
49
|
+
1. A list of contents is a list of texts.
|
|
50
|
+
2. The output will be a `list[Vector]`, where each element is a `Vector` representing the
|
|
51
|
+
embedding of each single content.
|
|
52
|
+
|
|
53
|
+
# Example: Embedding a list of contents.
|
|
54
|
+
```python
|
|
55
|
+
text1 = "This is a text"
|
|
56
|
+
text2 = "This is another text"
|
|
57
|
+
text3 = "This is yet another text"
|
|
58
|
+
result = await em_invoker.invoke([text1, text2, text3])
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The above examples will return a `list[Vector]` with a size of (3, embedding_size).
|
|
62
|
+
|
|
63
|
+
Retry and timeout:
|
|
64
|
+
The `BedrockEMInvoker` supports retry and timeout configuration.
|
|
65
|
+
By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
|
|
66
|
+
They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
|
|
67
|
+
|
|
68
|
+
Retry config examples:
|
|
69
|
+
```python
|
|
70
|
+
retry_config = RetryConfig(max_retries=0, timeout=0.0) # No retry, no timeout
|
|
71
|
+
retry_config = RetryConfig(max_retries=0, timeout=10.0) # No retry, 10.0 seconds timeout
|
|
72
|
+
retry_config = RetryConfig(max_retries=5, timeout=0.0) # 5 max retries, no timeout
|
|
73
|
+
retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Usage example:
|
|
77
|
+
```python
|
|
78
|
+
em_invoker = BedrockEMInvoker(..., retry_config=retry_config)
|
|
79
|
+
```
|
|
80
|
+
'''
|
|
81
|
+
session: Incomplete
|
|
82
|
+
client_kwargs: Incomplete
|
|
83
|
+
def __init__(self, model_name: str, access_key_id: str | None = None, secret_access_key: str | None = None, region_name: str = 'us-east-1', model_kwargs: dict[str, Any] | None = None, default_hyperparameters: dict[str, Any] | None = None, retry_config: RetryConfig | None = None, truncation_config: TruncationConfig | None = None) -> None:
|
|
84
|
+
'''Initializes a new instance of the BedrockEMInvoker class.
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
model_name (str): The name of the Bedrock embedding model to be used.
|
|
88
|
+
access_key_id (str | None, optional): The AWS access key ID. Defaults to None, in which case
|
|
89
|
+
the `AWS_ACCESS_KEY_ID` environment variable will be used.
|
|
90
|
+
secret_access_key (str | None, optional): The AWS secret access key. Defaults to None, in which case
|
|
91
|
+
the `AWS_SECRET_ACCESS_KEY` environment variable will be used.
|
|
92
|
+
region_name (str, optional): The AWS region name. Defaults to "us-east-1".
|
|
93
|
+
model_kwargs (dict[str, Any] | None, optional): Additional keyword arguments for the Bedrock client.
|
|
94
|
+
Defaults to None.
|
|
95
|
+
default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
|
|
96
|
+
Defaults to None.
|
|
97
|
+
retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
|
|
98
|
+
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
99
|
+
truncation_config (TruncationConfig | None, optional): Configuration for text truncation behavior.
|
|
100
|
+
Defaults to None, in which case no truncation is applied.
|
|
101
|
+
|
|
102
|
+
Raises:
|
|
103
|
+
ValueError: If the model name is not supported.
|
|
104
|
+
ValueError: If `access_key_id` or `secret_access_key` is neither provided nor set in the
|
|
105
|
+
`AWS_ACCESS_KEY_ID` or `AWS_SECRET_ACCESS_KEY` environment variables, respectively.
|
|
106
|
+
'''
|
|
@@ -3,8 +3,8 @@ from _typeshed import Incomplete
|
|
|
3
3
|
from abc import ABC
|
|
4
4
|
from gllm_core.utils.retry import RetryConfig
|
|
5
5
|
from gllm_inference.constants import DOCUMENT_MIME_TYPES as DOCUMENT_MIME_TYPES, INVOKER_DEFAULT_TIMEOUT as INVOKER_DEFAULT_TIMEOUT
|
|
6
|
-
from gllm_inference.exceptions import
|
|
7
|
-
from gllm_inference.schema import Attachment as Attachment, AttachmentType as AttachmentType, EMContent as EMContent, ModelId as ModelId, Vector as Vector
|
|
6
|
+
from gllm_inference.exceptions import BaseInvokerError as BaseInvokerError, convert_to_base_invoker_error as convert_to_base_invoker_error
|
|
7
|
+
from gllm_inference.schema import Attachment as Attachment, AttachmentType as AttachmentType, EMContent as EMContent, ModelId as ModelId, TruncateSide as TruncateSide, TruncationConfig as TruncationConfig, Vector as Vector
|
|
8
8
|
from typing import Any
|
|
9
9
|
|
|
10
10
|
class BaseEMInvoker(ABC, metaclass=abc.ABCMeta):
|
|
@@ -16,12 +16,17 @@ class BaseEMInvoker(ABC, metaclass=abc.ABCMeta):
|
|
|
16
16
|
model_id (str): The model ID of the embedding model.
|
|
17
17
|
model_provider (str): The provider of the embedding model.
|
|
18
18
|
model_name (str): The name of the embedding model.
|
|
19
|
-
default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the
|
|
19
|
+
default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the
|
|
20
|
+
embedding model. Defaults to None, in which case an empty dictionary is used.
|
|
20
21
|
retry_config (RetryConfig): The retry configuration for the embedding model.
|
|
22
|
+
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
23
|
+
truncation_config (TruncationConfig | None): The truncation configuration for the embedding model.
|
|
24
|
+
Defaults to None, in which case no truncation is applied.
|
|
21
25
|
"""
|
|
22
26
|
default_hyperparameters: Incomplete
|
|
23
27
|
retry_config: Incomplete
|
|
24
|
-
|
|
28
|
+
truncation_config: Incomplete
|
|
29
|
+
def __init__(self, model_id: ModelId, default_hyperparameters: dict[str, Any] | None = None, supported_attachments: set[str] | None = None, retry_config: RetryConfig | None = None, truncation_config: TruncationConfig | None = None) -> None:
|
|
25
30
|
"""Initializes a new instance of the BaseEMInvoker class.
|
|
26
31
|
|
|
27
32
|
Args:
|
|
@@ -32,6 +37,8 @@ class BaseEMInvoker(ABC, metaclass=abc.ABCMeta):
|
|
|
32
37
|
in which case an empty set is used (indicating that no attachments are supported).
|
|
33
38
|
retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
|
|
34
39
|
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
40
|
+
truncation_config (TruncationConfig | None, optional): Configuration for text truncation behavior.
|
|
41
|
+
Defaults to None, in which case no truncation is applied.
|
|
35
42
|
"""
|
|
36
43
|
@property
|
|
37
44
|
def model_id(self) -> str:
|
|
@@ -3,7 +3,9 @@ from gllm_core.utils.retry import RetryConfig as RetryConfig
|
|
|
3
3
|
from gllm_inference.constants import GOOGLE_SCOPES as GOOGLE_SCOPES, SECONDS_TO_MILLISECONDS as SECONDS_TO_MILLISECONDS
|
|
4
4
|
from gllm_inference.em_invoker.em_invoker import BaseEMInvoker as BaseEMInvoker
|
|
5
5
|
from gllm_inference.em_invoker.schema.google import Key as Key
|
|
6
|
-
from gllm_inference.
|
|
6
|
+
from gllm_inference.exceptions import BaseInvokerError as BaseInvokerError, convert_http_status_to_base_invoker_error as convert_http_status_to_base_invoker_error
|
|
7
|
+
from gllm_inference.exceptions.provider_error_map import GOOGLE_ERROR_MAPPING as GOOGLE_ERROR_MAPPING
|
|
8
|
+
from gllm_inference.schema import ModelId as ModelId, ModelProvider as ModelProvider, TruncationConfig as TruncationConfig, Vector as Vector
|
|
7
9
|
from typing import Any
|
|
8
10
|
|
|
9
11
|
SUPPORTED_ATTACHMENTS: Incomplete
|
|
@@ -17,7 +19,8 @@ class GoogleEMInvoker(BaseEMInvoker):
|
|
|
17
19
|
model_name (str): The name of the embedding model.
|
|
18
20
|
client_params (dict[str, Any]): The Google client instance init parameters.
|
|
19
21
|
default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the embedding model.
|
|
20
|
-
retry_config (RetryConfig
|
|
22
|
+
retry_config (RetryConfig): The retry configuration for the embedding model.
|
|
23
|
+
truncation_config (TruncationConfig | None): The truncation configuration for the embedding model.
|
|
21
24
|
|
|
22
25
|
Initialization:
|
|
23
26
|
The `GoogleEMInvoker` can use either Google Gen AI or Google Vertex AI.
|
|
@@ -98,7 +101,7 @@ class GoogleEMInvoker(BaseEMInvoker):
|
|
|
98
101
|
```
|
|
99
102
|
'''
|
|
100
103
|
client_params: Incomplete
|
|
101
|
-
def __init__(self, model_name: str, api_key: str | None = None, credentials_path: str | None = None, project_id: str | None = None, location: str = 'us-central1', model_kwargs: dict[str, Any] | None = None, default_hyperparameters: dict[str, Any] | None = None, retry_config: RetryConfig | None = None) -> None:
|
|
104
|
+
def __init__(self, model_name: str, api_key: str | None = None, credentials_path: str | None = None, project_id: str | None = None, location: str = 'us-central1', model_kwargs: dict[str, Any] | None = None, default_hyperparameters: dict[str, Any] | None = None, retry_config: RetryConfig | None = None, truncation_config: TruncationConfig | None = None) -> None:
|
|
102
105
|
'''Initializes a new instance of the GoogleEMInvoker class.
|
|
103
106
|
|
|
104
107
|
Args:
|
|
@@ -117,6 +120,8 @@ class GoogleEMInvoker(BaseEMInvoker):
|
|
|
117
120
|
Defaults to None.
|
|
118
121
|
retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
|
|
119
122
|
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
123
|
+
truncation_config (TruncationConfig | None, optional): Configuration for text truncation behavior.
|
|
124
|
+
Defaults to None, in which case no truncation is applied.
|
|
120
125
|
|
|
121
126
|
Note:
|
|
122
127
|
If neither `api_key` nor `credentials_path` is provided, Google Gen AI will be used by default.
|
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
from gllm_inference.em_invoker.em_invoker import BaseEMInvoker as BaseEMInvoker
|
|
2
|
-
from gllm_inference.schema import Vector as Vector
|
|
2
|
+
from gllm_inference.schema import Attachment as Attachment, Vector as Vector
|
|
3
|
+
from gllm_inference.utils.io_utils import DEFAULT_BASE64_ALLOWED_MIMETYPES as DEFAULT_BASE64_ALLOWED_MIMETYPES, base64_to_bytes as base64_to_bytes
|
|
3
4
|
from langchain_core.embeddings import Embeddings
|
|
4
5
|
from pydantic import BaseModel
|
|
5
6
|
from typing import Any
|
|
6
7
|
|
|
7
8
|
class EMInvokerEmbeddings(BaseModel, Embeddings, arbitrary_types_allowed=True):
|
|
8
|
-
|
|
9
|
+
'''An adapter class that enables an `EMInvoker` to be used as a LangChain `Embeddings`.
|
|
9
10
|
|
|
10
11
|
Attributes:
|
|
11
12
|
em_invoker (BaseEMInvoker): The `EMInvoker` instance to be interacted with.
|
|
13
|
+
use_base64 (bool):
|
|
14
|
+
Whether to apply strict base64 encoding to the input.
|
|
15
|
+
1, If `True`, only inputs with specific MIME types (e.g. images,
|
|
16
|
+
audio, and video) will be converted into base64 strings before being sent.
|
|
17
|
+
2. If `False`, each input is treated as a raw string.
|
|
18
|
+
|
|
19
|
+
This ensures "strict" handling: base64 encoding is not applied
|
|
20
|
+
universally, but only when required for those MIME types.
|
|
12
21
|
|
|
13
22
|
Usage example:
|
|
14
23
|
```python
|
|
@@ -18,8 +27,9 @@ class EMInvokerEmbeddings(BaseModel, Embeddings, arbitrary_types_allowed=True):
|
|
|
18
27
|
em_invoker = OpenAIEMInvoker(...)
|
|
19
28
|
embeddings = EMInvokerEmbeddings(em_invoker=em_invoker)
|
|
20
29
|
```
|
|
21
|
-
|
|
30
|
+
'''
|
|
22
31
|
em_invoker: BaseEMInvoker
|
|
32
|
+
use_base64: bool
|
|
23
33
|
async def aembed_documents(self, texts: list[str], **kwargs: Any) -> list[Vector]:
|
|
24
34
|
"""Asynchronously embed documents using the `EMInvoker`.
|
|
25
35
|
|
|
@@ -29,6 +39,9 @@ class EMInvokerEmbeddings(BaseModel, Embeddings, arbitrary_types_allowed=True):
|
|
|
29
39
|
|
|
30
40
|
Returns:
|
|
31
41
|
list[Vector]: List of embeddings, one for each text.
|
|
42
|
+
|
|
43
|
+
Raises:
|
|
44
|
+
ValueError: If `texts` is not a list of strings.
|
|
32
45
|
"""
|
|
33
46
|
async def aembed_query(self, text: str, **kwargs: Any) -> Vector:
|
|
34
47
|
"""Asynchronously embed query using the `EMInvoker`.
|
|
@@ -39,6 +52,9 @@ class EMInvokerEmbeddings(BaseModel, Embeddings, arbitrary_types_allowed=True):
|
|
|
39
52
|
|
|
40
53
|
Returns:
|
|
41
54
|
Vector: Embeddings for the text.
|
|
55
|
+
|
|
56
|
+
Raises:
|
|
57
|
+
ValueError: If `text` is not a string.
|
|
42
58
|
"""
|
|
43
59
|
def embed_documents(self, texts: list[str], **kwargs: Any) -> list[Vector]:
|
|
44
60
|
"""Embed documents using the `EMInvoker`.
|
|
@@ -49,6 +65,9 @@ class EMInvokerEmbeddings(BaseModel, Embeddings, arbitrary_types_allowed=True):
|
|
|
49
65
|
|
|
50
66
|
Returns:
|
|
51
67
|
list[Vector]: List of embeddings, one for each text.
|
|
68
|
+
|
|
69
|
+
Raises:
|
|
70
|
+
ValueError: If `texts` is not a list of strings.
|
|
52
71
|
"""
|
|
53
72
|
def embed_query(self, text: str, **kwargs: Any) -> Vector:
|
|
54
73
|
"""Embed query using the `EMInvoker`.
|
|
@@ -59,4 +78,7 @@ class EMInvokerEmbeddings(BaseModel, Embeddings, arbitrary_types_allowed=True):
|
|
|
59
78
|
|
|
60
79
|
Returns:
|
|
61
80
|
Vector: Embeddings for the text.
|
|
81
|
+
|
|
82
|
+
Raises:
|
|
83
|
+
ValueError: If `text` is not a string.
|
|
62
84
|
"""
|
|
@@ -3,7 +3,9 @@ from gllm_core.utils.retry import RetryConfig
|
|
|
3
3
|
from gllm_inference.constants import INVOKER_DEFAULT_TIMEOUT as INVOKER_DEFAULT_TIMEOUT, INVOKER_PROPAGATED_MAX_RETRIES as INVOKER_PROPAGATED_MAX_RETRIES
|
|
4
4
|
from gllm_inference.em_invoker.em_invoker import BaseEMInvoker as BaseEMInvoker
|
|
5
5
|
from gllm_inference.em_invoker.schema.langchain import Key as Key
|
|
6
|
-
from gllm_inference.
|
|
6
|
+
from gllm_inference.exceptions import BaseInvokerError as BaseInvokerError, InvokerRuntimeError as InvokerRuntimeError, build_debug_info as build_debug_info
|
|
7
|
+
from gllm_inference.exceptions.provider_error_map import ALL_PROVIDER_ERROR_MAPPINGS as ALL_PROVIDER_ERROR_MAPPINGS, LANGCHAIN_ERROR_CODE_MAPPING as LANGCHAIN_ERROR_CODE_MAPPING
|
|
8
|
+
from gllm_inference.schema import ModelId as ModelId, ModelProvider as ModelProvider, TruncationConfig as TruncationConfig, Vector as Vector
|
|
7
9
|
from gllm_inference.utils import load_langchain_model as load_langchain_model, parse_model_data as parse_model_data
|
|
8
10
|
from langchain_core.embeddings import Embeddings as Embeddings
|
|
9
11
|
from typing import Any
|
|
@@ -19,9 +21,10 @@ class LangChainEMInvoker(BaseEMInvoker):
|
|
|
19
21
|
model_name (str): The name of the embedding model.
|
|
20
22
|
em (Embeddings): The instance to interact with an embedding model defined using LangChain's Embeddings.
|
|
21
23
|
retry_config (RetryConfig): The retry configuration for the embedding model.
|
|
24
|
+
truncation_config (TruncationConfig | None): The truncation configuration for the embedding model.
|
|
22
25
|
"""
|
|
23
26
|
model: Incomplete
|
|
24
|
-
def __init__(self, model: Embeddings | None = None, model_class_path: str | None = None, model_name: str | None = None, model_kwargs: dict[str, Any] | None = None, default_hyperparameters: dict[str, Any] | None = None, retry_config: RetryConfig | None = None) -> None:
|
|
27
|
+
def __init__(self, model: Embeddings | None = None, model_class_path: str | None = None, model_name: str | None = None, model_kwargs: dict[str, Any] | None = None, default_hyperparameters: dict[str, Any] | None = None, retry_config: RetryConfig | None = None, truncation_config: TruncationConfig | None = None) -> None:
|
|
25
28
|
'''Initializes a new instance of the LangChainEMInvoker class.
|
|
26
29
|
|
|
27
30
|
Args:
|
|
@@ -38,4 +41,6 @@ class LangChainEMInvoker(BaseEMInvoker):
|
|
|
38
41
|
Defaults to None.
|
|
39
42
|
retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
|
|
40
43
|
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
44
|
+
truncation_config (TruncationConfig | None, optional): Configuration for text truncation behavior.
|
|
45
|
+
Defaults to None, in which case no truncation is applied.
|
|
41
46
|
'''
|
|
@@ -3,7 +3,7 @@ from gllm_core.utils.retry import RetryConfig as RetryConfig
|
|
|
3
3
|
from gllm_inference.constants import INVOKER_PROPAGATED_MAX_RETRIES as INVOKER_PROPAGATED_MAX_RETRIES
|
|
4
4
|
from gllm_inference.em_invoker.openai_em_invoker import OpenAIEMInvoker as OpenAIEMInvoker
|
|
5
5
|
from gllm_inference.em_invoker.schema.openai_compatible import Key as Key
|
|
6
|
-
from gllm_inference.schema import ModelId as ModelId, ModelProvider as ModelProvider
|
|
6
|
+
from gllm_inference.schema import ModelId as ModelId, ModelProvider as ModelProvider, TruncationConfig as TruncationConfig
|
|
7
7
|
from typing import Any
|
|
8
8
|
|
|
9
9
|
class OpenAICompatibleEMInvoker(OpenAIEMInvoker):
|
|
@@ -16,6 +16,8 @@ class OpenAICompatibleEMInvoker(OpenAIEMInvoker):
|
|
|
16
16
|
client (AsyncOpenAI): The OpenAI client instance.
|
|
17
17
|
default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the embedding model.
|
|
18
18
|
retry_config (RetryConfig): The retry configuration for the embedding model.
|
|
19
|
+
truncation_config (TruncationConfig | None): The truncation configuration for the embedding model.
|
|
20
|
+
|
|
19
21
|
|
|
20
22
|
When to use:
|
|
21
23
|
The `OpenAICompatibleEMInvoker` is designed to interact with endpoints that are compatible with OpenAI\'s
|
|
@@ -76,7 +78,7 @@ class OpenAICompatibleEMInvoker(OpenAIEMInvoker):
|
|
|
76
78
|
```
|
|
77
79
|
'''
|
|
78
80
|
client: Incomplete
|
|
79
|
-
def __init__(self, model_name: str, base_url: str, api_key: str | None = None, model_kwargs: dict[str, Any] | None = None, default_hyperparameters: dict[str, Any] | None = None, retry_config: RetryConfig | None = None) -> None:
|
|
81
|
+
def __init__(self, model_name: str, base_url: str, api_key: str | None = None, model_kwargs: dict[str, Any] | None = None, default_hyperparameters: dict[str, Any] | None = None, retry_config: RetryConfig | None = None, truncation_config: TruncationConfig | None = None) -> None:
|
|
80
82
|
"""Initializes a new instance of the OpenAICompatibleEMInvoker class.
|
|
81
83
|
|
|
82
84
|
Args:
|
|
@@ -89,4 +91,6 @@ class OpenAICompatibleEMInvoker(OpenAIEMInvoker):
|
|
|
89
91
|
Defaults to None.
|
|
90
92
|
retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
|
|
91
93
|
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
94
|
+
truncation_config (TruncationConfig | None, optional): Configuration for text truncation behavior.
|
|
95
|
+
Defaults to None, in which case no truncation is applied.
|
|
92
96
|
"""
|
|
@@ -4,6 +4,7 @@ from gllm_inference.constants import INVOKER_PROPAGATED_MAX_RETRIES as INVOKER_P
|
|
|
4
4
|
from gllm_inference.em_invoker.em_invoker import BaseEMInvoker as BaseEMInvoker
|
|
5
5
|
from gllm_inference.em_invoker.schema.openai import Key as Key
|
|
6
6
|
from gllm_inference.schema import ModelId as ModelId, ModelProvider as ModelProvider, Vector as Vector
|
|
7
|
+
from gllm_inference.schema.config import TruncationConfig as TruncationConfig
|
|
7
8
|
from typing import Any
|
|
8
9
|
|
|
9
10
|
SUPPORTED_ATTACHMENTS: Incomplete
|
|
@@ -18,6 +19,7 @@ class OpenAIEMInvoker(BaseEMInvoker):
|
|
|
18
19
|
client (AsyncOpenAI): The client for the OpenAI API.
|
|
19
20
|
default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the embedding model.
|
|
20
21
|
retry_config (RetryConfig): The retry configuration for the embedding model.
|
|
22
|
+
truncation_config (TruncationConfig | None): The truncation configuration for the embedding model.
|
|
21
23
|
|
|
22
24
|
Input types:
|
|
23
25
|
The `OpenAIEMInvoker` only supports text inputs.
|
|
@@ -70,7 +72,7 @@ class OpenAIEMInvoker(BaseEMInvoker):
|
|
|
70
72
|
```
|
|
71
73
|
'''
|
|
72
74
|
client: Incomplete
|
|
73
|
-
def __init__(self, model_name: str, api_key: str | None = None, model_kwargs: dict[str, Any] | None = None, default_hyperparameters: dict[str, Any] | None = None, retry_config: RetryConfig | None = None) -> None:
|
|
75
|
+
def __init__(self, model_name: str, api_key: str | None = None, model_kwargs: dict[str, Any] | None = None, default_hyperparameters: dict[str, Any] | None = None, retry_config: RetryConfig | None = None, truncation_config: TruncationConfig | None = None) -> None:
|
|
74
76
|
"""Initializes a new instance of the OpenAIEMInvoker class.
|
|
75
77
|
|
|
76
78
|
Args:
|
|
@@ -83,4 +85,6 @@ class OpenAIEMInvoker(BaseEMInvoker):
|
|
|
83
85
|
Defaults to None.
|
|
84
86
|
retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
|
|
85
87
|
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
88
|
+
truncation_config (TruncationConfig | None, optional): Configuration for text truncation behavior.
|
|
89
|
+
Defaults to None, in which case no truncation is applied.
|
|
86
90
|
"""
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
class Key:
|
|
2
|
+
"""Defines valid keys in Bedrock."""
|
|
3
|
+
ACCEPT: str
|
|
4
|
+
CONTENT_TYPE: str
|
|
5
|
+
HTTP_STATUS_CODE: str
|
|
6
|
+
INPUT_TEXT: str
|
|
7
|
+
INPUT_TYPE: str
|
|
8
|
+
MODEL_ID: str
|
|
9
|
+
RESPONSE_METADATA: str
|
|
10
|
+
TEXTS: str
|
|
11
|
+
|
|
12
|
+
class InputType:
|
|
13
|
+
"""Defines valid input types in Bedrock."""
|
|
14
|
+
APPLICATION_JSON: str
|
|
15
|
+
SEARCH_DOCUMENT: str
|
|
16
|
+
SEARCH_QUERY: str
|
|
17
|
+
|
|
18
|
+
class OutputType:
|
|
19
|
+
"""Defines valid output types in Bedrock."""
|
|
20
|
+
BODY: str
|
|
21
|
+
EMBEDDING: str
|
|
22
|
+
EMBEDDINGS: str
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
from _typeshed import Incomplete
|
|
2
2
|
from gllm_core.utils.retry import RetryConfig as RetryConfig
|
|
3
|
-
from gllm_inference.constants import INVOKER_PROPAGATED_MAX_RETRIES as INVOKER_PROPAGATED_MAX_RETRIES
|
|
4
3
|
from gllm_inference.em_invoker.em_invoker import BaseEMInvoker as BaseEMInvoker
|
|
5
4
|
from gllm_inference.em_invoker.schema.twelvelabs import InputType as InputType, Key as Key, OutputType as OutputType
|
|
6
|
-
from gllm_inference.schema import Attachment as Attachment, AttachmentType as AttachmentType, EMContent as EMContent, ModelId as ModelId, ModelProvider as ModelProvider, Vector as Vector
|
|
5
|
+
from gllm_inference.schema import Attachment as Attachment, AttachmentType as AttachmentType, EMContent as EMContent, ModelId as ModelId, ModelProvider as ModelProvider, TruncationConfig as TruncationConfig, Vector as Vector
|
|
7
6
|
from typing import Any
|
|
8
7
|
|
|
9
8
|
SUPPORTED_ATTACHMENTS: Incomplete
|
|
@@ -18,6 +17,7 @@ class TwelveLabsEMInvoker(BaseEMInvoker):
|
|
|
18
17
|
client (Client): The client for the TwelveLabs API.
|
|
19
18
|
default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the embedding model.
|
|
20
19
|
retry_config (RetryConfig): The retry configuration for the embedding model.
|
|
20
|
+
truncation_config (TruncationConfig | None): The truncation configuration for the embedding model.
|
|
21
21
|
|
|
22
22
|
Input types:
|
|
23
23
|
The `TwelveLabsEMInvoker` supports the following input types: text, audio, and image.
|
|
@@ -83,7 +83,7 @@ class TwelveLabsEMInvoker(BaseEMInvoker):
|
|
|
83
83
|
```
|
|
84
84
|
'''
|
|
85
85
|
client: Incomplete
|
|
86
|
-
def __init__(self, model_name: str, api_key: str | None = None, model_kwargs: dict[str, Any] | None = None, default_hyperparameters: dict[str, Any] | None = None, retry_config: RetryConfig | None = None) -> None:
|
|
86
|
+
def __init__(self, model_name: str, api_key: str | None = None, model_kwargs: dict[str, Any] | None = None, default_hyperparameters: dict[str, Any] | None = None, retry_config: RetryConfig | None = None, truncation_config: TruncationConfig | None = None) -> None:
|
|
87
87
|
"""Initializes a new instance of the TwelveLabsEMInvoker class.
|
|
88
88
|
|
|
89
89
|
Args:
|
|
@@ -96,4 +96,6 @@ class TwelveLabsEMInvoker(BaseEMInvoker):
|
|
|
96
96
|
Defaults to None.
|
|
97
97
|
retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
|
|
98
98
|
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
99
|
+
truncation_config (TruncationConfig | None, optional): Configuration for text truncation behavior.
|
|
100
|
+
Defaults to None, in which case no truncation is applied.
|
|
99
101
|
"""
|
|
@@ -3,7 +3,7 @@ from gllm_core.utils.retry import RetryConfig as RetryConfig
|
|
|
3
3
|
from gllm_inference.constants import INVOKER_PROPAGATED_MAX_RETRIES as INVOKER_PROPAGATED_MAX_RETRIES
|
|
4
4
|
from gllm_inference.em_invoker.em_invoker import BaseEMInvoker as BaseEMInvoker
|
|
5
5
|
from gllm_inference.em_invoker.schema.voyage import InputType as InputType, Key as Key
|
|
6
|
-
from gllm_inference.schema import Attachment as Attachment, AttachmentType as AttachmentType, EMContent as EMContent, ModelId as ModelId, ModelProvider as ModelProvider, Vector as Vector
|
|
6
|
+
from gllm_inference.schema import Attachment as Attachment, AttachmentType as AttachmentType, EMContent as EMContent, ModelId as ModelId, ModelProvider as ModelProvider, TruncationConfig as TruncationConfig, Vector as Vector
|
|
7
7
|
from typing import Any
|
|
8
8
|
|
|
9
9
|
SUPPORTED_ATTACHMENTS: Incomplete
|
|
@@ -19,6 +19,7 @@ class VoyageEMInvoker(BaseEMInvoker):
|
|
|
19
19
|
client (Client): The client for the Voyage API.
|
|
20
20
|
default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the embedding model.
|
|
21
21
|
retry_config (RetryConfig): The retry configuration for the embedding model.
|
|
22
|
+
truncation_config (TruncationConfig | None): The truncation configuration for the embedding model.
|
|
22
23
|
|
|
23
24
|
Input types:
|
|
24
25
|
The `VoyageEMInvoker` supports the following input types: text, image, and a tuple containing text and image.
|
|
@@ -85,7 +86,7 @@ class VoyageEMInvoker(BaseEMInvoker):
|
|
|
85
86
|
```
|
|
86
87
|
'''
|
|
87
88
|
client: Incomplete
|
|
88
|
-
def __init__(self, model_name: str, api_key: str | None = None, model_kwargs: dict[str, Any] | None = None, default_hyperparameters: dict[str, Any] | None = None, retry_config: RetryConfig | None = None) -> None:
|
|
89
|
+
def __init__(self, model_name: str, api_key: str | None = None, model_kwargs: dict[str, Any] | None = None, default_hyperparameters: dict[str, Any] | None = None, retry_config: RetryConfig | None = None, truncation_config: TruncationConfig | None = None) -> None:
|
|
89
90
|
"""Initializes a new instance of the VoyageEMInvoker class.
|
|
90
91
|
|
|
91
92
|
Args:
|
|
@@ -98,4 +99,6 @@ class VoyageEMInvoker(BaseEMInvoker):
|
|
|
98
99
|
Defaults to None.
|
|
99
100
|
retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
|
|
100
101
|
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
102
|
+
truncation_config (TruncationConfig | None, optional): Configuration for text truncation behavior.
|
|
103
|
+
Defaults to None, in which case no truncation is applied.
|
|
101
104
|
"""
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from gllm_inference.exceptions.error_parser import
|
|
2
|
-
from gllm_inference.exceptions.exceptions import BaseInvokerError as BaseInvokerError, InvokerRuntimeError as InvokerRuntimeError, ModelNotFoundError as ModelNotFoundError, ProviderAuthError as ProviderAuthError, ProviderInternalError as ProviderInternalError, ProviderInvalidArgsError as ProviderInvalidArgsError, ProviderOverloadedError as ProviderOverloadedError, ProviderRateLimitError as ProviderRateLimitError
|
|
1
|
+
from gllm_inference.exceptions.error_parser import _get_exception_key as _get_exception_key, build_debug_info as build_debug_info, convert_http_status_to_base_invoker_error as convert_http_status_to_base_invoker_error, convert_to_base_invoker_error as convert_to_base_invoker_error
|
|
2
|
+
from gllm_inference.exceptions.exceptions import APIConnectionError as APIConnectionError, APITimeoutError as APITimeoutError, BaseInvokerError as BaseInvokerError, InvokerRuntimeError as InvokerRuntimeError, ModelNotFoundError as ModelNotFoundError, ProviderAuthError as ProviderAuthError, ProviderConflictError as ProviderConflictError, ProviderInternalError as ProviderInternalError, ProviderInvalidArgsError as ProviderInvalidArgsError, ProviderOverloadedError as ProviderOverloadedError, ProviderRateLimitError as ProviderRateLimitError
|
|
3
3
|
|
|
4
|
-
__all__ = ['
|
|
4
|
+
__all__ = ['_get_exception_key', 'APIConnectionError', 'APITimeoutError', 'BaseInvokerError', 'InvokerRuntimeError', 'ModelNotFoundError', 'ProviderAuthError', 'ProviderConflictError', 'ProviderInternalError', 'ProviderInvalidArgsError', 'ProviderOverloadedError', 'ProviderRateLimitError', 'build_debug_info', 'convert_http_status_to_base_invoker_error', 'convert_to_base_invoker_error']
|