gllm-inference-binary 0.5.9b1__cp311-cp311-macosx_10_9_universal2.macosx_13_0_x86_64.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.

Files changed (105) hide show
  1. gllm_inference/__init__.pyi +0 -0
  2. gllm_inference/builder/__init__.pyi +6 -0
  3. gllm_inference/builder/build_em_invoker.pyi +137 -0
  4. gllm_inference/builder/build_lm_invoker.pyi +161 -0
  5. gllm_inference/builder/build_lm_request_processor.pyi +93 -0
  6. gllm_inference/builder/build_output_parser.pyi +29 -0
  7. gllm_inference/catalog/__init__.pyi +4 -0
  8. gllm_inference/catalog/catalog.pyi +121 -0
  9. gllm_inference/catalog/lm_request_processor_catalog.pyi +112 -0
  10. gllm_inference/catalog/prompt_builder_catalog.pyi +82 -0
  11. gllm_inference/constants.pyi +10 -0
  12. gllm_inference/em_invoker/__init__.pyi +10 -0
  13. gllm_inference/em_invoker/azure_openai_em_invoker.pyi +88 -0
  14. gllm_inference/em_invoker/bedrock_em_invoker.pyi +106 -0
  15. gllm_inference/em_invoker/em_invoker.pyi +90 -0
  16. gllm_inference/em_invoker/google_em_invoker.pyi +129 -0
  17. gllm_inference/em_invoker/langchain/__init__.pyi +3 -0
  18. gllm_inference/em_invoker/langchain/em_invoker_embeddings.pyi +84 -0
  19. gllm_inference/em_invoker/langchain_em_invoker.pyi +46 -0
  20. gllm_inference/em_invoker/openai_compatible_em_invoker.pyi +96 -0
  21. gllm_inference/em_invoker/openai_em_invoker.pyi +90 -0
  22. gllm_inference/em_invoker/schema/__init__.pyi +0 -0
  23. gllm_inference/em_invoker/schema/bedrock.pyi +22 -0
  24. gllm_inference/em_invoker/schema/google.pyi +9 -0
  25. gllm_inference/em_invoker/schema/langchain.pyi +5 -0
  26. gllm_inference/em_invoker/schema/openai.pyi +7 -0
  27. gllm_inference/em_invoker/schema/openai_compatible.pyi +7 -0
  28. gllm_inference/em_invoker/schema/twelvelabs.pyi +17 -0
  29. gllm_inference/em_invoker/schema/voyage.pyi +15 -0
  30. gllm_inference/em_invoker/twelevelabs_em_invoker.pyi +101 -0
  31. gllm_inference/em_invoker/voyage_em_invoker.pyi +104 -0
  32. gllm_inference/exceptions/__init__.pyi +4 -0
  33. gllm_inference/exceptions/error_parser.pyi +41 -0
  34. gllm_inference/exceptions/exceptions.pyi +132 -0
  35. gllm_inference/exceptions/provider_error_map.pyi +23 -0
  36. gllm_inference/lm_invoker/__init__.pyi +12 -0
  37. gllm_inference/lm_invoker/anthropic_lm_invoker.pyi +275 -0
  38. gllm_inference/lm_invoker/azure_openai_lm_invoker.pyi +252 -0
  39. gllm_inference/lm_invoker/bedrock_lm_invoker.pyi +234 -0
  40. gllm_inference/lm_invoker/datasaur_lm_invoker.pyi +166 -0
  41. gllm_inference/lm_invoker/google_lm_invoker.pyi +317 -0
  42. gllm_inference/lm_invoker/langchain_lm_invoker.pyi +260 -0
  43. gllm_inference/lm_invoker/litellm_lm_invoker.pyi +248 -0
  44. gllm_inference/lm_invoker/lm_invoker.pyi +152 -0
  45. gllm_inference/lm_invoker/openai_compatible_lm_invoker.pyi +265 -0
  46. gllm_inference/lm_invoker/openai_lm_invoker.pyi +362 -0
  47. gllm_inference/lm_invoker/schema/__init__.pyi +0 -0
  48. gllm_inference/lm_invoker/schema/anthropic.pyi +50 -0
  49. gllm_inference/lm_invoker/schema/bedrock.pyi +53 -0
  50. gllm_inference/lm_invoker/schema/datasaur.pyi +12 -0
  51. gllm_inference/lm_invoker/schema/google.pyi +24 -0
  52. gllm_inference/lm_invoker/schema/langchain.pyi +23 -0
  53. gllm_inference/lm_invoker/schema/openai.pyi +91 -0
  54. gllm_inference/lm_invoker/schema/openai_compatible.pyi +60 -0
  55. gllm_inference/lm_invoker/schema/xai.pyi +31 -0
  56. gllm_inference/lm_invoker/xai_lm_invoker.pyi +305 -0
  57. gllm_inference/model/__init__.pyi +9 -0
  58. gllm_inference/model/em/__init__.pyi +0 -0
  59. gllm_inference/model/em/google_em.pyi +16 -0
  60. gllm_inference/model/em/openai_em.pyi +15 -0
  61. gllm_inference/model/em/twelvelabs_em.pyi +13 -0
  62. gllm_inference/model/em/voyage_em.pyi +20 -0
  63. gllm_inference/model/lm/__init__.pyi +0 -0
  64. gllm_inference/model/lm/anthropic_lm.pyi +20 -0
  65. gllm_inference/model/lm/google_lm.pyi +17 -0
  66. gllm_inference/model/lm/openai_lm.pyi +27 -0
  67. gllm_inference/output_parser/__init__.pyi +3 -0
  68. gllm_inference/output_parser/json_output_parser.pyi +60 -0
  69. gllm_inference/output_parser/output_parser.pyi +27 -0
  70. gllm_inference/prompt_builder/__init__.pyi +3 -0
  71. gllm_inference/prompt_builder/prompt_builder.pyi +56 -0
  72. gllm_inference/prompt_formatter/__init__.pyi +7 -0
  73. gllm_inference/prompt_formatter/agnostic_prompt_formatter.pyi +49 -0
  74. gllm_inference/prompt_formatter/huggingface_prompt_formatter.pyi +55 -0
  75. gllm_inference/prompt_formatter/llama_prompt_formatter.pyi +59 -0
  76. gllm_inference/prompt_formatter/mistral_prompt_formatter.pyi +53 -0
  77. gllm_inference/prompt_formatter/openai_prompt_formatter.pyi +35 -0
  78. gllm_inference/prompt_formatter/prompt_formatter.pyi +30 -0
  79. gllm_inference/request_processor/__init__.pyi +4 -0
  80. gllm_inference/request_processor/lm_request_processor.pyi +101 -0
  81. gllm_inference/request_processor/uses_lm_mixin.pyi +130 -0
  82. gllm_inference/schema/__init__.pyi +14 -0
  83. gllm_inference/schema/attachment.pyi +88 -0
  84. gllm_inference/schema/code_exec_result.pyi +14 -0
  85. gllm_inference/schema/config.pyi +15 -0
  86. gllm_inference/schema/enums.pyi +29 -0
  87. gllm_inference/schema/lm_output.pyi +36 -0
  88. gllm_inference/schema/message.pyi +52 -0
  89. gllm_inference/schema/model_id.pyi +147 -0
  90. gllm_inference/schema/reasoning.pyi +15 -0
  91. gllm_inference/schema/token_usage.pyi +75 -0
  92. gllm_inference/schema/tool_call.pyi +14 -0
  93. gllm_inference/schema/tool_result.pyi +11 -0
  94. gllm_inference/schema/type_alias.pyi +11 -0
  95. gllm_inference/utils/__init__.pyi +5 -0
  96. gllm_inference/utils/io_utils.pyi +26 -0
  97. gllm_inference/utils/langchain.pyi +30 -0
  98. gllm_inference/utils/validation.pyi +12 -0
  99. gllm_inference.build/.gitignore +1 -0
  100. gllm_inference.cpython-311-darwin.so +0 -0
  101. gllm_inference.pyi +123 -0
  102. gllm_inference_binary-0.5.9b1.dist-info/METADATA +71 -0
  103. gllm_inference_binary-0.5.9b1.dist-info/RECORD +105 -0
  104. gllm_inference_binary-0.5.9b1.dist-info/WHEEL +6 -0
  105. gllm_inference_binary-0.5.9b1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,96 @@
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.openai_em_invoker import OpenAIEMInvoker as OpenAIEMInvoker
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, TruncationConfig as TruncationConfig
7
+ from typing import Any
8
+
9
+ class OpenAICompatibleEMInvoker(OpenAIEMInvoker):
10
+ '''An embedding model invoker to interact with endpoints compatible with OpenAI\'s embedding API contract.
11
+
12
+ Attributes:
13
+ model_id (str): The model ID of the embedding model.
14
+ model_provider (str): The provider of the embedding model.
15
+ model_name (str): The name of the embedding model.
16
+ client (AsyncOpenAI): The OpenAI client instance.
17
+ default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the embedding model.
18
+ retry_config (RetryConfig): The retry configuration for the embedding model.
19
+ truncation_config (TruncationConfig | None): The truncation configuration for the embedding model.
20
+
21
+
22
+ When to use:
23
+ The `OpenAICompatibleEMInvoker` is designed to interact with endpoints that are compatible with OpenAI\'s
24
+ embedding API contract. This includes but are not limited to:
25
+ 1. Text Embeddings Inference (https://github.com/huggingface/text-embeddings-inference)
26
+ 2. vLLM (https://vllm.ai/)
27
+ When using this invoker, please note that the supported features and capabilities may vary between different
28
+ endpoints and language models. Using features that are not supported by the endpoint will result in an error.
29
+
30
+ Input types:
31
+ The `OpenAICompatibleEMInvoker` only supports text inputs.
32
+
33
+ Output format:
34
+ The `OpenAICompatibleEMInvoker` can embed either:
35
+ 1. A single content.
36
+ 1. A single content is a single text.
37
+ 2. The output will be a `Vector`, representing the embedding of the content.
38
+
39
+ # Example 1: Embedding a text content.
40
+ ```python
41
+ text = "This is a text"
42
+ result = await em_invoker.invoke(text)
43
+ ```
44
+
45
+ The above examples will return a `Vector` with a size of (embedding_size,).
46
+
47
+ 2. A list of contents.
48
+ 1. A list of contents is a list of texts.
49
+ 2. The output will be a `list[Vector]`, where each element is a `Vector` representing the
50
+ embedding of each single content.
51
+
52
+ # Example: Embedding a list of contents.
53
+ ```python
54
+ text1 = "This is a text"
55
+ text2 = "This is another text"
56
+ text3 = "This is yet another text"
57
+ result = await em_invoker.invoke([text1, text2, text3])
58
+ ```
59
+
60
+ The above examples will return a `list[Vector]` with a size of (3, embedding_size).
61
+
62
+ Retry and timeout:
63
+ The `OpenAICompatibleEMInvoker` supports retry and timeout configuration.
64
+ By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
65
+ They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
66
+
67
+ Retry config examples:
68
+ ```python
69
+ retry_config = RetryConfig(max_retries=0, timeout=0.0) # No retry, no timeout
70
+ retry_config = RetryConfig(max_retries=0, timeout=10.0) # No retry, 10.0 seconds timeout
71
+ retry_config = RetryConfig(max_retries=5, timeout=0.0) # 5 max retries, no timeout
72
+ retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
73
+ ```
74
+
75
+ Usage example:
76
+ ```python
77
+ em_invoker = OpenAICompatibleEMInvoker(..., retry_config=retry_config)
78
+ ```
79
+ '''
80
+ client: Incomplete
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:
82
+ """Initializes a new instance of the OpenAICompatibleEMInvoker class.
83
+
84
+ Args:
85
+ model_name (str): The name of the embedding model hosted on the OpenAI compatible endpoint.
86
+ base_url (str): The base URL for the OpenAI compatible endpoint.
87
+ api_key (str | None, optional): The API key for authenticating with the OpenAI compatible endpoint.
88
+ Defaults to None, in which case the `OPENAI_API_KEY` environment variable will be used.
89
+ model_kwargs (dict[str, Any] | None, optional): Additional model parameters. Defaults to None.
90
+ default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
91
+ Defaults to None.
92
+ retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
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.
96
+ """
@@ -0,0 +1,90 @@
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 gllm_inference.schema.config import TruncationConfig as TruncationConfig
8
+ from typing import Any
9
+
10
+ SUPPORTED_ATTACHMENTS: Incomplete
11
+
12
+ class OpenAIEMInvoker(BaseEMInvoker):
13
+ '''An embedding model invoker to interact with OpenAI 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 (AsyncOpenAI): The client for the OpenAI 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
+ truncation_config (TruncationConfig | None): The truncation configuration for the embedding model.
23
+
24
+ Input types:
25
+ The `OpenAIEMInvoker` only supports text inputs.
26
+
27
+ Output format:
28
+ The `OpenAIEMInvoker` can embed either:
29
+ 1. A single content.
30
+ 1. A single content is a single text.
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 = "This is a text"
36
+ result = await em_invoker.invoke(text)
37
+ ```
38
+
39
+ The above examples will return a `Vector` with a size of (embedding_size,).
40
+
41
+ 2. A list of contents.
42
+ 1. A list of contents is a list of texts.
43
+ 2. The output will be a `list[Vector]`, where each element is a `Vector` representing the
44
+ embedding of each single content.
45
+
46
+ # Example: Embedding a list of contents.
47
+ ```python
48
+ text1 = "This is a text"
49
+ text2 = "This is another text"
50
+ text3 = "This is yet another text"
51
+ result = await em_invoker.invoke([text1, text2, text3])
52
+ ```
53
+
54
+ The above examples will return a `list[Vector]` with a size of (3, embedding_size).
55
+
56
+ Retry and timeout:
57
+ The `OpenAIEMInvoker` supports retry and timeout configuration.
58
+ By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
59
+ They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
60
+
61
+ Retry config examples:
62
+ ```python
63
+ retry_config = RetryConfig(max_retries=0, timeout=0.0) # No retry, no timeout
64
+ retry_config = RetryConfig(max_retries=0, timeout=10.0) # No retry, 10.0 seconds timeout
65
+ retry_config = RetryConfig(max_retries=5, timeout=0.0) # 5 max retries, no timeout
66
+ retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
67
+ ```
68
+
69
+ Usage example:
70
+ ```python
71
+ em_invoker = OpenAIEMInvoker(..., retry_config=retry_config)
72
+ ```
73
+ '''
74
+ client: Incomplete
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:
76
+ """Initializes a new instance of the OpenAIEMInvoker class.
77
+
78
+ Args:
79
+ model_name (str): The name of the OpenAI embedding model to be used.
80
+ api_key (str | None, optional): The API key for the OpenAI API. Defaults to None, in which
81
+ case the `OPENAI_API_KEY` environment variable will be used.
82
+ model_kwargs (dict[str, Any] | None, optional): Additional keyword arguments for the OpenAI client.
83
+ Defaults to None.
84
+ default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
85
+ Defaults to None.
86
+ retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
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.
90
+ """
File without changes
@@ -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
@@ -0,0 +1,9 @@
1
+ class Key:
2
+ """Defines valid keys in Google."""
3
+ API_KEY: str
4
+ CREDENTIALS: str
5
+ HTTP_OPTIONS: str
6
+ LOCATION: str
7
+ PROJECT: str
8
+ TIMEOUT: str
9
+ VERTEXAI: str
@@ -0,0 +1,5 @@
1
+ class Key:
2
+ """Defines valid keys in LangChain."""
3
+ ERROR_CODE: str
4
+ MAX_RETRIES: str
5
+ TIMEOUT: str
@@ -0,0 +1,7 @@
1
+ class Key:
2
+ """Defines valid keys in OpenAI."""
3
+ API_KEY: str
4
+ BASE_URL: str
5
+ MAX_RETRIES: str
6
+ MODEL: str
7
+ TIMEOUT: str
@@ -0,0 +1,7 @@
1
+ class Key:
2
+ """Defines valid keys in OpenAI Compatible."""
3
+ API_KEY: str
4
+ BASE_URL: str
5
+ MAX_RETRIES: str
6
+ MODEL: str
7
+ TIMEOUT: str
@@ -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,101 @@
1
+ from _typeshed import Incomplete
2
+ from gllm_core.utils.retry import RetryConfig as RetryConfig
3
+ from gllm_inference.em_invoker.em_invoker import BaseEMInvoker as BaseEMInvoker
4
+ from gllm_inference.em_invoker.schema.twelvelabs import InputType as InputType, Key as Key, OutputType as OutputType
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
6
+ from typing import Any
7
+
8
+ SUPPORTED_ATTACHMENTS: Incomplete
9
+
10
+ class TwelveLabsEMInvoker(BaseEMInvoker):
11
+ '''An embedding model invoker to interact with TwelveLabs embedding models.
12
+
13
+ Attributes:
14
+ model_id (str): The model ID of the embedding model.
15
+ model_provider (str): The provider of the embedding model.
16
+ model_name (str): The name of the embedding model.
17
+ client (Client): The client for the TwelveLabs API.
18
+ default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the embedding model.
19
+ retry_config (RetryConfig): The retry configuration for the embedding model.
20
+ truncation_config (TruncationConfig | None): The truncation 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, truncation_config: TruncationConfig | 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
+ truncation_config (TruncationConfig | None, optional): Configuration for text truncation behavior.
100
+ Defaults to None, in which case no truncation is applied.
101
+ """
@@ -0,0 +1,104 @@
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, TruncationConfig as TruncationConfig, 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
+ truncation_config (TruncationConfig | None): The truncation configuration for the embedding model.
23
+
24
+ Input types:
25
+ The `VoyageEMInvoker` supports the following input types: text, image, and a tuple containing text and image.
26
+ Non-text inputs must be passed as a `Attachment` object.
27
+
28
+ Output format:
29
+ The `VoyageEMInvoker` can embed either:
30
+ 1. A single content.
31
+ 1. A single content is either a text, an image, or a tuple containing a text and an image.
32
+ 2. The output will be a `Vector`, representing the embedding of the content.
33
+
34
+ # Example 1: Embedding a text content.
35
+ ```python
36
+ text = "What animal is in this image?"
37
+ result = await em_invoker.invoke(text)
38
+ ```
39
+
40
+ # Example 2: Embedding an image content.
41
+ ```python
42
+ image = Attachment.from_path("path/to/local/image.png")
43
+ result = await em_invoker.invoke(image)
44
+ ```
45
+
46
+ # Example 3: Embedding a tuple containing a text and an image.
47
+ ```python
48
+ text = "What animal is in this image?"
49
+ image = Attachment.from_path("path/to/local/image.png")
50
+ result = await em_invoker.invoke((text, image))
51
+ ```
52
+
53
+ The above examples will return a `Vector` with a size of (embedding_size,).
54
+
55
+ 2. A list of contents.
56
+ 1. A list of contents is a list that consists of any of the above single contents.
57
+ 2. The output will be a `list[Vector]`, where each element is a `Vector` representing the
58
+ embedding of each single content.
59
+
60
+ # Example: Embedding a list of contents.
61
+ ```python
62
+ text = "What animal is in this image?"
63
+ image = Attachment.from_path("path/to/local/image.png")
64
+ mix_content = (text, image)
65
+ result = await em_invoker.invoke([text, image, mix_content])
66
+ ```
67
+
68
+ The above examples will return a `list[Vector]` with a size of (3, embedding_size).
69
+
70
+ Retry and timeout:
71
+ The `VoyageEMInvoker` supports retry and timeout configuration.
72
+ By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
73
+ They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
74
+
75
+ Retry config examples:
76
+ ```python
77
+ retry_config = RetryConfig(max_retries=0, timeout=0.0) # No retry, no timeout
78
+ retry_config = RetryConfig(max_retries=0, timeout=10.0) # No retry, 10.0 seconds timeout
79
+ retry_config = RetryConfig(max_retries=5, timeout=0.0) # 5 max retries, no timeout
80
+ retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
81
+ ```
82
+
83
+ Usage example:
84
+ ```python
85
+ em_invoker = VoyageEMInvoker(..., retry_config=retry_config)
86
+ ```
87
+ '''
88
+ client: Incomplete
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:
90
+ """Initializes a new instance of the VoyageEMInvoker class.
91
+
92
+ Args:
93
+ model_name (str): The name of the Voyage embedding model to be used.
94
+ api_key (str | None, optional): The API key for the Voyage API. Defaults to None, in which
95
+ case the `VOYAGE_API_KEY` environment variable will be used.
96
+ model_kwargs (dict[str, Any] | None, optional): Additional keyword arguments for the Voyage client.
97
+ Defaults to None.
98
+ default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
99
+ Defaults to None.
100
+ retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
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.
104
+ """
@@ -0,0 +1,4 @@
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
+
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']
@@ -0,0 +1,41 @@
1
+ from gllm_inference.exceptions.exceptions import BaseInvokerError as BaseInvokerError, InvokerRuntimeError as InvokerRuntimeError
2
+ from gllm_inference.exceptions.provider_error_map import ALL_PROVIDER_ERROR_MAPPINGS as ALL_PROVIDER_ERROR_MAPPINGS, HTTP_STATUS_TO_EXCEPTION_MAP as HTTP_STATUS_TO_EXCEPTION_MAP
3
+ from typing import Any
4
+
5
+ def build_debug_info(error: Any, class_name: str) -> dict[str, Any]:
6
+ """Build debug information for an error.
7
+
8
+ Args:
9
+ error (Any): The error to extract debug information from.
10
+ class_name (str): The name of the class that raised the error.
11
+
12
+ Returns:
13
+ dict[str, Any]: A dictionary containing debug information about the error.
14
+ """
15
+ def convert_http_status_to_base_invoker_error(error: Exception, invoker: BaseEMInvoker | BaseLMInvoker, status_code_extractor: callable = None, provider_error_mapping: dict[str, type[BaseInvokerError]] = ...) -> BaseInvokerError:
16
+ """Extract provider error with HTTP status code fallback pattern.
17
+
18
+ This function implements the common pattern used by Bedrock and Google invokers
19
+ where they first try to extract HTTP status codes, then fall back to provider-specific
20
+ error mappings based on exception keys.
21
+
22
+ Args:
23
+ error (Exception): The error to convert.
24
+ invoker (BaseEMInvoker | BaseLMInvoker): The invoker instance that raised the error.
25
+ status_code_extractor (callable): Function to extract status code from error.
26
+ provider_error_mapping (dict): Provider-specific error mapping dictionary.
27
+
28
+ Returns:
29
+ BaseInvokerError: The converted error.
30
+ """
31
+ def convert_to_base_invoker_error(error: Exception, invoker: BaseEMInvoker | BaseLMInvoker) -> BaseInvokerError:
32
+ """Convert provider error into BaseInvokerError.
33
+
34
+ Args:
35
+ error (Exception): The error to convert.
36
+ invoker (BaseEMInvoker | BaseLMInvoker): The invoker instance that raised the error.
37
+
38
+ Returns:
39
+ BaseInvokerError: The converted error.
40
+
41
+ """