gllm-inference-binary 0.5.9b1__cp313-cp313-macosx_10_13_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-313-darwin.so +0 -0
  101. gllm_inference.pyi +124 -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,31 @@
1
+ from enum import StrEnum
2
+
3
+ class Key:
4
+ """Defines valid keys in xAI."""
5
+ ARGUMENTS: str
6
+ CHANNEL_OPTIONS: str
7
+ CITATIONS: str
8
+ COMPLETION_TOKENS: str
9
+ CONTENT: str
10
+ FINISH_REASON: str
11
+ FUNCTION: str
12
+ ID: str
13
+ NAME: str
14
+ ON: str
15
+ PROMPT_TOKENS: str
16
+ REASONING_CONTENT: str
17
+ REASONING_EFFORT: str
18
+ RESPONSE_FORMAT: str
19
+ SEARCH_PARAMETERS: str
20
+ TIMEOUT: str
21
+ TOOL_CALLS: str
22
+ TOOLS: str
23
+ TYPE: str
24
+ URL: str
25
+ URL_CITATION: str
26
+ USAGE: str
27
+
28
+ class ReasoningEffort(StrEnum):
29
+ """Defines the reasoning effort for reasoning models."""
30
+ HIGH = 'high'
31
+ LOW = 'low'
@@ -0,0 +1,305 @@
1
+ from _typeshed import Incomplete
2
+ from gllm_core.event import EventEmitter as EventEmitter
3
+ from gllm_core.schema.tool import Tool as Tool
4
+ from gllm_core.utils.retry import RetryConfig as RetryConfig
5
+ from gllm_inference.constants import GRPC_ENABLE_RETRIES_KEY as GRPC_ENABLE_RETRIES_KEY, INVOKER_PROPAGATED_MAX_RETRIES as INVOKER_PROPAGATED_MAX_RETRIES
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 GRPC_STATUS_CODE_MAPPING as GRPC_STATUS_CODE_MAPPING
8
+ from gllm_inference.lm_invoker.lm_invoker import BaseLMInvoker as BaseLMInvoker
9
+ from gllm_inference.lm_invoker.schema.xai import Key as Key, ReasoningEffort as ReasoningEffort
10
+ from gllm_inference.schema import Attachment as Attachment, AttachmentType as AttachmentType, EmitDataType as EmitDataType, LMOutput as LMOutput, Message as Message, MessageRole as MessageRole, ModelId as ModelId, ModelProvider as ModelProvider, Reasoning as Reasoning, ResponseSchema as ResponseSchema, TokenUsage as TokenUsage, ToolCall as ToolCall, ToolResult as ToolResult
11
+ from gllm_inference.utils.validation import validate_string_enum as validate_string_enum
12
+ from langchain_core.tools import Tool as LangChainTool
13
+ from typing import Any
14
+
15
+ SUPPORTED_ATTACHMENTS: Incomplete
16
+
17
+ class XAILMInvoker(BaseLMInvoker):
18
+ '''A language model invoker to interact with xAI language models.
19
+
20
+ Attributes:
21
+ model_id (str): The model ID of the language model.
22
+ model_provider (str): The provider of the language model.
23
+ model_name (str): The name of the language model.
24
+ client_params (dict[str, Any]): The xAI client initialization parameters.
25
+ default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the model.
26
+ tools (list[Tool]): The list of tools provided to the model to enable tool calling.
27
+ response_schema (ResponseSchema | None): The schema of the response. If provided, the model will output a
28
+ structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema dictionary.
29
+ output_analytics (bool): Whether to output the invocation analytics.
30
+ retry_config (RetryConfig | None): The retry configuration for the language model.
31
+ reasoning_effort (ReasoningEffort | None): The reasoning effort level for reasoning models ("low" or "high").
32
+ web_search (bool): Whether to enable the web search.
33
+
34
+
35
+ Basic usage:
36
+ The `XAILMInvoker` can be used as follows:
37
+ ```python
38
+ lm_invoker = XAILMInvoker(model_name="grok-3")
39
+ result = await lm_invoker.invoke("Hi there!")
40
+ ```
41
+
42
+ Input types:
43
+ The `XAILMInvoker` supports the following input types: text and image.
44
+ Non-text inputs can be passed as an `Attachment` object with the `user` role.
45
+
46
+ Usage example:
47
+ ```python
48
+ text = "What animal is in this image?"
49
+ image = Attachment.from_path("path/to/local/image.png")
50
+ result = await lm_invoker.invoke([text, image])
51
+ ```
52
+
53
+ Tool calling:
54
+ Tool calling is a feature that allows the language model to call tools to perform tasks.
55
+ Tools can be passed to the via the `tools` parameter as a list of `Tool` objects.
56
+ When tools are provided and the model decides to call a tool, the tool calls are stored in the
57
+ `tool_calls` attribute in the output.
58
+
59
+ Usage example:
60
+ ```python
61
+ lm_invoker = XAILMInvoker(..., tools=[tool_1, tool_2])
62
+ ```
63
+
64
+ Output example:
65
+ ```python
66
+ LMOutput(
67
+ response="Let me call the tools...",
68
+ tool_calls=[
69
+ ToolCall(id="123", name="tool_1", args={"key": "value"}),
70
+ ToolCall(id="456", name="tool_2", args={"key": "value"}),
71
+ ]
72
+ )
73
+ ```
74
+
75
+ Structured output:
76
+ Structured output is a feature that allows the language model to output a structured response.
77
+ This feature can be enabled by providing a schema to the `response_schema` parameter.
78
+
79
+ The schema must be either a JSON schema dictionary or a Pydantic BaseModel class.
80
+ If JSON schema is used, it must be compatible with Pydantic\'s JSON schema, especially for complex schemas.
81
+ For this reason, it is recommended to create the JSON schema using Pydantic\'s `model_json_schema` method.
82
+
83
+ The language model also doesn\'t need to stream anything when structured output is enabled. Thus, standard
84
+ invocation will be performed regardless of whether the `event_emitter` parameter is provided or not.
85
+
86
+ When enabled, the structured output is stored in the `structured_output` attribute in the output.
87
+ 1. If the schema is a JSON schema dictionary, the structured output is a dictionary.
88
+ 2. If the schema is a Pydantic BaseModel class, the structured output is a Pydantic model.
89
+
90
+ # Example 1: Using a JSON schema dictionary
91
+ Usage example:
92
+ ```python
93
+ schema = {
94
+ "title": "Animal",
95
+ "description": "A description of an animal.",
96
+ "properties": {
97
+ "color": {"title": "Color", "type": "string"},
98
+ "name": {"title": "Name", "type": "string"},
99
+ },
100
+ "required": ["name", "color"],
101
+ "type": "object",
102
+ }
103
+ lm_invoker = XAILMInvoker(..., response_schema=schema)
104
+ ```
105
+ Output example:
106
+ ```python
107
+ LMOutput(structured_output={"name": "Golden retriever", "color": "Golden"})
108
+ ```
109
+
110
+ # Example 2: Using a Pydantic BaseModel class
111
+ Usage example:
112
+ ```python
113
+ class Animal(BaseModel):
114
+ name: str
115
+ color: str
116
+
117
+ lm_invoker = XAILMInvoker(..., response_schema=Animal)
118
+ ```
119
+ Output example:
120
+ ```python
121
+ LMOutput(structured_output=Animal(name="Golden retriever", color="Golden"))
122
+ ```
123
+
124
+ Reasoning:
125
+ Reasoning effort is a feature specific to xAI\'s reasoning models that allows you to control the level
126
+ of reasoning performed by the model. This feature can be enabled by setting the `reasoning_effort` parameter.
127
+ Valid values are "low" and "high".
128
+
129
+ Please note that Grok 4 does not have a `reasoning_effort` parameter. If a `reasoning_effort` is provided,
130
+ the request will return error.
131
+
132
+ Usage example:
133
+ ```python
134
+ lm_invoker = XAILMInvoker(
135
+ model_name="grok-3",
136
+ reasoning_effort="high" # Enable high reasoning effort
137
+ )
138
+ ```
139
+
140
+ When reasoning effort is enabled, the model\'s internal reasoning process is captured and stored in the
141
+ `reasoning` attribute in the output.
142
+
143
+ Output example:
144
+ ```python
145
+ LMOutput(
146
+ response="The answer is 42",
147
+ reasoning=[
148
+ Reasoning(
149
+ id="reasoning_1",
150
+ reasoning="First, I need to understand the question. The user is asking about..."
151
+ )
152
+ ]
153
+ )
154
+ ```
155
+
156
+ When streaming is enabled along with reasoning summary, the reasoning summary token will be streamed with the
157
+ `EventType.DATA` event type.
158
+
159
+ Streaming output example:
160
+ ```python
161
+ {"type": "data", "value": \'{"data_type": "thinking_start", "data_value": ""}\', ...}
162
+ {"type": "data", "value": \'{"data_type": "thinking", "data_value": "Let me think "}\', ...}
163
+ {"type": "data", "value": \'{"data_type": "thinking", "data_value": "about it..."}\', ...}
164
+ {"type": "data", "value": \'{"data_type": "thinking_end", "data_value": ""}\', ...}
165
+ {"type": "response", "value": "Golden retriever ", ...}
166
+ {"type": "response", "value": "is a good dog breed.", ...}
167
+ ```
168
+
169
+ Setting reasoning-related parameters for non-reasoning models will raise an error.
170
+
171
+ Analytics tracking:
172
+ Analytics tracking is a feature that allows the module to output additional information about the invocation.
173
+ This feature can be enabled by setting the `output_analytics` parameter to `True`.
174
+ When enabled, the following attributes will be stored in the output:
175
+ 1. `token_usage`: The token usage.
176
+ 2. `finish_details`: The details about how the generation finished.
177
+
178
+ Output example:
179
+ ```python
180
+ LMOutput(
181
+ response="Golden retriever is a good dog breed.",
182
+ token_usage=TokenUsage(input_tokens=100, output_tokens=50),
183
+ finish_details={"finish_reason": "stop"},
184
+ )
185
+ ```
186
+
187
+ When streaming is enabled, token usage is not supported. Therefore, the `token_usage` attribute will be `None`
188
+ regardless of the value of the `output_analytics` parameter.
189
+
190
+ Retry and timeout:
191
+ The `XAILMInvoker` supports retry and timeout configuration.
192
+ By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
193
+ They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
194
+
195
+ Retry config examples:
196
+ ```python
197
+ retry_config = RetryConfig(max_retries=0, timeout=0.0) # No retry, no timeout
198
+ retry_config = RetryConfig(max_retries=0, timeout=10.0) # No retry, 10.0 seconds timeout
199
+ retry_config = RetryConfig(max_retries=5, timeout=0.0) # 5 max retries, no timeout
200
+ retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
201
+ ```
202
+
203
+ Usage example:
204
+ ```python
205
+ lm_invoker = XAILMInvoker(..., retry_config=retry_config)
206
+ ```
207
+
208
+ Web Search:
209
+ The web search is a feature that allows the language model to search the web for relevant information.
210
+ This feature can be enabled by setting the `web_search` parameter to `True`.
211
+
212
+ Usage example:
213
+ ```python
214
+ lm_invoker = XAILMInvoker(
215
+ model_name="grok-3",
216
+ web_search=True
217
+ )
218
+ ```
219
+
220
+ When web search is enabled, the language model will search for relevant information and may cite the
221
+ relevant sources (including from X platform). The citations will be stored as `Chunk` objects in the `citations`
222
+ attribute in the output.
223
+
224
+ Output example:
225
+ ```python
226
+ LMOutput(
227
+ response="According to recent reports, the latest AI developments include... ([Source](https://example.com)).",
228
+ citations=[
229
+ Chunk(
230
+ id="search_result_1",
231
+ content="Latest AI developments report",
232
+ metadata={
233
+ "start_index": 164,
234
+ "end_index": 275,
235
+ "title": "Example title",
236
+ "url": "https://www.example.com",
237
+ "type": "url_citation",
238
+ },
239
+ ),
240
+ ],
241
+ )
242
+ ```
243
+
244
+ When streaming is enabled, the live search activities will be streamed with the `EventType.DATA` event type.
245
+ This allows you to track the search process in real-time.
246
+
247
+ Streaming output example:
248
+ ```python
249
+ {"type": "data", "value": \'{"data_type": "activity", "data_value": "{\\"query\\": \\"search query\\"}", ...}\', ...}
250
+ {"type": "response", "value": "According to recent reports, ", ...}
251
+ {"type": "response", "value": "the latest AI developments include...", ...}
252
+ ```
253
+
254
+ Output types:
255
+ The output of the `XAILMInvoker` can either be:
256
+ 1. `str`: The text response if no additional output is needed.
257
+ 2. `LMOutput`: A Pydantic model with the following attributes if any additional output is needed:
258
+ 2.1. response (str): The text response.
259
+ 2.2. tool_calls (list[ToolCall]): The tool calls, if the `tools` parameter is defined and the language
260
+ model decides to invoke tools. Defaults to an empty list.
261
+ 2.3. structured_output (dict[str, Any] | BaseModel | None): The structured output, if the `response_schema`
262
+ parameter is defined. Defaults to None.
263
+ 2.4. token_usage (TokenUsage | None): The token usage analytics, if the `output_analytics` parameter is
264
+ set to `True`. Defaults to None.
265
+ 2.5. duration (float | None): The duration of the invocation in seconds, if the `output_analytics`
266
+ parameter is set to `True`. Defaults to None.
267
+ 2.6. finish_details (dict[str, Any] | None): The details about how the generation finished, if the
268
+ `output_analytics` parameter is set to `True`. Defaults to None.
269
+ 2.7. reasoning (list[Reasoning]): The reasoning objects, if the `reasoning_effort` parameter is set.
270
+ Defaults to an empty list.
271
+ 2.8. citations (list[Chunk]): The citations, if the web_search is enabled and the language model decides
272
+ to cite the relevant sources. Defaults to an empty list.
273
+ 2.9. code_exec_results (list[CodeExecResult]): The code execution results. Currently not supported.
274
+ Defaults to an empty list.
275
+ '''
276
+ reasoning_effort: Incomplete
277
+ web_search: Incomplete
278
+ client_params: Incomplete
279
+ 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, tools: list[Tool | LangChainTool] | None = None, response_schema: ResponseSchema | None = None, output_analytics: bool = False, retry_config: RetryConfig | None = None, reasoning_effort: ReasoningEffort | None = None, web_search: bool = False) -> None:
280
+ """Initializes a new instance of the XAILMInvoker class.
281
+
282
+ Args:
283
+ model_name (str): The name of the xAI model.
284
+ api_key (str | None, optional): The API key for authenticating with xAI. Defaults to None, in which
285
+ case the `XAI_API_KEY` environment variable will be used.
286
+ model_kwargs (dict[str, Any] | None, optional): Additional model parameters. Defaults to None.
287
+ default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
288
+ Defaults to None.
289
+ tools (list[Tool | LangChainTool] | None, optional): Tools provided to the language model to enable tool
290
+ calling.
291
+ Defaults to None.
292
+ response_schema (ResponseSchema | None, optional): The schema of the response. If provided, the model will
293
+ output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema
294
+ dictionary. Defaults to None.
295
+ output_analytics (bool, optional): Whether to output the invocation analytics. Defaults to False.
296
+ retry_config (RetryConfig | None, optional): The retry configuration for the language model.
297
+ Defaults to None, in which case a default config with no retry and 30.0 seconds timeout is used.
298
+ reasoning_effort (ReasoningEffort | None, optional): The reasoning effort for reasoning models. Not allowed
299
+ for non-reasoning models. If None, the model will perform medium reasoning effort. Defaults to None.
300
+ web_search (bool, optional): Whether to enable the web search. Defaults to False.
301
+
302
+ Raises:
303
+ ValueError:
304
+ 1. `reasoning_effort` is provided, but is not a valid ReasoningEffort.
305
+ """
@@ -0,0 +1,9 @@
1
+ from gllm_inference.model.em.google_em import GoogleEM as GoogleEM
2
+ from gllm_inference.model.em.openai_em import OpenAIEM as OpenAIEM
3
+ from gllm_inference.model.em.twelvelabs_em import TwelveLabsEM as TwelveLabsEM
4
+ from gllm_inference.model.em.voyage_em import VoyageEM as VoyageEM
5
+ from gllm_inference.model.lm.anthropic_lm import AnthropicLM as AnthropicLM
6
+ from gllm_inference.model.lm.google_lm import GoogleLM as GoogleLM
7
+ from gllm_inference.model.lm.openai_lm import OpenAILM as OpenAILM
8
+
9
+ __all__ = ['AnthropicLM', 'GoogleEM', 'GoogleLM', 'OpenAIEM', 'OpenAILM', 'TwelveLabsEM', 'VoyageEM']
File without changes
@@ -0,0 +1,16 @@
1
+ class GoogleEM:
2
+ '''Defines Google embedding model names constants.
3
+
4
+ Usage example:
5
+ ```python
6
+ from gllm_inference.model import GoogleEM
7
+ from gllm_inference.em_invoker import GoogleEMInvoker
8
+
9
+ em_invoker = GoogleEMInvoker(GoogleEM.GEMINI_EMBEDDING_001)
10
+ result = await em_invoker.invoke("Hello, world!")
11
+ ```
12
+ '''
13
+ GEMINI_EMBEDDING_001: str
14
+ TEXT_EMBEDDING_004: str
15
+ TEXT_EMBEDDING_005: str
16
+ TEXT_MULTILINGUAL_EMBEDDING_002: str
@@ -0,0 +1,15 @@
1
+ class OpenAIEM:
2
+ '''Defines OpenAI embedding model names constants.
3
+
4
+ Usage example:
5
+ ```python
6
+ from gllm_inference.model import OpenAIEM
7
+ from gllm_inference.em_invoker import OpenAIEMInvoker
8
+
9
+ em_invoker = OpenAIEMInvoker(OpenAIEM.TEXT_EMBEDDING_3_SMALL)
10
+ result = await em_invoker.invoke("Hello, world!")
11
+ ```
12
+ '''
13
+ TEXT_EMBEDDING_3_SMALL: str
14
+ TEXT_EMBEDDING_3_LARGE: str
15
+ TEXT_EMBEDDING_ADA_002: str
@@ -0,0 +1,13 @@
1
+ class TwelveLabsEM:
2
+ '''Defines TwelveLabs embedding model names constants.
3
+
4
+ Usage example:
5
+ ```python
6
+ from gllm_inference.model import TwelveLabsEM
7
+ from gllm_inference.em_invoker import TwelveLabsEMInvoker
8
+
9
+ em_invoker = TwelveLabsEMInvoker(TwelveLabsEM.MARENGO_RETRIEVAL_2_7)
10
+ result = await em_invoker.invoke("Hello, world!")
11
+ ```
12
+ '''
13
+ MARENGO_RETRIEVAL_2_7: str
@@ -0,0 +1,20 @@
1
+ class VoyageEM:
2
+ '''Defines Voyage embedding model names constants.
3
+
4
+ Usage example:
5
+ ```python
6
+ from gllm_inference.model import VoyageEM
7
+ from gllm_inference.em_invoker import VoyageEMInvoker
8
+
9
+ em_invoker = VoyageEMInvoker(VoyageEM.VOYAGE_3_5_LITE)
10
+ result = await em_invoker.invoke("Hello, world!")
11
+ ```
12
+ '''
13
+ VOYAGE_3_5: str
14
+ VOYAGE_3_5_LITE: str
15
+ VOYAGE_3_LARGE: str
16
+ VOYAGE_CODE_3: str
17
+ VOYAGE_FINANCE_2: str
18
+ VOYAGE_LAW_2: str
19
+ VOYAGE_CODE_2: str
20
+ VOYAGE_MULTIMODAL_3: str
File without changes
@@ -0,0 +1,20 @@
1
+ class AnthropicLM:
2
+ '''Defines Anthropic language model names constants.
3
+
4
+ Usage example:
5
+ ```python
6
+ from gllm_inference.model import AnthropicLM
7
+ from gllm_inference.lm_invoker import AnthropicLMInvoker
8
+
9
+ lm_invoker = AnthropicLMInvoker(AnthropicLM.CLAUDE_SONNET_4)
10
+ response = await lm_invoker.invoke("Hello, world!")
11
+ ```
12
+ '''
13
+ CLAUDE_OPUS_4_1: str
14
+ CLAUDE_OPUS_4: str
15
+ CLAUDE_SONNET_4: str
16
+ CLAUDE_SONNET_3_7: str
17
+ CLAUDE_SONNET_3_5: str
18
+ CLAUDE_HAIKU_3_5: str
19
+ CLAUDE_OPUS_3: str
20
+ CLAUDE_HAIKU_3: str
@@ -0,0 +1,17 @@
1
+ class GoogleLM:
2
+ '''Defines Google language model names constants.
3
+
4
+ Usage example:
5
+ ```python
6
+ from gllm_inference.model import GoogleLM
7
+ from gllm_inference.lm_invoker import GoogleLMInvoker
8
+
9
+ lm_invoker = GoogleLMInvoker(GoogleLM.GEMINI_2_5_FLASH)
10
+ response = await lm_invoker.invoke("Hello, world!")
11
+ ```
12
+ '''
13
+ GEMINI_2_5_PRO: str
14
+ GEMINI_2_5_FLASH: str
15
+ GEMINI_2_5_FLASH_LITE: str
16
+ GEMINI_2_0_FLASH: str
17
+ GEMINI_2_0_FLASH_LITE: str
@@ -0,0 +1,27 @@
1
+ class OpenAILM:
2
+ '''Defines OpenAI language model names constants.
3
+
4
+ Usage example:
5
+ ```python
6
+ from gllm_inference.model import OpenAILM
7
+ from gllm_inference.lm_invoker import OpenAILMInvoker
8
+
9
+ lm_invoker = OpenAILMInvoker(OpenAILM.GPT_5_NANO)
10
+ response = await lm_invoker.invoke("Hello, world!")
11
+ ```
12
+ '''
13
+ GPT_5: str
14
+ GPT_5_MINI: str
15
+ GPT_5_NANO: str
16
+ GPT_4_1: str
17
+ GPT_4_1_MINI: str
18
+ GPT_4_1_NANO: str
19
+ GPT_4O: str
20
+ GPT_4O_MINI: str
21
+ O4_MINI: str
22
+ O4_MINI_DEEP_RESEARCH: str
23
+ O3: str
24
+ O3_PRO: str
25
+ O3_DEEP_RESEARCH: str
26
+ O1: str
27
+ O1_PRO: str
@@ -0,0 +1,3 @@
1
+ from gllm_inference.output_parser.json_output_parser import JSONOutputParser as JSONOutputParser
2
+
3
+ __all__ = ['JSONOutputParser']
@@ -0,0 +1,60 @@
1
+ from gllm_inference.output_parser.output_parser import BaseOutputParser as BaseOutputParser
2
+ from typing import Any
3
+
4
+ class JSONOutputParser(BaseOutputParser[dict[str, Any]]):
5
+ '''An output parser that parses a json object from the language model output.
6
+
7
+ The `JSONOutputParser` class searches for the first opening curly brace `{` and the last closing curly brace `}`
8
+ in the language model\'s output to identify and extract a JSON object. It then parses the extracted substring into
9
+ a Python dictionary. This method relies on finding a well-formed JSON structure enclosed by the first and last
10
+ curly braces in the string. If the result contains additional curly braces outside the JSON object, or if there
11
+ are multiple JSON objects, this parser will not function correctly and will raise a `ValueError`.
12
+
13
+ Example:
14
+ If the result is:
15
+ ```
16
+ "Here is the data: {\\"key\\": \\"value\\"} and some other text."
17
+ ```
18
+ The parser will extract the `{"key": "value"}` JSON object.
19
+
20
+ However, if the result contains multiple JSON objects or nested data, such as:
21
+ ```
22
+ "Here are two JSONs: {\\"key1\\": \\"value1\\"} and {\\"key2\\": \\"value2\\"}"
23
+ ```
24
+ The parser will not handle this correctly, as it only extracts the content between the first `{` and the last `}`.
25
+ '''
26
+ def parse(self, result: str) -> dict[str, Any]:
27
+ '''Parses the raw output string to extract and decode a JSON object.
28
+
29
+ This method searches the provided string for the first opening curly brace `{` and the last closing curly
30
+ brace `}` to identify a JSON object. It extracts the substring between these braces and attempts to parse it
31
+ as a JSON object. The method raises a `ValueError` if no valid JSON structure is found or if the JSON is
32
+ malformed.
33
+
34
+ Note:
35
+ This approach relies on the first `{` and the last `}` in the string. It will fail if:
36
+ - The result contains curly braces outside the intended JSON object.
37
+ - There are multiple JSON objects within the string, as it only processes the first and last braces.
38
+
39
+ Example:
40
+ If the result is:
41
+ ```
42
+ "Here is the data: {\\"key\\": \\"value\\"} and some other text."
43
+ ```
44
+ The parser will extract and return the `{"key": "value"}` object.
45
+
46
+ However, if the result is:
47
+ ```
48
+ "Here are two JSONs: {\\"key1\\": \\"value1\\"} and {\\"key2\\": \\"value2\\"}"
49
+ ```
50
+ The parser will incorrectly attempt to parse everything between the first `{` and the last `}`.
51
+
52
+ Args:
53
+ result (str): The raw output string from the language model.
54
+
55
+ Returns:
56
+ dict[str, Any]: The parsed JSON object as a Python dictionary.
57
+
58
+ Raises:
59
+ ValueError: If no valid JSON object is found or if the JSON string is invalid.
60
+ '''
@@ -0,0 +1,27 @@
1
+ import abc
2
+ from abc import ABC, abstractmethod
3
+ from typing import Generic, TypeVar
4
+
5
+ T = TypeVar('T')
6
+
7
+ class BaseOutputParser(ABC, Generic[T], metaclass=abc.ABCMeta):
8
+ """A base class for output parsers used in Gen AI applications.
9
+
10
+ The `BaseOutputParser` class defines the interface for parsing the output of language models.
11
+ Subclasses must implement the `parse` method to process and extract meaningful data from the raw output.
12
+ """
13
+ @abstractmethod
14
+ def parse(self, result: str) -> T:
15
+ """Parses the raw output string from the language model.
16
+
17
+ This abstract method must be implemented by subclasses to define how the result is parsed and processed.
18
+
19
+ Args:
20
+ result (str): The raw output string from the language model.
21
+
22
+ Returns:
23
+ T: The parsed result of type T.
24
+
25
+ Raises:
26
+ NotImplementedError: If the method is not implemented in a subclass.
27
+ """
@@ -0,0 +1,3 @@
1
+ from gllm_inference.prompt_builder.prompt_builder import PromptBuilder as PromptBuilder
2
+
3
+ __all__ = ['PromptBuilder']
@@ -0,0 +1,56 @@
1
+ from _typeshed import Incomplete
2
+ from gllm_inference.schema import Message as Message, MessageContent as MessageContent, MessageRole as MessageRole
3
+ from typing import Any
4
+
5
+ KEY_EXTRACTOR_REGEX: Incomplete
6
+
7
+ class PromptBuilder:
8
+ """A prompt builder class used in Gen AI applications.
9
+
10
+ Attributes:
11
+ system_template (str): The system prompt template. May contain placeholders enclosed in curly braces `{}`.
12
+ user_template (str): The user prompt template. May contain placeholders enclosed in curly braces `{}`.
13
+ prompt_key_set (set[str]): A set of expected keys that must be present in the prompt templates.
14
+ key_defaults (dict[str, str]): Default values for the keys in the prompt templates.
15
+ """
16
+ system_template: Incomplete
17
+ user_template: Incomplete
18
+ prompt_key_set: Incomplete
19
+ key_defaults: Incomplete
20
+ def __init__(self, system_template: str = '', user_template: str = '', key_defaults: dict[str, str] | None = None, ignore_extra_keys: bool | None = None) -> None:
21
+ """Initializes a new instance of the PromptBuilder class.
22
+
23
+ Args:
24
+ system_template (str, optional): The system prompt template. May contain placeholders enclosed in curly
25
+ braces `{}`. Defaults to an empty string.
26
+ user_template (str, optional): The user prompt template. May contain placeholders enclosed in curly
27
+ braces `{}`. Defaults to an empty string.
28
+ key_defaults (dict[str, str] | None, optional): Default values for the keys in the prompt templates.
29
+ Applied when the corresponding keys are not provided in the runtime input.
30
+ Defaults to None, in which case no default values will be assigned to the keys.
31
+ ignore_extra_keys (bool | None, optional): Deprecated parameter. Will be removed in v0.6. Extra keys
32
+ will always raise a warning only instead of raising an error.
33
+
34
+ Raises:
35
+ ValueError: If both `system_template` and `user_template` are empty.
36
+ """
37
+ def format(self, history: list[Message] | None = None, extra_contents: list[MessageContent] | None = None, **kwargs: Any) -> list[Message]:
38
+ """Formats the prompt templates into a list of messages.
39
+
40
+ This method processes each prompt template, replacing the placeholders in the template content with the
41
+ corresponding values from `kwargs`. If any required key is missing from `kwargs`, it raises a `ValueError`.
42
+ It also handles the provided history and extra contents. It formats the prompt as a list of messages.
43
+
44
+ Args:
45
+ history (list[Message] | None, optional): The history to be included in the prompt. Defaults to None.
46
+ extra_contents (list[MessageContent] | None, optional): The extra contents to be included in the user
47
+ message. Defaults to None.
48
+ **kwargs (Any): A dictionary of placeholder values to be injected into the prompt templates.
49
+ Values must be either a string or an object that can be serialized to a string.
50
+
51
+ Returns:
52
+ list[Message]: A formatted list of messages.
53
+
54
+ Raises:
55
+ ValueError: If a required key for the prompt template is missing from `kwargs`.
56
+ """
@@ -0,0 +1,7 @@
1
+ from gllm_inference.prompt_formatter.agnostic_prompt_formatter import AgnosticPromptFormatter as AgnosticPromptFormatter
2
+ from gllm_inference.prompt_formatter.huggingface_prompt_formatter import HuggingFacePromptFormatter as HuggingFacePromptFormatter
3
+ from gllm_inference.prompt_formatter.llama_prompt_formatter import LlamaPromptFormatter as LlamaPromptFormatter
4
+ from gllm_inference.prompt_formatter.mistral_prompt_formatter import MistralPromptFormatter as MistralPromptFormatter
5
+ from gllm_inference.prompt_formatter.openai_prompt_formatter import OpenAIPromptFormatter as OpenAIPromptFormatter
6
+
7
+ __all__ = ['AgnosticPromptFormatter', 'HuggingFacePromptFormatter', 'LlamaPromptFormatter', 'MistralPromptFormatter', 'OpenAIPromptFormatter']