gllm-inference-binary 0.5.51b3__cp313-cp313-macosx_11_0_arm64.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.
Files changed (137) hide show
  1. gllm_inference/__init__.pyi +0 -0
  2. gllm_inference/builder/__init__.pyi +6 -0
  3. gllm_inference/builder/_build_invoker.pyi +28 -0
  4. gllm_inference/builder/build_em_invoker.pyi +130 -0
  5. gllm_inference/builder/build_lm_invoker.pyi +213 -0
  6. gllm_inference/builder/build_lm_request_processor.pyi +88 -0
  7. gllm_inference/builder/build_output_parser.pyi +29 -0
  8. gllm_inference/catalog/__init__.pyi +4 -0
  9. gllm_inference/catalog/catalog.pyi +121 -0
  10. gllm_inference/catalog/lm_request_processor_catalog.pyi +112 -0
  11. gllm_inference/catalog/prompt_builder_catalog.pyi +82 -0
  12. gllm_inference/constants.pyi +13 -0
  13. gllm_inference/em_invoker/__init__.pyi +12 -0
  14. gllm_inference/em_invoker/azure_openai_em_invoker.pyi +88 -0
  15. gllm_inference/em_invoker/bedrock_em_invoker.pyi +118 -0
  16. gllm_inference/em_invoker/cohere_em_invoker.pyi +128 -0
  17. gllm_inference/em_invoker/em_invoker.pyi +90 -0
  18. gllm_inference/em_invoker/google_em_invoker.pyi +129 -0
  19. gllm_inference/em_invoker/jina_em_invoker.pyi +103 -0
  20. gllm_inference/em_invoker/langchain/__init__.pyi +3 -0
  21. gllm_inference/em_invoker/langchain/em_invoker_embeddings.pyi +84 -0
  22. gllm_inference/em_invoker/langchain_em_invoker.pyi +46 -0
  23. gllm_inference/em_invoker/openai_compatible_em_invoker.pyi +41 -0
  24. gllm_inference/em_invoker/openai_em_invoker.pyi +118 -0
  25. gllm_inference/em_invoker/schema/__init__.pyi +0 -0
  26. gllm_inference/em_invoker/schema/bedrock.pyi +29 -0
  27. gllm_inference/em_invoker/schema/cohere.pyi +20 -0
  28. gllm_inference/em_invoker/schema/google.pyi +9 -0
  29. gllm_inference/em_invoker/schema/jina.pyi +29 -0
  30. gllm_inference/em_invoker/schema/langchain.pyi +5 -0
  31. gllm_inference/em_invoker/schema/openai.pyi +7 -0
  32. gllm_inference/em_invoker/schema/openai_compatible.pyi +7 -0
  33. gllm_inference/em_invoker/schema/twelvelabs.pyi +17 -0
  34. gllm_inference/em_invoker/schema/voyage.pyi +15 -0
  35. gllm_inference/em_invoker/twelevelabs_em_invoker.pyi +101 -0
  36. gllm_inference/em_invoker/voyage_em_invoker.pyi +104 -0
  37. gllm_inference/exceptions/__init__.pyi +4 -0
  38. gllm_inference/exceptions/error_parser.pyi +41 -0
  39. gllm_inference/exceptions/exceptions.pyi +132 -0
  40. gllm_inference/exceptions/provider_error_map.pyi +24 -0
  41. gllm_inference/lm_invoker/__init__.pyi +14 -0
  42. gllm_inference/lm_invoker/anthropic_lm_invoker.pyi +334 -0
  43. gllm_inference/lm_invoker/azure_openai_lm_invoker.pyi +254 -0
  44. gllm_inference/lm_invoker/batch/__init__.pyi +3 -0
  45. gllm_inference/lm_invoker/batch/batch_operations.pyi +127 -0
  46. gllm_inference/lm_invoker/bedrock_lm_invoker.pyi +226 -0
  47. gllm_inference/lm_invoker/datasaur_lm_invoker.pyi +157 -0
  48. gllm_inference/lm_invoker/google_lm_invoker.pyi +336 -0
  49. gllm_inference/lm_invoker/langchain_lm_invoker.pyi +251 -0
  50. gllm_inference/lm_invoker/litellm_lm_invoker.pyi +244 -0
  51. gllm_inference/lm_invoker/lm_invoker.pyi +164 -0
  52. gllm_inference/lm_invoker/openai_chat_completions_lm_invoker.pyi +272 -0
  53. gllm_inference/lm_invoker/openai_compatible_lm_invoker.pyi +52 -0
  54. gllm_inference/lm_invoker/openai_lm_invoker.pyi +433 -0
  55. gllm_inference/lm_invoker/portkey_lm_invoker.pyi +260 -0
  56. gllm_inference/lm_invoker/schema/__init__.pyi +0 -0
  57. gllm_inference/lm_invoker/schema/anthropic.pyi +56 -0
  58. gllm_inference/lm_invoker/schema/bedrock.pyi +53 -0
  59. gllm_inference/lm_invoker/schema/datasaur.pyi +14 -0
  60. gllm_inference/lm_invoker/schema/google.pyi +24 -0
  61. gllm_inference/lm_invoker/schema/langchain.pyi +23 -0
  62. gllm_inference/lm_invoker/schema/openai.pyi +106 -0
  63. gllm_inference/lm_invoker/schema/openai_chat_completions.pyi +62 -0
  64. gllm_inference/lm_invoker/schema/portkey.pyi +31 -0
  65. gllm_inference/lm_invoker/schema/xai.pyi +31 -0
  66. gllm_inference/lm_invoker/xai_lm_invoker.pyi +289 -0
  67. gllm_inference/model/__init__.pyi +12 -0
  68. gllm_inference/model/em/__init__.pyi +0 -0
  69. gllm_inference/model/em/cohere_em.pyi +17 -0
  70. gllm_inference/model/em/google_em.pyi +16 -0
  71. gllm_inference/model/em/jina_em.pyi +22 -0
  72. gllm_inference/model/em/openai_em.pyi +15 -0
  73. gllm_inference/model/em/twelvelabs_em.pyi +13 -0
  74. gllm_inference/model/em/voyage_em.pyi +20 -0
  75. gllm_inference/model/lm/__init__.pyi +0 -0
  76. gllm_inference/model/lm/anthropic_lm.pyi +22 -0
  77. gllm_inference/model/lm/google_lm.pyi +18 -0
  78. gllm_inference/model/lm/openai_lm.pyi +27 -0
  79. gllm_inference/model/lm/xai_lm.pyi +19 -0
  80. gllm_inference/output_parser/__init__.pyi +3 -0
  81. gllm_inference/output_parser/json_output_parser.pyi +60 -0
  82. gllm_inference/output_parser/output_parser.pyi +27 -0
  83. gllm_inference/prompt_builder/__init__.pyi +3 -0
  84. gllm_inference/prompt_builder/format_strategy/__init__.pyi +4 -0
  85. gllm_inference/prompt_builder/format_strategy/format_strategy.pyi +55 -0
  86. gllm_inference/prompt_builder/format_strategy/jinja_format_strategy.pyi +45 -0
  87. gllm_inference/prompt_builder/format_strategy/string_format_strategy.pyi +20 -0
  88. gllm_inference/prompt_builder/prompt_builder.pyi +69 -0
  89. gllm_inference/prompt_formatter/__init__.pyi +7 -0
  90. gllm_inference/prompt_formatter/agnostic_prompt_formatter.pyi +49 -0
  91. gllm_inference/prompt_formatter/huggingface_prompt_formatter.pyi +55 -0
  92. gllm_inference/prompt_formatter/llama_prompt_formatter.pyi +59 -0
  93. gllm_inference/prompt_formatter/mistral_prompt_formatter.pyi +53 -0
  94. gllm_inference/prompt_formatter/openai_prompt_formatter.pyi +35 -0
  95. gllm_inference/prompt_formatter/prompt_formatter.pyi +30 -0
  96. gllm_inference/realtime_chat/__init__.pyi +3 -0
  97. gllm_inference/realtime_chat/google_realtime_chat.pyi +205 -0
  98. gllm_inference/realtime_chat/input_streamer/__init__.pyi +4 -0
  99. gllm_inference/realtime_chat/input_streamer/input_streamer.pyi +36 -0
  100. gllm_inference/realtime_chat/input_streamer/keyboard_input_streamer.pyi +27 -0
  101. gllm_inference/realtime_chat/input_streamer/linux_mic_input_streamer.pyi +36 -0
  102. gllm_inference/realtime_chat/output_streamer/__init__.pyi +4 -0
  103. gllm_inference/realtime_chat/output_streamer/console_output_streamer.pyi +21 -0
  104. gllm_inference/realtime_chat/output_streamer/linux_speaker_output_streamer.pyi +42 -0
  105. gllm_inference/realtime_chat/output_streamer/output_streamer.pyi +33 -0
  106. gllm_inference/realtime_chat/realtime_chat.pyi +28 -0
  107. gllm_inference/request_processor/__init__.pyi +4 -0
  108. gllm_inference/request_processor/lm_request_processor.pyi +101 -0
  109. gllm_inference/request_processor/uses_lm_mixin.pyi +130 -0
  110. gllm_inference/schema/__init__.pyi +18 -0
  111. gllm_inference/schema/activity.pyi +64 -0
  112. gllm_inference/schema/attachment.pyi +88 -0
  113. gllm_inference/schema/code_exec_result.pyi +14 -0
  114. gllm_inference/schema/config.pyi +15 -0
  115. gllm_inference/schema/enums.pyi +69 -0
  116. gllm_inference/schema/events.pyi +105 -0
  117. gllm_inference/schema/lm_input.pyi +4 -0
  118. gllm_inference/schema/lm_output.pyi +44 -0
  119. gllm_inference/schema/mcp.pyi +31 -0
  120. gllm_inference/schema/message.pyi +52 -0
  121. gllm_inference/schema/model_id.pyi +176 -0
  122. gllm_inference/schema/reasoning.pyi +15 -0
  123. gllm_inference/schema/token_usage.pyi +75 -0
  124. gllm_inference/schema/tool_call.pyi +14 -0
  125. gllm_inference/schema/tool_result.pyi +11 -0
  126. gllm_inference/schema/type_alias.pyi +11 -0
  127. gllm_inference/utils/__init__.pyi +5 -0
  128. gllm_inference/utils/io_utils.pyi +26 -0
  129. gllm_inference/utils/langchain.pyi +30 -0
  130. gllm_inference/utils/validation.pyi +12 -0
  131. gllm_inference.build/.gitignore +1 -0
  132. gllm_inference.cpython-313-darwin.so +0 -0
  133. gllm_inference.pyi +157 -0
  134. gllm_inference_binary-0.5.51b3.dist-info/METADATA +138 -0
  135. gllm_inference_binary-0.5.51b3.dist-info/RECORD +137 -0
  136. gllm_inference_binary-0.5.51b3.dist-info/WHEEL +5 -0
  137. gllm_inference_binary-0.5.51b3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,289 @@
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, LMOutput as LMOutput, Message as Message, MessageRole as MessageRole, ModelId as ModelId, ModelProvider as ModelProvider, Reasoning as Reasoning, ResponseSchema as ResponseSchema, ThinkingEvent as ThinkingEvent, 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
+ Streaming output example:
157
+ ```python
158
+ {"type": "thinking_start", "value": ""}\', ...}
159
+ {"type": "thinking", "value": "Let me think "}\', ...}
160
+ {"type": "thinking", "value": "about it..."}\', ...}
161
+ {"type": "thinking_end", "value": ""}\', ...}
162
+ {"type": "response", "value": "Golden retriever ", ...}
163
+ {"type": "response", "value": "is a good dog breed.", ...}
164
+ ```
165
+ Note: By default, the thinking token will be streamed with the legacy `EventType.DATA` event type.
166
+ To use the new simplified streamed event format, set the `simplify_events` parameter to `True` during
167
+ LM invoker initialization. The legacy event format support will be removed in v0.6.
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=None) # 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=None) # 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
222
+ `citations` attribute in the output.
223
+
224
+ Output example:
225
+ ```python
226
+ LMOutput(
227
+ response="According to recent reports, the latest AI developments... ([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
+ Output types:
245
+ The output of the `XAILMInvoker` can either be:
246
+ 1. `str`: A text response.
247
+ 2. `LMOutput`: A Pydantic model that may contain the following attributes:
248
+ 2.1. response (str)
249
+ 2.2. tool_calls (list[ToolCall])
250
+ 2.3. structured_output (dict[str, Any] | BaseModel | None)
251
+ 2.4. token_usage (TokenUsage | None)
252
+ 2.5. duration (float | None)
253
+ 2.6. finish_details (dict[str, Any])
254
+ 2.7. reasoning (list[Reasoning])
255
+ 2.8. citations (list[Chunk])
256
+ '''
257
+ reasoning_effort: Incomplete
258
+ web_search: Incomplete
259
+ client_params: Incomplete
260
+ 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, simplify_events: bool = False) -> None:
261
+ """Initializes a new instance of the XAILMInvoker class.
262
+
263
+ Args:
264
+ model_name (str): The name of the xAI model.
265
+ api_key (str | None, optional): The API key for authenticating with xAI. Defaults to None, in which
266
+ case the `XAI_API_KEY` environment variable will be used.
267
+ model_kwargs (dict[str, Any] | None, optional): Additional model parameters. Defaults to None.
268
+ default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
269
+ Defaults to None.
270
+ tools (list[Tool | LangChainTool] | None, optional): Tools provided to the language model to enable tool
271
+ calling.
272
+ Defaults to None.
273
+ response_schema (ResponseSchema | None, optional): The schema of the response. If provided, the model will
274
+ output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema
275
+ dictionary. Defaults to None.
276
+ output_analytics (bool, optional): Whether to output the invocation analytics. Defaults to False.
277
+ retry_config (RetryConfig | None, optional): The retry configuration for the language model.
278
+ Defaults to None, in which case a default config with no retry and 30.0 seconds timeout is used.
279
+ reasoning_effort (ReasoningEffort | None, optional): The reasoning effort for reasoning models. Not allowed
280
+ for non-reasoning models. If None, the model will perform medium reasoning effort. Defaults to None.
281
+ web_search (bool, optional): Whether to enable the web search. Defaults to False.
282
+ simplify_events (bool, optional): Temporary parameter to control the streamed events format.
283
+ When True, uses the simplified events format. When False, uses the legacy events format for
284
+ backward compatibility. Will be removed in v0.6. Defaults to False.
285
+
286
+ Raises:
287
+ ValueError:
288
+ 1. `reasoning_effort` is provided, but is not a valid ReasoningEffort.
289
+ """
@@ -0,0 +1,12 @@
1
+ from gllm_inference.model.em.cohere_em import CohereEM as CohereEM
2
+ from gllm_inference.model.em.google_em import GoogleEM as GoogleEM
3
+ from gllm_inference.model.em.jina_em import JinaEM as JinaEM
4
+ from gllm_inference.model.em.openai_em import OpenAIEM as OpenAIEM
5
+ from gllm_inference.model.em.twelvelabs_em import TwelveLabsEM as TwelveLabsEM
6
+ from gllm_inference.model.em.voyage_em import VoyageEM as VoyageEM
7
+ from gllm_inference.model.lm.anthropic_lm import AnthropicLM as AnthropicLM
8
+ from gllm_inference.model.lm.google_lm import GoogleLM as GoogleLM
9
+ from gllm_inference.model.lm.openai_lm import OpenAILM as OpenAILM
10
+ from gllm_inference.model.lm.xai_lm import XAILM as XAILM
11
+
12
+ __all__ = ['AnthropicLM', 'CohereEM', 'GoogleEM', 'GoogleLM', 'JinaEM', 'OpenAIEM', 'OpenAILM', 'TwelveLabsEM', 'VoyageEM', 'XAILM']
File without changes
@@ -0,0 +1,17 @@
1
+ class CohereEM:
2
+ '''Defines Cohere embedding model names constants.
3
+
4
+ Usage example:
5
+ ```python
6
+ from gllm_inference.model import CohereEM
7
+ from gllm_inference.em_invoker import CohereEMInvoker
8
+
9
+ em_invoker = CohereEMInvoker(CohereEM.EMBED_V4_0)
10
+ result = await em_invoker.invoke("Hello, world!")
11
+ ```
12
+ '''
13
+ EMBED_V4_0: str
14
+ EMBED_ENGLISH_V3_0: str
15
+ EMBED_ENGLISH_LIGHT_V3_0: str
16
+ EMBED_MULTILINGUAL_V3_0: str
17
+ EMBED_MULTILINGUAL_LIGHT_V3_0: str
@@ -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,22 @@
1
+ class JinaEM:
2
+ '''Defines Jina embedding model names constants.
3
+
4
+ Usage example:
5
+ ```python
6
+ from gllm_inference.model import JinaEM
7
+ from gllm_inference.em_invoker import JinaEMInvoker
8
+
9
+ em_invoker = JinaEMInvoker(JinaEM.JINA_EMBEDDINGS_V4)
10
+ result = await em_invoker.invoke("Hello, world!")
11
+ ```
12
+ '''
13
+ JINA_EMBEDDINGS_V4: str
14
+ JINA_EMBEDDINGS_V3: str
15
+ JINA_EMBEDDINGS_V2_BASE_EN: str
16
+ JINA_EMBEDDINGS_V2_BASE_CODE: str
17
+ JINA_CLIP_V2: str
18
+ JINA_CLIP_V1: str
19
+ JINA_CODE_EMBEDDINGS_1_5B: str
20
+ JINA_CODE_EMBEDDINGS_0_5B: str
21
+ JINA_COLBERT_V2: str
22
+ JINA_COLBERT_V1_EN: 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,22 @@
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_5: str
16
+ CLAUDE_SONNET_4: str
17
+ CLAUDE_SONNET_3_7: str
18
+ CLAUDE_SONNET_3_5: str
19
+ CLAUDE_HAIKU_4_5: str
20
+ CLAUDE_HAIKU_3_5: str
21
+ CLAUDE_OPUS_3: str
22
+ CLAUDE_HAIKU_3: str
@@ -0,0 +1,18 @@
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_IMAGE: str
16
+ GEMINI_2_5_FLASH_LITE: str
17
+ GEMINI_2_0_FLASH: str
18
+ 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,19 @@
1
+ class XAILM:
2
+ '''Defines XAI language model names constants.
3
+
4
+ Usage example:
5
+ ```python
6
+ from gllm_inference.model import XAILM
7
+ from gllm_inference.lm_invoker import XAILMInvoker
8
+
9
+ lm_invoker = XAILMInvoker(XAILM.GROK_4_FAST_REASONING)
10
+ response = await lm_invoker.invoke("Hello, world!")
11
+ ```
12
+ '''
13
+ GROK_CODE_FAST_1: str
14
+ GROK_4_FAST_REASONING: str
15
+ GROK_4_FAST_NON_REASONING: str
16
+ GROK_4_0709: str
17
+ GROK_3_MINI: str
18
+ GROK_3: str
19
+ GROK_2_VISION_1212: 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,4 @@
1
+ from gllm_inference.prompt_builder.format_strategy.jinja_format_strategy import JinjaFormatStrategy as JinjaFormatStrategy
2
+ from gllm_inference.prompt_builder.format_strategy.string_format_strategy import StringFormatStrategy as StringFormatStrategy
3
+
4
+ __all__ = ['StringFormatStrategy', 'JinjaFormatStrategy']
@@ -0,0 +1,55 @@
1
+ import abc
2
+ from _typeshed import Incomplete
3
+ from abc import ABC, abstractmethod
4
+ from gllm_inference.schema.message import MessageContent as MessageContent
5
+
6
+ class BasePromptFormattingStrategy(ABC, metaclass=abc.ABCMeta):
7
+ """Base class for prompt formatting strategies.
8
+
9
+ This class defines the interface for different prompt templating engines. Subclasses
10
+ implement specific formatting strategies to render templates with variable
11
+ substitution.
12
+
13
+ The strategy pattern allows the PromptBuilder to work with different templating engines
14
+ without changing its core logic.
15
+
16
+ Attributes:
17
+ key_defaults (dict[str, str]): The default values for the keys.
18
+ """
19
+ key_defaults: Incomplete
20
+ def __init__(self, key_defaults: dict[str, str] | None = None) -> None:
21
+ """Initialize the BasePromptFormattingStrategy.
22
+
23
+ Args:
24
+ key_defaults (dict[str, str] | None, optional): The default values for the keys. Defaults to None,
25
+ in which case no default values are used.
26
+ """
27
+ def format(self, template: str, variables_map: dict[str, str] | None = None, extra_contents: list[MessageContent] | None = None) -> list[str]:
28
+ """Format template with variables using the template method pattern.
29
+
30
+ This is a template method that defines the algorithm for formatting:
31
+ 1. Merge key_defaults and variables_map
32
+ 2. Render the template (delegated to subclass via _render_template)
33
+ 3. Append extra_contents to the result
34
+
35
+ Args:
36
+ template (str): Template string to format.
37
+ variables_map (dict[str, str] | None, optional): Variables for substitution. Defaults to None.
38
+ extra_contents (list[MessageContent] | None, optional): Extra contents to format. Defaults to None.
39
+
40
+ Returns:
41
+ str: Formatted template string.
42
+ """
43
+ @abstractmethod
44
+ def extract_keys(self, template: str | None) -> set[str]:
45
+ """Extract variable keys from template.
46
+
47
+ Args:
48
+ template (str | None): Template string to extract keys from.
49
+
50
+ Returns:
51
+ set[str]: Set of variable keys found in template.
52
+
53
+ Raises:
54
+ NotImplementedError: If the method is not implemented.
55
+ """