gllm-inference-binary 0.5.9__py3-none-any.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/__init__.pyi +0 -0
- gllm_inference/builder/__init__.pyi +6 -0
- gllm_inference/builder/build_em_invoker.pyi +122 -0
- gllm_inference/builder/build_lm_invoker.pyi +150 -0
- gllm_inference/builder/build_lm_request_processor.pyi +93 -0
- gllm_inference/builder/build_output_parser.pyi +29 -0
- gllm_inference/catalog/__init__.pyi +4 -0
- gllm_inference/catalog/catalog.pyi +121 -0
- gllm_inference/catalog/lm_request_processor_catalog.pyi +112 -0
- gllm_inference/catalog/prompt_builder_catalog.pyi +82 -0
- gllm_inference/constants.pyi +10 -0
- gllm_inference/em_invoker/__init__.pyi +9 -0
- gllm_inference/em_invoker/azure_openai_em_invoker.pyi +86 -0
- gllm_inference/em_invoker/em_invoker.pyi +83 -0
- gllm_inference/em_invoker/google_em_invoker.pyi +124 -0
- gllm_inference/em_invoker/langchain/__init__.pyi +3 -0
- gllm_inference/em_invoker/langchain/em_invoker_embeddings.pyi +62 -0
- gllm_inference/em_invoker/langchain_em_invoker.pyi +41 -0
- gllm_inference/em_invoker/openai_compatible_em_invoker.pyi +92 -0
- gllm_inference/em_invoker/openai_em_invoker.pyi +86 -0
- gllm_inference/em_invoker/schema/__init__.pyi +0 -0
- gllm_inference/em_invoker/schema/google.pyi +7 -0
- gllm_inference/em_invoker/schema/langchain.pyi +4 -0
- gllm_inference/em_invoker/schema/openai.pyi +7 -0
- gllm_inference/em_invoker/schema/openai_compatible.pyi +7 -0
- gllm_inference/em_invoker/schema/twelvelabs.pyi +17 -0
- gllm_inference/em_invoker/schema/voyage.pyi +15 -0
- gllm_inference/em_invoker/twelevelabs_em_invoker.pyi +99 -0
- gllm_inference/em_invoker/voyage_em_invoker.pyi +101 -0
- gllm_inference/exceptions/__init__.pyi +4 -0
- gllm_inference/exceptions/error_parser.pyi +48 -0
- gllm_inference/exceptions/exceptions.pyi +120 -0
- gllm_inference/lm_invoker/__init__.pyi +11 -0
- gllm_inference/lm_invoker/anthropic_lm_invoker.pyi +275 -0
- gllm_inference/lm_invoker/azure_openai_lm_invoker.pyi +253 -0
- gllm_inference/lm_invoker/bedrock_lm_invoker.pyi +232 -0
- gllm_inference/lm_invoker/datasaur_lm_invoker.pyi +166 -0
- gllm_inference/lm_invoker/google_lm_invoker.pyi +310 -0
- gllm_inference/lm_invoker/langchain_lm_invoker.pyi +258 -0
- gllm_inference/lm_invoker/litellm_lm_invoker.pyi +248 -0
- gllm_inference/lm_invoker/lm_invoker.pyi +151 -0
- gllm_inference/lm_invoker/openai_compatible_lm_invoker.pyi +265 -0
- gllm_inference/lm_invoker/openai_lm_invoker.pyi +361 -0
- gllm_inference/lm_invoker/schema/__init__.pyi +0 -0
- gllm_inference/lm_invoker/schema/anthropic.pyi +50 -0
- gllm_inference/lm_invoker/schema/bedrock.pyi +48 -0
- gllm_inference/lm_invoker/schema/datasaur.pyi +12 -0
- gllm_inference/lm_invoker/schema/google.pyi +24 -0
- gllm_inference/lm_invoker/schema/langchain.pyi +22 -0
- gllm_inference/lm_invoker/schema/openai.pyi +90 -0
- gllm_inference/lm_invoker/schema/openai_compatible.pyi +56 -0
- gllm_inference/model/__init__.pyi +9 -0
- gllm_inference/model/em/__init__.pyi +0 -0
- gllm_inference/model/em/google_em.pyi +16 -0
- gllm_inference/model/em/openai_em.pyi +15 -0
- gllm_inference/model/em/twelvelabs_em.pyi +13 -0
- gllm_inference/model/em/voyage_em.pyi +20 -0
- gllm_inference/model/lm/__init__.pyi +0 -0
- gllm_inference/model/lm/anthropic_lm.pyi +20 -0
- gllm_inference/model/lm/google_lm.pyi +17 -0
- gllm_inference/model/lm/openai_lm.pyi +27 -0
- gllm_inference/output_parser/__init__.pyi +3 -0
- gllm_inference/output_parser/json_output_parser.pyi +60 -0
- gllm_inference/output_parser/output_parser.pyi +27 -0
- gllm_inference/prompt_builder/__init__.pyi +3 -0
- gllm_inference/prompt_builder/prompt_builder.pyi +56 -0
- gllm_inference/prompt_formatter/__init__.pyi +7 -0
- gllm_inference/prompt_formatter/agnostic_prompt_formatter.pyi +49 -0
- gllm_inference/prompt_formatter/huggingface_prompt_formatter.pyi +55 -0
- gllm_inference/prompt_formatter/llama_prompt_formatter.pyi +59 -0
- gllm_inference/prompt_formatter/mistral_prompt_formatter.pyi +53 -0
- gllm_inference/prompt_formatter/openai_prompt_formatter.pyi +35 -0
- gllm_inference/prompt_formatter/prompt_formatter.pyi +30 -0
- gllm_inference/request_processor/__init__.pyi +4 -0
- gllm_inference/request_processor/lm_request_processor.pyi +92 -0
- gllm_inference/request_processor/uses_lm_mixin.pyi +50 -0
- gllm_inference/schema/__init__.pyi +13 -0
- gllm_inference/schema/attachment.pyi +88 -0
- gllm_inference/schema/code_exec_result.pyi +14 -0
- gllm_inference/schema/enums.pyi +24 -0
- gllm_inference/schema/lm_output.pyi +36 -0
- gllm_inference/schema/message.pyi +52 -0
- gllm_inference/schema/model_id.pyi +138 -0
- gllm_inference/schema/reasoning.pyi +15 -0
- gllm_inference/schema/token_usage.pyi +11 -0
- gllm_inference/schema/tool_call.pyi +14 -0
- gllm_inference/schema/tool_result.pyi +11 -0
- gllm_inference/schema/type_alias.pyi +15 -0
- gllm_inference/utils/__init__.pyi +4 -0
- gllm_inference/utils/langchain.pyi +30 -0
- gllm_inference/utils/validation.pyi +12 -0
- gllm_inference_binary-0.5.9.dist-info/METADATA +108 -0
- gllm_inference_binary-0.5.9.dist-info/RECORD +94 -0
- gllm_inference_binary-0.5.9.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
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
|
+
from gllm_inference.em_invoker.em_invoker import BaseEMInvoker as BaseEMInvoker
|
|
5
|
+
from gllm_inference.em_invoker.schema.openai import Key as Key
|
|
6
|
+
from gllm_inference.schema import ModelId as ModelId, ModelProvider as ModelProvider, Vector as Vector
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
SUPPORTED_ATTACHMENTS: Incomplete
|
|
10
|
+
|
|
11
|
+
class OpenAIEMInvoker(BaseEMInvoker):
|
|
12
|
+
'''An embedding model invoker to interact with OpenAI embedding models.
|
|
13
|
+
|
|
14
|
+
Attributes:
|
|
15
|
+
model_id (str): The model ID of the embedding model.
|
|
16
|
+
model_provider (str): The provider of the embedding model.
|
|
17
|
+
model_name (str): The name of the embedding model.
|
|
18
|
+
client (AsyncOpenAI): The client for the OpenAI API.
|
|
19
|
+
default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the embedding model.
|
|
20
|
+
retry_config (RetryConfig): The retry configuration for the embedding model.
|
|
21
|
+
|
|
22
|
+
Input types:
|
|
23
|
+
The `OpenAIEMInvoker` only supports text inputs.
|
|
24
|
+
|
|
25
|
+
Output format:
|
|
26
|
+
The `OpenAIEMInvoker` can embed either:
|
|
27
|
+
1. A single content.
|
|
28
|
+
1. A single content is a single text.
|
|
29
|
+
2. The output will be a `Vector`, representing the embedding of the content.
|
|
30
|
+
|
|
31
|
+
# Example 1: Embedding a text content.
|
|
32
|
+
```python
|
|
33
|
+
text = "This is a text"
|
|
34
|
+
result = await em_invoker.invoke(text)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The above examples will return a `Vector` with a size of (embedding_size,).
|
|
38
|
+
|
|
39
|
+
2. A list of contents.
|
|
40
|
+
1. A list of contents is a list of texts.
|
|
41
|
+
2. The output will be a `list[Vector]`, where each element is a `Vector` representing the
|
|
42
|
+
embedding of each single content.
|
|
43
|
+
|
|
44
|
+
# Example: Embedding a list of contents.
|
|
45
|
+
```python
|
|
46
|
+
text1 = "This is a text"
|
|
47
|
+
text2 = "This is another text"
|
|
48
|
+
text3 = "This is yet another text"
|
|
49
|
+
result = await em_invoker.invoke([text1, text2, text3])
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The above examples will return a `list[Vector]` with a size of (3, embedding_size).
|
|
53
|
+
|
|
54
|
+
Retry and timeout:
|
|
55
|
+
The `OpenAIEMInvoker` supports retry and timeout configuration.
|
|
56
|
+
By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
|
|
57
|
+
They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
|
|
58
|
+
|
|
59
|
+
Retry config examples:
|
|
60
|
+
```python
|
|
61
|
+
retry_config = RetryConfig(max_retries=0, timeout=0.0) # No retry, no timeout
|
|
62
|
+
retry_config = RetryConfig(max_retries=0, timeout=10.0) # No retry, 10.0 seconds timeout
|
|
63
|
+
retry_config = RetryConfig(max_retries=5, timeout=0.0) # 5 max retries, no timeout
|
|
64
|
+
retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Usage example:
|
|
68
|
+
```python
|
|
69
|
+
em_invoker = OpenAIEMInvoker(..., retry_config=retry_config)
|
|
70
|
+
```
|
|
71
|
+
'''
|
|
72
|
+
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:
|
|
74
|
+
"""Initializes a new instance of the OpenAIEMInvoker class.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
model_name (str): The name of the OpenAI embedding model to be used.
|
|
78
|
+
api_key (str | None, optional): The API key for the OpenAI API. Defaults to None, in which
|
|
79
|
+
case the `OPENAI_API_KEY` environment variable will be used.
|
|
80
|
+
model_kwargs (dict[str, Any] | None, optional): Additional keyword arguments for the OpenAI client.
|
|
81
|
+
Defaults to None.
|
|
82
|
+
default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
|
|
83
|
+
Defaults to None.
|
|
84
|
+
retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
|
|
85
|
+
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
86
|
+
"""
|
|
File without changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
class Key:
|
|
2
|
+
"""Defines valid keys in TwelveLabs."""
|
|
3
|
+
INPUT_KEY: str
|
|
4
|
+
MAX_RETRIES: str
|
|
5
|
+
OUTPUT_KEY: str
|
|
6
|
+
TIMEOUT: str
|
|
7
|
+
VALUE: str
|
|
8
|
+
|
|
9
|
+
class InputType:
|
|
10
|
+
"""Defines valid input types in TwelveLabs."""
|
|
11
|
+
FILE_SUFFIX: str
|
|
12
|
+
TEXT: str
|
|
13
|
+
|
|
14
|
+
class OutputType:
|
|
15
|
+
"""Defines valid output types in TwelveLabs."""
|
|
16
|
+
EMBEDDING_SUFFIX: str
|
|
17
|
+
TEXT_EMBEDDING: str
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class Key:
|
|
2
|
+
"""Defines valid keys in Voyage."""
|
|
3
|
+
API_KEY: str
|
|
4
|
+
CONTENT: str
|
|
5
|
+
IMAGE_BASE64: str
|
|
6
|
+
MAX_RETRIES: str
|
|
7
|
+
MODEL: str
|
|
8
|
+
TEXT: str
|
|
9
|
+
TIMEOUT: str
|
|
10
|
+
TYPE: str
|
|
11
|
+
|
|
12
|
+
class InputType:
|
|
13
|
+
"""Defines valid input types in Voyage."""
|
|
14
|
+
IMAGE_BASE64: str
|
|
15
|
+
TEXT: str
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
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
|
+
from gllm_inference.em_invoker.em_invoker import BaseEMInvoker as BaseEMInvoker
|
|
5
|
+
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
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
SUPPORTED_ATTACHMENTS: Incomplete
|
|
10
|
+
|
|
11
|
+
class TwelveLabsEMInvoker(BaseEMInvoker):
|
|
12
|
+
'''An embedding model invoker to interact with TwelveLabs embedding models.
|
|
13
|
+
|
|
14
|
+
Attributes:
|
|
15
|
+
model_id (str): The model ID of the embedding model.
|
|
16
|
+
model_provider (str): The provider of the embedding model.
|
|
17
|
+
model_name (str): The name of the embedding model.
|
|
18
|
+
client (Client): The client for the TwelveLabs API.
|
|
19
|
+
default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the embedding model.
|
|
20
|
+
retry_config (RetryConfig): The retry configuration for the embedding model.
|
|
21
|
+
|
|
22
|
+
Input types:
|
|
23
|
+
The `TwelveLabsEMInvoker` supports the following input types: text, audio, and image.
|
|
24
|
+
Non-text inputs must be passed as a `Attachment` object.
|
|
25
|
+
|
|
26
|
+
Output format:
|
|
27
|
+
The `TwelveLabsEMInvoker` can embed either:
|
|
28
|
+
1. A single content.
|
|
29
|
+
1. A single content is either a text, an audio, or an image.
|
|
30
|
+
2. The output will be a `Vector`, representing the embedding of the content.
|
|
31
|
+
|
|
32
|
+
# Example 1: Embedding a text content.
|
|
33
|
+
```python
|
|
34
|
+
text = "What animal is in this image?"
|
|
35
|
+
result = await em_invoker.invoke(text)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
# Example 2: Embedding an audio content.
|
|
39
|
+
```python
|
|
40
|
+
audio = Attachment.from_path("path/to/local/audio.mp3")
|
|
41
|
+
result = await em_invoker.invoke(audio)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
# Example 3: Embedding an image content.
|
|
45
|
+
```python
|
|
46
|
+
image = Attachment.from_path("path/to/local/image.png")
|
|
47
|
+
result = await em_invoker.invoke(image)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The above examples will return a `Vector` with a size of (embedding_size,).
|
|
51
|
+
|
|
52
|
+
2. A list of contents.
|
|
53
|
+
1. A list of contents is a list that consists of any of the above single contents.
|
|
54
|
+
2. The output will be a `list[Vector]`, where each element is a `Vector` representing the
|
|
55
|
+
embedding of each single content.
|
|
56
|
+
|
|
57
|
+
# Example: Embedding a list of contents.
|
|
58
|
+
```python
|
|
59
|
+
text = "What animal is in this image?"
|
|
60
|
+
audio = Attachment.from_path("path/to/local/audio.mp3")
|
|
61
|
+
image = Attachment.from_path("path/to/local/image.png")
|
|
62
|
+
result = await em_invoker.invoke([text, audio, image])
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The above examples will return a `list[Vector]` with a size of (3, embedding_size).
|
|
66
|
+
|
|
67
|
+
Retry and timeout:
|
|
68
|
+
The `TwelveLabsEMInvoker` supports retry and timeout configuration.
|
|
69
|
+
By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
|
|
70
|
+
They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
|
|
71
|
+
|
|
72
|
+
Retry config examples:
|
|
73
|
+
```python
|
|
74
|
+
retry_config = RetryConfig(max_retries=0, timeout=0.0) # No retry, no timeout
|
|
75
|
+
retry_config = RetryConfig(max_retries=0, timeout=10.0) # No retry, 10.0 seconds timeout
|
|
76
|
+
retry_config = RetryConfig(max_retries=5, timeout=0.0) # 5 max retries, no timeout
|
|
77
|
+
retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Usage example:
|
|
81
|
+
```python
|
|
82
|
+
em_invoker = TwelveLabsEMInvoker(..., retry_config=retry_config)
|
|
83
|
+
```
|
|
84
|
+
'''
|
|
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:
|
|
87
|
+
"""Initializes a new instance of the TwelveLabsEMInvoker class.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
model_name (str): The name of the TwelveLabs embedding model to be used.
|
|
91
|
+
api_key (str | None, optional): The API key for the TwelveLabs API. Defaults to None, in which
|
|
92
|
+
case the `TWELVELABS_API_KEY` environment variable will be used.
|
|
93
|
+
model_kwargs (dict[str, Any] | None, optional): Additional keyword arguments for the TwelveLabs 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
|
+
"""
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
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
|
+
from gllm_inference.em_invoker.em_invoker import BaseEMInvoker as BaseEMInvoker
|
|
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
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
SUPPORTED_ATTACHMENTS: Incomplete
|
|
10
|
+
MAX_PYTHON_MINOR_VERSION: int
|
|
11
|
+
|
|
12
|
+
class VoyageEMInvoker(BaseEMInvoker):
|
|
13
|
+
'''An embedding model invoker to interact with Voyage embedding models.
|
|
14
|
+
|
|
15
|
+
Attributes:
|
|
16
|
+
model_id (str): The model ID of the embedding model.
|
|
17
|
+
model_provider (str): The provider of the embedding model.
|
|
18
|
+
model_name (str): The name of the embedding model.
|
|
19
|
+
client (Client): The client for the Voyage API.
|
|
20
|
+
default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the embedding model.
|
|
21
|
+
retry_config (RetryConfig): The retry configuration for the embedding model.
|
|
22
|
+
|
|
23
|
+
Input types:
|
|
24
|
+
The `VoyageEMInvoker` supports the following input types: text, image, and a tuple containing text and image.
|
|
25
|
+
Non-text inputs must be passed as a `Attachment` object.
|
|
26
|
+
|
|
27
|
+
Output format:
|
|
28
|
+
The `VoyageEMInvoker` can embed either:
|
|
29
|
+
1. A single content.
|
|
30
|
+
1. A single content is either a text, an image, or a tuple containing a text and an image.
|
|
31
|
+
2. The output will be a `Vector`, representing the embedding of the content.
|
|
32
|
+
|
|
33
|
+
# Example 1: Embedding a text content.
|
|
34
|
+
```python
|
|
35
|
+
text = "What animal is in this image?"
|
|
36
|
+
result = await em_invoker.invoke(text)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
# Example 2: Embedding an image content.
|
|
40
|
+
```python
|
|
41
|
+
image = Attachment.from_path("path/to/local/image.png")
|
|
42
|
+
result = await em_invoker.invoke(image)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
# Example 3: Embedding a tuple containing a text and an image.
|
|
46
|
+
```python
|
|
47
|
+
text = "What animal is in this image?"
|
|
48
|
+
image = Attachment.from_path("path/to/local/image.png")
|
|
49
|
+
result = await em_invoker.invoke((text, image))
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The above examples will return a `Vector` with a size of (embedding_size,).
|
|
53
|
+
|
|
54
|
+
2. A list of contents.
|
|
55
|
+
1. A list of contents is a list that consists of any of the above single contents.
|
|
56
|
+
2. The output will be a `list[Vector]`, where each element is a `Vector` representing the
|
|
57
|
+
embedding of each single content.
|
|
58
|
+
|
|
59
|
+
# Example: Embedding a list of contents.
|
|
60
|
+
```python
|
|
61
|
+
text = "What animal is in this image?"
|
|
62
|
+
image = Attachment.from_path("path/to/local/image.png")
|
|
63
|
+
mix_content = (text, image)
|
|
64
|
+
result = await em_invoker.invoke([text, image, mix_content])
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The above examples will return a `list[Vector]` with a size of (3, embedding_size).
|
|
68
|
+
|
|
69
|
+
Retry and timeout:
|
|
70
|
+
The `VoyageEMInvoker` supports retry and timeout configuration.
|
|
71
|
+
By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
|
|
72
|
+
They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
|
|
73
|
+
|
|
74
|
+
Retry config examples:
|
|
75
|
+
```python
|
|
76
|
+
retry_config = RetryConfig(max_retries=0, timeout=0.0) # No retry, no timeout
|
|
77
|
+
retry_config = RetryConfig(max_retries=0, timeout=10.0) # No retry, 10.0 seconds timeout
|
|
78
|
+
retry_config = RetryConfig(max_retries=5, timeout=0.0) # 5 max retries, no timeout
|
|
79
|
+
retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Usage example:
|
|
83
|
+
```python
|
|
84
|
+
em_invoker = VoyageEMInvoker(..., retry_config=retry_config)
|
|
85
|
+
```
|
|
86
|
+
'''
|
|
87
|
+
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
|
+
"""Initializes a new instance of the VoyageEMInvoker class.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
model_name (str): The name of the Voyage embedding model to be used.
|
|
93
|
+
api_key (str | None, optional): The API key for the Voyage API. Defaults to None, in which
|
|
94
|
+
case the `VOYAGE_API_KEY` environment variable will be used.
|
|
95
|
+
model_kwargs (dict[str, Any] | None, optional): Additional keyword arguments for the Voyage client.
|
|
96
|
+
Defaults to None.
|
|
97
|
+
default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
|
|
98
|
+
Defaults to None.
|
|
99
|
+
retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
|
|
100
|
+
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
101
|
+
"""
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
from gllm_inference.exceptions.error_parser import ExtendedHTTPStatus as ExtendedHTTPStatus, HTTP_STATUS_TO_EXCEPTION_MAP as HTTP_STATUS_TO_EXCEPTION_MAP, extract_http_status_code as extract_http_status_code, parse_error_message as parse_error_message
|
|
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
|
|
3
|
+
|
|
4
|
+
__all__ = ['HTTP_STATUS_TO_EXCEPTION_MAP', 'BaseInvokerError', 'ExtendedHTTPStatus', 'InvokerRuntimeError', 'ModelNotFoundError', 'ProviderAuthError', 'ProviderInternalError', 'ProviderInvalidArgsError', 'ProviderOverloadedError', 'ProviderRateLimitError', 'extract_http_status_code', 'parse_error_message']
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from enum import IntEnum
|
|
2
|
+
from gllm_inference.constants import HTTP_STATUS_CODE_PATTERNS as HTTP_STATUS_CODE_PATTERNS
|
|
3
|
+
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
|
|
4
|
+
from gllm_inference.schema import ErrorResponse as ErrorResponse
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
class ExtendedHTTPStatus(IntEnum):
|
|
8
|
+
"""HTTP status codes outside of the standard HTTPStatus enum.
|
|
9
|
+
|
|
10
|
+
Attributes:
|
|
11
|
+
SERVICE_OVERLOADED (int): HTTP status code for service overloaded.
|
|
12
|
+
"""
|
|
13
|
+
SERVICE_OVERLOADED = 529
|
|
14
|
+
|
|
15
|
+
HTTP_STATUS_TO_EXCEPTION_MAP: dict[int, type[BaseInvokerError]]
|
|
16
|
+
|
|
17
|
+
def extract_http_status_code(response: ErrorResponse) -> int | None:
|
|
18
|
+
'''Extract HTTP status code from error message.
|
|
19
|
+
|
|
20
|
+
This function extracts the HTTP status code from the error message. For example,
|
|
21
|
+
if the error message is "Error code: 401 - Invalid API key", "HTTP 429 Rate limit exceeded",
|
|
22
|
+
or "status: 500 Internal server error", the function will return "401", "429", or "500" respectively.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
response (ErrorResponse): The response object or error message containing HTTP status code.
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
int | None: The extracted HTTP status code, or None if not found.
|
|
29
|
+
'''
|
|
30
|
+
def parse_error_message(class_name: str, error: Any) -> BaseInvokerError:
|
|
31
|
+
"""Parse error from different AI providers and return appropriate exception type.
|
|
32
|
+
|
|
33
|
+
This function analyzes the error message and HTTP status code to determine
|
|
34
|
+
the most appropriate exception type to return.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
class_name (str): Class name to include in the error message for clarity.
|
|
38
|
+
error (Any): The error object or message from the AI provider.
|
|
39
|
+
Can be an Exception object, Response object, ClientResponse object, string, or dict
|
|
40
|
+
that might contain HTTP status information.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
BaseInvokerError: The appropriate exception instance based on error analysis.
|
|
44
|
+
|
|
45
|
+
Raises:
|
|
46
|
+
CancelledError: If the original error is a CancelledError.
|
|
47
|
+
TimeoutError: If the original error is a TimeoutError.
|
|
48
|
+
"""
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
class BaseInvokerError(Exception):
|
|
5
|
+
"""Base exception class for all gllm_inference invoker errors."""
|
|
6
|
+
debug_info: Incomplete
|
|
7
|
+
class_name: Incomplete
|
|
8
|
+
def __init__(self, class_name: str, message: str, debug_info: dict[str, Any] | None = None) -> None:
|
|
9
|
+
"""Initialize the base exception.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
class_name (str): The name of the class that raised the error.
|
|
13
|
+
message (str): The error message.
|
|
14
|
+
debug_info (dict[str, Any] | None, optional): Additional debug information for developers.
|
|
15
|
+
Defaults to None.
|
|
16
|
+
"""
|
|
17
|
+
def verbose(self) -> str:
|
|
18
|
+
"""Verbose error message with debug information.
|
|
19
|
+
|
|
20
|
+
Returns:
|
|
21
|
+
str: The verbose error message with debug information.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
class ProviderInvalidArgsError(BaseInvokerError):
|
|
25
|
+
"""Exception for bad or malformed requests, invalid parameters or structure.
|
|
26
|
+
|
|
27
|
+
Corresponds to HTTP 400 status code.
|
|
28
|
+
"""
|
|
29
|
+
def __init__(self, class_name: str, debug_info: dict[str, Any] | None = None) -> None:
|
|
30
|
+
"""Initialize ProviderInvalidArgsError.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
class_name (str): The name of the class that raised the error.
|
|
34
|
+
debug_info (dict[str, Any] | None, optional): Additional debug information for developers.
|
|
35
|
+
Defaults to None.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
class ProviderAuthError(BaseInvokerError):
|
|
39
|
+
"""Exception for authorization failures due to API key issues.
|
|
40
|
+
|
|
41
|
+
Corresponds to HTTP 401-403 status codes.
|
|
42
|
+
"""
|
|
43
|
+
def __init__(self, class_name: str, debug_info: dict[str, Any] | None = None) -> None:
|
|
44
|
+
"""Initialize ProviderAuthError.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
class_name (str): The name of the class that raised the error.
|
|
48
|
+
debug_info (dict[str, Any] | None, optional): Additional debug information for developers.
|
|
49
|
+
Defaults to None.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
class ProviderRateLimitError(BaseInvokerError):
|
|
53
|
+
"""Exception for rate limit violations.
|
|
54
|
+
|
|
55
|
+
Corresponds to HTTP 429 status code.
|
|
56
|
+
"""
|
|
57
|
+
def __init__(self, class_name: str, debug_info: dict[str, Any] | None = None) -> None:
|
|
58
|
+
"""Initialize ProviderRateLimitError.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
class_name (str): The name of the class that raised the error.
|
|
62
|
+
debug_info (dict[str, Any] | None, optional): Additional debug information for developers.
|
|
63
|
+
Defaults to None.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
class ProviderInternalError(BaseInvokerError):
|
|
67
|
+
"""Exception for unexpected server-side errors.
|
|
68
|
+
|
|
69
|
+
Corresponds to HTTP 500 status code.
|
|
70
|
+
"""
|
|
71
|
+
def __init__(self, class_name: str, debug_info: dict[str, Any] | None = None) -> None:
|
|
72
|
+
"""Initialize ProviderInternalError.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
class_name (str): The name of the class that raised the error.
|
|
76
|
+
debug_info (dict[str, Any] | None, optional): Additional debug information for developers.
|
|
77
|
+
Defaults to None.
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
class ProviderOverloadedError(BaseInvokerError):
|
|
81
|
+
"""Exception for when the engine is currently overloaded.
|
|
82
|
+
|
|
83
|
+
Corresponds to HTTP 503, 529 status codes.
|
|
84
|
+
"""
|
|
85
|
+
def __init__(self, class_name: str, debug_info: dict[str, Any] | None = None) -> None:
|
|
86
|
+
"""Initialize ProviderOverloadedError.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
class_name (str): The name of the class that raised the error.
|
|
90
|
+
debug_info (dict[str, Any] | None, optional): Additional debug information for developers.
|
|
91
|
+
Defaults to None.
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
class ModelNotFoundError(BaseInvokerError):
|
|
95
|
+
"""Exception for model not found errors.
|
|
96
|
+
|
|
97
|
+
Corresponds to HTTP 404 status code.
|
|
98
|
+
"""
|
|
99
|
+
def __init__(self, class_name: str, debug_info: dict[str, Any] | None = None) -> None:
|
|
100
|
+
"""Initialize ModelNotFoundError.
|
|
101
|
+
|
|
102
|
+
Args:
|
|
103
|
+
class_name (str): The name of the class that raised the error.
|
|
104
|
+
debug_info (dict[str, Any] | None, optional): Additional debug information for developers.
|
|
105
|
+
Defaults to None.
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
class InvokerRuntimeError(BaseInvokerError):
|
|
109
|
+
"""Exception for runtime errors that occur during the invocation of the model.
|
|
110
|
+
|
|
111
|
+
Corresponds to HTTP status codes other than the ones defined in HTTP_STATUS_TO_EXCEPTION_MAP.
|
|
112
|
+
"""
|
|
113
|
+
def __init__(self, class_name: str, debug_info: dict[str, Any] | None = None) -> None:
|
|
114
|
+
"""Initialize the InvokerRuntimeError.
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
class_name (str): The name of the class that raised the error.
|
|
118
|
+
debug_info (dict[str, Any] | None, optional): Additional debug information for developers.
|
|
119
|
+
Defaults to None.
|
|
120
|
+
"""
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from gllm_inference.lm_invoker.anthropic_lm_invoker import AnthropicLMInvoker as AnthropicLMInvoker
|
|
2
|
+
from gllm_inference.lm_invoker.azure_openai_lm_invoker import AzureOpenAILMInvoker as AzureOpenAILMInvoker
|
|
3
|
+
from gllm_inference.lm_invoker.bedrock_lm_invoker import BedrockLMInvoker as BedrockLMInvoker
|
|
4
|
+
from gllm_inference.lm_invoker.datasaur_lm_invoker import DatasaurLMInvoker as DatasaurLMInvoker
|
|
5
|
+
from gllm_inference.lm_invoker.google_lm_invoker import GoogleLMInvoker as GoogleLMInvoker
|
|
6
|
+
from gllm_inference.lm_invoker.langchain_lm_invoker import LangChainLMInvoker as LangChainLMInvoker
|
|
7
|
+
from gllm_inference.lm_invoker.litellm_lm_invoker import LiteLLMLMInvoker as LiteLLMLMInvoker
|
|
8
|
+
from gllm_inference.lm_invoker.openai_compatible_lm_invoker import OpenAICompatibleLMInvoker as OpenAICompatibleLMInvoker
|
|
9
|
+
from gllm_inference.lm_invoker.openai_lm_invoker import OpenAILMInvoker as OpenAILMInvoker
|
|
10
|
+
|
|
11
|
+
__all__ = ['AnthropicLMInvoker', 'AzureOpenAILMInvoker', 'BedrockLMInvoker', 'DatasaurLMInvoker', 'GoogleLMInvoker', 'LangChainLMInvoker', 'LiteLLMLMInvoker', 'OpenAICompatibleLMInvoker', 'OpenAILMInvoker']
|