gllm-inference-binary 0.5.55__cp313-cp313-macosx_13_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.

Potentially problematic release.


This version of gllm-inference-binary might be problematic. Click here for more details.

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 +12 -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 +318 -0
  43. gllm_inference/lm_invoker/azure_openai_lm_invoker.pyi +237 -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 +212 -0
  47. gllm_inference/lm_invoker/datasaur_lm_invoker.pyi +157 -0
  48. gllm_inference/lm_invoker/google_lm_invoker.pyi +327 -0
  49. gllm_inference/lm_invoker/langchain_lm_invoker.pyi +239 -0
  50. gllm_inference/lm_invoker/litellm_lm_invoker.pyi +224 -0
  51. gllm_inference/lm_invoker/lm_invoker.pyi +165 -0
  52. gllm_inference/lm_invoker/openai_chat_completions_lm_invoker.pyi +253 -0
  53. gllm_inference/lm_invoker/openai_compatible_lm_invoker.pyi +52 -0
  54. gllm_inference/lm_invoker/openai_lm_invoker.pyi +404 -0
  55. gllm_inference/lm_invoker/portkey_lm_invoker.pyi +296 -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 +253 -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 +80 -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 +188 -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 +154 -0
  134. gllm_inference_binary-0.5.55.dist-info/METADATA +138 -0
  135. gllm_inference_binary-0.5.55.dist-info/RECORD +137 -0
  136. gllm_inference_binary-0.5.55.dist-info/WHEEL +5 -0
  137. gllm_inference_binary-0.5.55.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,253 @@
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
+ Text output:
54
+ The `XAILMInvoker` generates text outputs by default.
55
+ Text outputs are stored in the `outputs` attribute of the `LMOutput` object and can be accessed
56
+ via the `texts` (all text outputs) or `text` (first text output) properties.
57
+
58
+ Output example:
59
+ ```python
60
+ LMOutput(outputs=[LMOutputItem(type="text", output="Hello, there!")])
61
+ ```
62
+
63
+ Structured output:
64
+ The `XAILMInvoker` can be configured to generate structured outputs.
65
+ This feature can be enabled by providing a schema to the `response_schema` parameter.
66
+
67
+ Structured outputs are stored in the `outputs` attribute of the `LMOutput` object and can be accessed
68
+ via the `structureds` (all structured outputs) or `structured` (first structured output) properties.
69
+
70
+ The schema must either be one of the following:
71
+ 1. A Pydantic BaseModel class
72
+ The structured output will be a Pydantic model.
73
+ 2. A JSON schema dictionary
74
+ JSON dictionary schema must be compatible with Pydantic\'s JSON schema, especially for complex schemas.
75
+ Thus, it is recommended to create the JSON schema using Pydantic\'s `model_json_schema` method.
76
+ The structured output will be a dictionary.
77
+
78
+ Usage example:
79
+ ```python
80
+ class Animal(BaseModel):
81
+ name: str
82
+ color: str
83
+
84
+ json_schema = Animal.model_json_schema()
85
+
86
+ lm_invoker = XAILMInvoker(..., response_schema=Animal) # Using Pydantic BaseModel class
87
+ lm_invoker = XAILMInvoker(..., response_schema=json_schema) # Using JSON schema dictionary
88
+ ```
89
+
90
+ Output example:
91
+ ```python
92
+ # Using Pydantic BaseModel class outputs a Pydantic model
93
+ LMOutput(outputs=[LMOutputItem(type="structured", output=Animal(name="dog", color="white"))])
94
+
95
+ # Using JSON schema dictionary outputs a dictionary
96
+ LMOutput(outputs=[LMOutputItem(type="structured", output={"name": "dog", "color": "white"})])
97
+ ```
98
+
99
+ When structured output is enabled, streaming is disabled.
100
+
101
+ Tool calling:
102
+ The `XAILMInvoker` can be configured to call tools to perform certain tasks.
103
+ This feature can be enabled by providing a list of `Tool` objects to the `tools` parameter.
104
+
105
+ Tool calls outputs are stored in the `outputs` attribute of the `LMOutput` object and
106
+ can be accessed via the `tool_calls` property.
107
+
108
+ Usage example:
109
+ ```python
110
+ lm_invoker = XAILMInvoker(..., tools=[tool_1, tool_2])
111
+ ```
112
+
113
+ Output example:
114
+ ```python
115
+ LMOutput(
116
+ outputs=[
117
+ LMOutputItem(type="text", output="I\'m using tools..."),
118
+ LMOutputItem(type="tool_call", output=ToolCall(id="123", name="tool_1", args={"key": "value"})),
119
+ LMOutputItem(type="tool_call", output=ToolCall(id="456", name="tool_2", args={"key": "value"})),
120
+ ]
121
+ )
122
+ ```
123
+
124
+ Reasoning:
125
+ The `XAILMInvoker` performs step-by-step reasoning before generating a response when reasoning
126
+ models are used, such as `grok-3-mini`.
127
+
128
+ For some models, the reasoning effort can be set via the `reasoning_effort` parameter, which guides
129
+ the models on the amount of reasoning tokens to generate. Available options include `low` and `high`.
130
+
131
+ Some models may also output the reasoning tokens. In this case, the reasoning tokens are stored in
132
+ the `outputs` attribute of the `LMOutput` object and can be accessed via the `thinkings` property.
133
+
134
+ Usage example:
135
+ ```python
136
+ lm_invoker = XAILMInvoker(model_name="grok-3-mini", reasoning_effort="low")
137
+ ```
138
+
139
+ Output example:
140
+ ```python
141
+ LMOutput(
142
+ outputs=[
143
+ LMOutputItem(type="thinking", output=Reasoning(reasoning="I\'m thinking...", ...)),
144
+ LMOutputItem(type="text", output="Golden retriever is a good dog breed."),
145
+ ]
146
+ )
147
+ ```
148
+
149
+ Streaming output example:
150
+ ```python
151
+ {"type": "thinking_start", "value": "", ...}
152
+ {"type": "thinking", "value": "I\'m ", ...}
153
+ {"type": "thinking", "value": "thinking...", ...}
154
+ {"type": "thinking_end", "value": "", ...}
155
+ {"type": "response", "value": "Golden retriever ", ...}
156
+ {"type": "response", "value": "is a good dog breed.", ...}
157
+ ```
158
+ Note: By default, the thinking token will be streamed with the legacy `EventType.DATA` event type.
159
+ To use the new simplified streamed event format, set the `simplify_events` parameter to `True` during
160
+ LM invoker initialization. The legacy event format support will be removed in v0.6.
161
+
162
+ Web Search:
163
+ The `XAILMInvoker` can be configured to search the web for relevant information.
164
+ This feature can be enabled by setting the `web_search` parameter to `True`.
165
+
166
+ Web search citations are stored in the `outputs` attribute of the `LMOutput` object and
167
+ can be accessed via the `citations` property.
168
+
169
+ Usage example:
170
+ ```python
171
+ lm_invoker = XAILMInvoker(..., web_search=True)
172
+ ```
173
+
174
+ Output example:
175
+ ```python
176
+ LMOutput(
177
+ outputs=[
178
+ LMOutputItem(type="citation", output=Chunk(id="123", content="...", metadata={...}, score=None)),
179
+ LMOutputItem(type="text", output="According to recent reports... ([Source](https://example.com))."),
180
+ ],
181
+ )
182
+ ```
183
+
184
+ Analytics tracking:
185
+ The `XAILMInvoker` can be configured to output additional information about the invocation.
186
+ This feature can be enabled by setting the `output_analytics` parameter to `True`.
187
+
188
+ When enabled, the following attributes will be stored in the output:
189
+ 1. `token_usage`: The token usage.
190
+ 2. `duration`: The duration in seconds.
191
+ 3. `finish_details`: The details about how the generation finished.
192
+
193
+ Output example:
194
+ ```python
195
+ LMOutput(
196
+ outputs=[...],
197
+ token_usage=TokenUsage(input_tokens=100, output_tokens=50),
198
+ duration=0.729,
199
+ finish_details={"stop_reason": "end_turn"},
200
+ )
201
+ ```
202
+
203
+ When streaming is enabled, token usage is not supported.
204
+
205
+ Retry and timeout:
206
+ The `XAILMInvoker` supports retry and timeout configuration.
207
+ By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
208
+ They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
209
+
210
+ Retry config examples:
211
+ ```python
212
+ retry_config = RetryConfig(max_retries=0, timeout=None) # No retry, no timeout
213
+ retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
214
+ ```
215
+
216
+ Usage example:
217
+ ```python
218
+ lm_invoker = XAILMInvoker(..., retry_config=retry_config)
219
+ ```
220
+ '''
221
+ reasoning_effort: Incomplete
222
+ web_search: Incomplete
223
+ client_params: Incomplete
224
+ 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:
225
+ """Initializes a new instance of the XAILMInvoker class.
226
+
227
+ Args:
228
+ model_name (str): The name of the xAI model.
229
+ api_key (str | None, optional): The API key for authenticating with xAI. Defaults to None, in which
230
+ case the `XAI_API_KEY` environment variable will be used.
231
+ model_kwargs (dict[str, Any] | None, optional): Additional model parameters. Defaults to None.
232
+ default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
233
+ Defaults to None.
234
+ tools (list[Tool | LangChainTool] | None, optional): Tools provided to the language model to enable tool
235
+ calling.
236
+ Defaults to None.
237
+ response_schema (ResponseSchema | None, optional): The schema of the response. If provided, the model will
238
+ output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema
239
+ dictionary. Defaults to None.
240
+ output_analytics (bool, optional): Whether to output the invocation analytics. Defaults to False.
241
+ retry_config (RetryConfig | None, optional): The retry configuration for the language model.
242
+ Defaults to None, in which case a default config with no retry and 30.0 seconds timeout is used.
243
+ reasoning_effort (ReasoningEffort | None, optional): The reasoning effort for reasoning models. Not allowed
244
+ for non-reasoning models. If None, the model will perform medium reasoning effort. Defaults to None.
245
+ web_search (bool, optional): Whether to enable the web search. Defaults to False.
246
+ simplify_events (bool, optional): Temporary parameter to control the streamed events format.
247
+ When True, uses the simplified events format. When False, uses the legacy events format for
248
+ backward compatibility. Will be removed in v0.6. Defaults to False.
249
+
250
+ Raises:
251
+ ValueError:
252
+ 1. `reasoning_effort` is provided, but is not a valid ReasoningEffort.
253
+ """
@@ -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
+ """