gllm-inference-binary 0.5.12__cp312-cp312-macosx_13_0_x86_64.whl → 0.5.14__cp312-cp312-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.
- gllm_inference/builder/build_lm_invoker.pyi +12 -1
- gllm_inference/constants.pyi +1 -0
- gllm_inference/lm_invoker/__init__.pyi +2 -1
- gllm_inference/lm_invoker/schema/xai.pyi +31 -0
- gllm_inference/lm_invoker/xai_lm_invoker.pyi +303 -0
- gllm_inference/request_processor/lm_request_processor.pyi +12 -3
- gllm_inference/schema/model_id.pyi +9 -0
- gllm_inference/schema/type_alias.pyi +1 -1
- gllm_inference.cpython-312-darwin.so +0 -0
- gllm_inference.pyi +7 -0
- {gllm_inference_binary-0.5.12.dist-info → gllm_inference_binary-0.5.14.dist-info}/METADATA +4 -2
- {gllm_inference_binary-0.5.12.dist-info → gllm_inference_binary-0.5.14.dist-info}/RECORD +13 -11
- {gllm_inference_binary-0.5.12.dist-info → gllm_inference_binary-0.5.14.dist-info}/WHEEL +0 -0
@@ -1,5 +1,5 @@
|
|
1
1
|
from _typeshed import Incomplete
|
2
|
-
from gllm_inference.lm_invoker import AnthropicLMInvoker as AnthropicLMInvoker, AzureOpenAILMInvoker as AzureOpenAILMInvoker, BedrockLMInvoker as BedrockLMInvoker, DatasaurLMInvoker as DatasaurLMInvoker, GoogleLMInvoker as GoogleLMInvoker, LangChainLMInvoker as LangChainLMInvoker, LiteLLMLMInvoker as LiteLLMLMInvoker, OpenAICompatibleLMInvoker as OpenAICompatibleLMInvoker, OpenAILMInvoker as OpenAILMInvoker
|
2
|
+
from gllm_inference.lm_invoker import AnthropicLMInvoker as AnthropicLMInvoker, AzureOpenAILMInvoker as AzureOpenAILMInvoker, BedrockLMInvoker as BedrockLMInvoker, DatasaurLMInvoker as DatasaurLMInvoker, GoogleLMInvoker as GoogleLMInvoker, LangChainLMInvoker as LangChainLMInvoker, LiteLLMLMInvoker as LiteLLMLMInvoker, OpenAICompatibleLMInvoker as OpenAICompatibleLMInvoker, OpenAILMInvoker as OpenAILMInvoker, XAILMInvoker as XAILMInvoker
|
3
3
|
from gllm_inference.lm_invoker.lm_invoker import BaseLMInvoker as BaseLMInvoker
|
4
4
|
from gllm_inference.schema.model_id import ModelId as ModelId, ModelProvider as ModelProvider
|
5
5
|
from typing import Any
|
@@ -144,6 +144,17 @@ def build_lm_invoker(model_id: str | ModelId, credentials: str | dict[str, Any]
|
|
144
144
|
For the list of supported providers, please refer to the following page:
|
145
145
|
https://docs.litellm.ai/docs/providers/
|
146
146
|
|
147
|
+
# Using xAI
|
148
|
+
```python
|
149
|
+
lm_invoker = build_lm_invoker(
|
150
|
+
model_id="xai/grok-3",
|
151
|
+
credentials="xai-..."
|
152
|
+
)
|
153
|
+
```
|
154
|
+
The credentials can also be provided through the `XAI_API_KEY` environment variable.
|
155
|
+
For the list of supported models, please refer to the following page:
|
156
|
+
https://docs.x.ai/docs/models
|
157
|
+
|
147
158
|
Security warning:
|
148
159
|
Please provide the LM invoker credentials ONLY to the `credentials` parameter. Do not put any kind of
|
149
160
|
credentials in the `config` parameter as the content of the `config` parameter will be logged.
|
gllm_inference/constants.pyi
CHANGED
@@ -7,5 +7,6 @@ from gllm_inference.lm_invoker.langchain_lm_invoker import LangChainLMInvoker as
|
|
7
7
|
from gllm_inference.lm_invoker.litellm_lm_invoker import LiteLLMLMInvoker as LiteLLMLMInvoker
|
8
8
|
from gllm_inference.lm_invoker.openai_compatible_lm_invoker import OpenAICompatibleLMInvoker as OpenAICompatibleLMInvoker
|
9
9
|
from gllm_inference.lm_invoker.openai_lm_invoker import OpenAILMInvoker as OpenAILMInvoker
|
10
|
+
from gllm_inference.lm_invoker.xai_lm_invoker import XAILMInvoker as XAILMInvoker
|
10
11
|
|
11
|
-
__all__ = ['AnthropicLMInvoker', 'AzureOpenAILMInvoker', 'BedrockLMInvoker', 'DatasaurLMInvoker', 'GoogleLMInvoker', 'LangChainLMInvoker', 'LiteLLMLMInvoker', 'OpenAICompatibleLMInvoker', 'OpenAILMInvoker']
|
12
|
+
__all__ = ['AnthropicLMInvoker', 'AzureOpenAILMInvoker', 'BedrockLMInvoker', 'DatasaurLMInvoker', 'GoogleLMInvoker', 'LangChainLMInvoker', 'LiteLLMLMInvoker', 'OpenAICompatibleLMInvoker', 'OpenAILMInvoker', 'XAILMInvoker']
|
@@ -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,303 @@
|
|
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.lm_invoker.lm_invoker import BaseLMInvoker as BaseLMInvoker
|
7
|
+
from gllm_inference.lm_invoker.schema.xai import Key as Key, ReasoningEffort as ReasoningEffort
|
8
|
+
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
|
9
|
+
from gllm_inference.utils.validation import validate_string_enum as validate_string_enum
|
10
|
+
from langchain_core.tools import Tool as LangChainTool
|
11
|
+
from typing import Any
|
12
|
+
|
13
|
+
SUPPORTED_ATTACHMENTS: Incomplete
|
14
|
+
|
15
|
+
class XAILMInvoker(BaseLMInvoker):
|
16
|
+
'''A language model invoker to interact with xAI language models.
|
17
|
+
|
18
|
+
Attributes:
|
19
|
+
model_id (str): The model ID of the language model.
|
20
|
+
model_provider (str): The provider of the language model.
|
21
|
+
model_name (str): The name of the language model.
|
22
|
+
client_params (dict[str, Any]): The xAI client initialization parameters.
|
23
|
+
default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the model.
|
24
|
+
tools (list[Tool]): The list of tools provided to the model to enable tool calling.
|
25
|
+
response_schema (ResponseSchema | None): The schema of the response. If provided, the model will output a
|
26
|
+
structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema dictionary.
|
27
|
+
output_analytics (bool): Whether to output the invocation analytics.
|
28
|
+
retry_config (RetryConfig | None): The retry configuration for the language model.
|
29
|
+
reasoning_effort (ReasoningEffort | None): The reasoning effort level for reasoning models ("low" or "high").
|
30
|
+
web_search (bool): Whether to enable the web search.
|
31
|
+
|
32
|
+
|
33
|
+
Basic usage:
|
34
|
+
The `XAILMInvoker` can be used as follows:
|
35
|
+
```python
|
36
|
+
lm_invoker = XAILMInvoker(model_name="grok-3")
|
37
|
+
result = await lm_invoker.invoke("Hi there!")
|
38
|
+
```
|
39
|
+
|
40
|
+
Input types:
|
41
|
+
The `XAILMInvoker` supports the following input types: text and image.
|
42
|
+
Non-text inputs can be passed as an `Attachment` object with the `user` role.
|
43
|
+
|
44
|
+
Usage example:
|
45
|
+
```python
|
46
|
+
text = "What animal is in this image?"
|
47
|
+
image = Attachment.from_path("path/to/local/image.png")
|
48
|
+
result = await lm_invoker.invoke([text, image])
|
49
|
+
```
|
50
|
+
|
51
|
+
Tool calling:
|
52
|
+
Tool calling is a feature that allows the language model to call tools to perform tasks.
|
53
|
+
Tools can be passed to the via the `tools` parameter as a list of `Tool` objects.
|
54
|
+
When tools are provided and the model decides to call a tool, the tool calls are stored in the
|
55
|
+
`tool_calls` attribute in the output.
|
56
|
+
|
57
|
+
Usage example:
|
58
|
+
```python
|
59
|
+
lm_invoker = XAILMInvoker(..., tools=[tool_1, tool_2])
|
60
|
+
```
|
61
|
+
|
62
|
+
Output example:
|
63
|
+
```python
|
64
|
+
LMOutput(
|
65
|
+
response="Let me call the tools...",
|
66
|
+
tool_calls=[
|
67
|
+
ToolCall(id="123", name="tool_1", args={"key": "value"}),
|
68
|
+
ToolCall(id="456", name="tool_2", args={"key": "value"}),
|
69
|
+
]
|
70
|
+
)
|
71
|
+
```
|
72
|
+
|
73
|
+
Structured output:
|
74
|
+
Structured output is a feature that allows the language model to output a structured response.
|
75
|
+
This feature can be enabled by providing a schema to the `response_schema` parameter.
|
76
|
+
|
77
|
+
The schema must be either a JSON schema dictionary or a Pydantic BaseModel class.
|
78
|
+
If JSON schema is used, it must be compatible with Pydantic\'s JSON schema, especially for complex schemas.
|
79
|
+
For this reason, it is recommended to create the JSON schema using Pydantic\'s `model_json_schema` method.
|
80
|
+
|
81
|
+
The language model also doesn\'t need to stream anything when structured output is enabled. Thus, standard
|
82
|
+
invocation will be performed regardless of whether the `event_emitter` parameter is provided or not.
|
83
|
+
|
84
|
+
When enabled, the structured output is stored in the `structured_output` attribute in the output.
|
85
|
+
1. If the schema is a JSON schema dictionary, the structured output is a dictionary.
|
86
|
+
2. If the schema is a Pydantic BaseModel class, the structured output is a Pydantic model.
|
87
|
+
|
88
|
+
# Example 1: Using a JSON schema dictionary
|
89
|
+
Usage example:
|
90
|
+
```python
|
91
|
+
schema = {
|
92
|
+
"title": "Animal",
|
93
|
+
"description": "A description of an animal.",
|
94
|
+
"properties": {
|
95
|
+
"color": {"title": "Color", "type": "string"},
|
96
|
+
"name": {"title": "Name", "type": "string"},
|
97
|
+
},
|
98
|
+
"required": ["name", "color"],
|
99
|
+
"type": "object",
|
100
|
+
}
|
101
|
+
lm_invoker = XAILMInvoker(..., response_schema=schema)
|
102
|
+
```
|
103
|
+
Output example:
|
104
|
+
```python
|
105
|
+
LMOutput(structured_output={"name": "Golden retriever", "color": "Golden"})
|
106
|
+
```
|
107
|
+
|
108
|
+
# Example 2: Using a Pydantic BaseModel class
|
109
|
+
Usage example:
|
110
|
+
```python
|
111
|
+
class Animal(BaseModel):
|
112
|
+
name: str
|
113
|
+
color: str
|
114
|
+
|
115
|
+
lm_invoker = XAILMInvoker(..., response_schema=Animal)
|
116
|
+
```
|
117
|
+
Output example:
|
118
|
+
```python
|
119
|
+
LMOutput(structured_output=Animal(name="Golden retriever", color="Golden"))
|
120
|
+
```
|
121
|
+
|
122
|
+
Reasoning:
|
123
|
+
Reasoning effort is a feature specific to xAI\'s reasoning models that allows you to control the level
|
124
|
+
of reasoning performed by the model. This feature can be enabled by setting the `reasoning_effort` parameter.
|
125
|
+
Valid values are "low" and "high".
|
126
|
+
|
127
|
+
Please note that Grok 4 does not have a `reasoning_effort` parameter. If a `reasoning_effort` is provided,
|
128
|
+
the request will return error.
|
129
|
+
|
130
|
+
Usage example:
|
131
|
+
```python
|
132
|
+
lm_invoker = XAILMInvoker(
|
133
|
+
model_name="grok-3",
|
134
|
+
reasoning_effort="high" # Enable high reasoning effort
|
135
|
+
)
|
136
|
+
```
|
137
|
+
|
138
|
+
When reasoning effort is enabled, the model\'s internal reasoning process is captured and stored in the
|
139
|
+
`reasoning` attribute in the output.
|
140
|
+
|
141
|
+
Output example:
|
142
|
+
```python
|
143
|
+
LMOutput(
|
144
|
+
response="The answer is 42",
|
145
|
+
reasoning=[
|
146
|
+
Reasoning(
|
147
|
+
id="reasoning_1",
|
148
|
+
reasoning="First, I need to understand the question. The user is asking about..."
|
149
|
+
)
|
150
|
+
]
|
151
|
+
)
|
152
|
+
```
|
153
|
+
|
154
|
+
When streaming is enabled along with reasoning summary, the reasoning summary token will be streamed with the
|
155
|
+
`EventType.DATA` event type.
|
156
|
+
|
157
|
+
Streaming output example:
|
158
|
+
```python
|
159
|
+
{"type": "data", "value": \'{"data_type": "thinking_start", "data_value": ""}\', ...}
|
160
|
+
{"type": "data", "value": \'{"data_type": "thinking", "data_value": "Let me think "}\', ...}
|
161
|
+
{"type": "data", "value": \'{"data_type": "thinking", "data_value": "about it..."}\', ...}
|
162
|
+
{"type": "data", "value": \'{"data_type": "thinking_end", "data_value": ""}\', ...}
|
163
|
+
{"type": "response", "value": "Golden retriever ", ...}
|
164
|
+
{"type": "response", "value": "is a good dog breed.", ...}
|
165
|
+
```
|
166
|
+
|
167
|
+
Setting reasoning-related parameters for non-reasoning models will raise an error.
|
168
|
+
|
169
|
+
Analytics tracking:
|
170
|
+
Analytics tracking is a feature that allows the module to output additional information about the invocation.
|
171
|
+
This feature can be enabled by setting the `output_analytics` parameter to `True`.
|
172
|
+
When enabled, the following attributes will be stored in the output:
|
173
|
+
1. `token_usage`: The token usage.
|
174
|
+
2. `finish_details`: The details about how the generation finished.
|
175
|
+
|
176
|
+
Output example:
|
177
|
+
```python
|
178
|
+
LMOutput(
|
179
|
+
response="Golden retriever is a good dog breed.",
|
180
|
+
token_usage=TokenUsage(input_tokens=100, output_tokens=50),
|
181
|
+
finish_details={"finish_reason": "stop"},
|
182
|
+
)
|
183
|
+
```
|
184
|
+
|
185
|
+
When streaming is enabled, token usage is not supported. Therefore, the `token_usage` attribute will be `None`
|
186
|
+
regardless of the value of the `output_analytics` parameter.
|
187
|
+
|
188
|
+
Retry and timeout:
|
189
|
+
The `XAILMInvoker` supports retry and timeout configuration.
|
190
|
+
By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
|
191
|
+
They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
|
192
|
+
|
193
|
+
Retry config examples:
|
194
|
+
```python
|
195
|
+
retry_config = RetryConfig(max_retries=0, timeout=0.0) # No retry, no timeout
|
196
|
+
retry_config = RetryConfig(max_retries=0, timeout=10.0) # No retry, 10.0 seconds timeout
|
197
|
+
retry_config = RetryConfig(max_retries=5, timeout=0.0) # 5 max retries, no timeout
|
198
|
+
retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
|
199
|
+
```
|
200
|
+
|
201
|
+
Usage example:
|
202
|
+
```python
|
203
|
+
lm_invoker = XAILMInvoker(..., retry_config=retry_config)
|
204
|
+
```
|
205
|
+
|
206
|
+
Web Search:
|
207
|
+
The web search is a feature that allows the language model to search the web for relevant information.
|
208
|
+
This feature can be enabled by setting the `web_search` parameter to `True`.
|
209
|
+
|
210
|
+
Usage example:
|
211
|
+
```python
|
212
|
+
lm_invoker = XAILMInvoker(
|
213
|
+
model_name="grok-3",
|
214
|
+
web_search=True
|
215
|
+
)
|
216
|
+
```
|
217
|
+
|
218
|
+
When web search is enabled, the language model will search for relevant information and may cite the
|
219
|
+
relevant sources (including from X platform). The citations will be stored as `Chunk` objects in the `citations`
|
220
|
+
attribute in the output.
|
221
|
+
|
222
|
+
Output example:
|
223
|
+
```python
|
224
|
+
LMOutput(
|
225
|
+
response="According to recent reports, the latest AI developments include... ([Source](https://example.com)).",
|
226
|
+
citations=[
|
227
|
+
Chunk(
|
228
|
+
id="search_result_1",
|
229
|
+
content="Latest AI developments report",
|
230
|
+
metadata={
|
231
|
+
"start_index": 164,
|
232
|
+
"end_index": 275,
|
233
|
+
"title": "Example title",
|
234
|
+
"url": "https://www.example.com",
|
235
|
+
"type": "url_citation",
|
236
|
+
},
|
237
|
+
),
|
238
|
+
],
|
239
|
+
)
|
240
|
+
```
|
241
|
+
|
242
|
+
When streaming is enabled, the live search activities will be streamed with the `EventType.DATA` event type.
|
243
|
+
This allows you to track the search process in real-time.
|
244
|
+
|
245
|
+
Streaming output example:
|
246
|
+
```python
|
247
|
+
{"type": "data", "value": \'{"data_type": "activity", "data_value": "{\\"query\\": \\"search query\\"}", ...}\', ...}
|
248
|
+
{"type": "response", "value": "According to recent reports, ", ...}
|
249
|
+
{"type": "response", "value": "the latest AI developments include...", ...}
|
250
|
+
```
|
251
|
+
|
252
|
+
Output types:
|
253
|
+
The output of the `XAILMInvoker` can either be:
|
254
|
+
1. `str`: The text response if no additional output is needed.
|
255
|
+
2. `LMOutput`: A Pydantic model with the following attributes if any additional output is needed:
|
256
|
+
2.1. response (str): The text response.
|
257
|
+
2.2. tool_calls (list[ToolCall]): The tool calls, if the `tools` parameter is defined and the language
|
258
|
+
model decides to invoke tools. Defaults to an empty list.
|
259
|
+
2.3. structured_output (dict[str, Any] | BaseModel | None): The structured output, if the `response_schema`
|
260
|
+
parameter is defined. Defaults to None.
|
261
|
+
2.4. token_usage (TokenUsage | None): The token usage analytics, if the `output_analytics` parameter is
|
262
|
+
set to `True`. Defaults to None.
|
263
|
+
2.5. duration (float | None): The duration of the invocation in seconds, if the `output_analytics`
|
264
|
+
parameter is set to `True`. Defaults to None.
|
265
|
+
2.6. finish_details (dict[str, Any] | None): The details about how the generation finished, if the
|
266
|
+
`output_analytics` parameter is set to `True`. Defaults to None.
|
267
|
+
2.7. reasoning (list[Reasoning]): The reasoning objects, if the `reasoning_effort` parameter is set.
|
268
|
+
Defaults to an empty list.
|
269
|
+
2.8. citations (list[Chunk]): The citations, if the web_search is enabled and the language model decides
|
270
|
+
to cite the relevant sources. Defaults to an empty list.
|
271
|
+
2.9. code_exec_results (list[CodeExecResult]): The code execution results. Currently not supported.
|
272
|
+
Defaults to an empty list.
|
273
|
+
'''
|
274
|
+
reasoning_effort: Incomplete
|
275
|
+
web_search: Incomplete
|
276
|
+
client_params: Incomplete
|
277
|
+
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:
|
278
|
+
"""Initializes a new instance of the XAILMInvoker class.
|
279
|
+
|
280
|
+
Args:
|
281
|
+
model_name (str): The name of the xAI model.
|
282
|
+
api_key (str | None, optional): The API key for authenticating with xAI. Defaults to None, in which
|
283
|
+
case the `XAI_API_KEY` environment variable will be used.
|
284
|
+
model_kwargs (dict[str, Any] | None, optional): Additional model parameters. Defaults to None.
|
285
|
+
default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
|
286
|
+
Defaults to None.
|
287
|
+
tools (list[Tool | LangChainTool] | None, optional): Tools provided to the language model to enable tool
|
288
|
+
calling.
|
289
|
+
Defaults to None.
|
290
|
+
response_schema (ResponseSchema | None, optional): The schema of the response. If provided, the model will
|
291
|
+
output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema
|
292
|
+
dictionary. Defaults to None.
|
293
|
+
output_analytics (bool, optional): Whether to output the invocation analytics. Defaults to False.
|
294
|
+
retry_config (RetryConfig | None, optional): The retry configuration for the language model.
|
295
|
+
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout is used.
|
296
|
+
reasoning_effort (ReasoningEffort | None, optional): The reasoning effort for reasoning models. Not allowed
|
297
|
+
for non-reasoning models. If None, the model will perform medium reasoning effort. Defaults to None.
|
298
|
+
web_search (bool, optional): Whether to enable the web search. Defaults to False.
|
299
|
+
|
300
|
+
Raises:
|
301
|
+
ValueError:
|
302
|
+
1. `reasoning_effort` is provided, but is not a valid ReasoningEffort.
|
303
|
+
"""
|
@@ -60,7 +60,7 @@ class LMRequestProcessor:
|
|
60
60
|
|
61
61
|
This method clears the response schema for the LM invoker.
|
62
62
|
"""
|
63
|
-
async def process(self, prompt_kwargs: dict[str, Any] | None = None, history: list[Message] | None = None, extra_contents: list[MessageContent] | None = None, hyperparameters: dict[str, Any] | None = None, event_emitter: EventEmitter | None = None, auto_execute_tools: bool = True, max_lm_calls: int = 5) -> Any:
|
63
|
+
async def process(self, prompt_kwargs: dict[str, Any] | None = None, history: list[Message] | None = None, extra_contents: list[MessageContent] | None = None, hyperparameters: dict[str, Any] | None = None, event_emitter: EventEmitter | None = None, auto_execute_tools: bool = True, max_lm_calls: int = 5, **kwargs: Any) -> Any:
|
64
64
|
"""Processes a language model inference request.
|
65
65
|
|
66
66
|
This method processes the language model inference request as follows:
|
@@ -72,8 +72,8 @@ class LMRequestProcessor:
|
|
72
72
|
LMOutput object, the output parser will process the `response` attribute of the LMOutput object.
|
73
73
|
|
74
74
|
Args:
|
75
|
-
prompt_kwargs (dict[str, Any], optional):
|
76
|
-
|
75
|
+
prompt_kwargs (dict[str, Any], optional): Deprecated parameter for passing prompt kwargs.
|
76
|
+
Replaced by **kwargs. Defaults to None
|
77
77
|
history (list[Message] | None, optional): A list of conversation history to be included in the prompt.
|
78
78
|
Defaults to None.
|
79
79
|
extra_contents (list[MessageContent] | None, optional): A list of extra contents to be included in the
|
@@ -86,6 +86,15 @@ class LMRequestProcessor:
|
|
86
86
|
tool calls. Defaults to True.
|
87
87
|
max_lm_calls (int, optional): The maximum number of times the language model can be invoked
|
88
88
|
when `auto_execute_tools` is True. Defaults to 5.
|
89
|
+
**kwargs (Any): Keyword arguments that will be passed to format the prompt builder.
|
90
|
+
Values must be either a string or an object that can be serialized to a string.
|
91
|
+
Reserved keyword arguments that cannot be passed to the prompt builder include:
|
92
|
+
1. `history`
|
93
|
+
2. `extra_contents`
|
94
|
+
3. `hyperparameters`
|
95
|
+
4. `event_emitter`
|
96
|
+
5. `auto_execute_tools`
|
97
|
+
6. `max_lm_calls`
|
89
98
|
|
90
99
|
Returns:
|
91
100
|
Any: The result of the language model invocation, optionally parsed by the output parser.
|
@@ -19,6 +19,7 @@ class ModelProvider(StrEnum):
|
|
19
19
|
OPENAI_COMPATIBLE = 'openai-compatible'
|
20
20
|
TWELVELABS = 'twelvelabs'
|
21
21
|
VOYAGE = 'voyage'
|
22
|
+
XAI = 'xai'
|
22
23
|
|
23
24
|
class ModelId(BaseModel):
|
24
25
|
'''Defines a representation of a valid model id.
|
@@ -88,12 +89,20 @@ class ModelId(BaseModel):
|
|
88
89
|
For the list of supported providers, please refer to the following page:
|
89
90
|
https://docs.litellm.ai/docs/providers/
|
90
91
|
|
92
|
+
# Using XAI
|
93
|
+
```python
|
94
|
+
model_id = ModelId.from_string("xai/grok-4-0709")
|
95
|
+
```
|
96
|
+
For the list of supported models, please refer to the following page:
|
97
|
+
https://docs.x.ai/docs/models
|
98
|
+
|
91
99
|
Custom model name validation example:
|
92
100
|
```python
|
93
101
|
validation_map = {
|
94
102
|
ModelProvider.ANTHROPIC: {"claude-3-5-sonnet-latest"},
|
95
103
|
ModelProvider.GOOGLE: {"gemini-1.5-flash", "gemini-1.5-pro"},
|
96
104
|
ModelProvider.OPENAI: {"gpt-4o", "gpt-4o-mini"},
|
105
|
+
}
|
97
106
|
|
98
107
|
model_id = ModelId.from_string("...", validation_map)
|
99
108
|
```
|
@@ -1,5 +1,5 @@
|
|
1
1
|
from aiohttp import ClientResponse
|
2
|
-
from gllm_inference.schema.
|
2
|
+
from gllm_inference.schema.attachment import Attachment as Attachment
|
3
3
|
from gllm_inference.schema.reasoning import Reasoning as Reasoning
|
4
4
|
from gllm_inference.schema.tool_call import ToolCall as ToolCall
|
5
5
|
from gllm_inference.schema.tool_result import ToolResult as ToolResult
|
Binary file
|
gllm_inference.pyi
CHANGED
@@ -28,6 +28,7 @@ import gllm_inference.lm_invoker.LangChainLMInvoker
|
|
28
28
|
import gllm_inference.lm_invoker.LiteLLMLMInvoker
|
29
29
|
import gllm_inference.lm_invoker.OpenAICompatibleLMInvoker
|
30
30
|
import gllm_inference.lm_invoker.OpenAILMInvoker
|
31
|
+
import gllm_inference.lm_invoker.XAILMInvoker
|
31
32
|
import gllm_inference.prompt_builder.PromptBuilder
|
32
33
|
import gllm_inference.output_parser.JSONOutputParser
|
33
34
|
import json
|
@@ -100,6 +101,12 @@ import langchain_core.utils.function_calling
|
|
100
101
|
import gllm_inference.schema.MessageContent
|
101
102
|
import gllm_inference.utils.validate_string_enum
|
102
103
|
import gllm_inference.schema.CodeExecResult
|
104
|
+
import xai_sdk
|
105
|
+
import xai_sdk.chat
|
106
|
+
import xai_sdk.search
|
107
|
+
import xai_sdk.proto
|
108
|
+
import xai_sdk.proto.v6
|
109
|
+
import xai_sdk.proto.v6.chat_pb2
|
103
110
|
import transformers
|
104
111
|
import gllm_inference.prompt_formatter.HuggingFacePromptFormatter
|
105
112
|
import gllm_core.utils.logger_manager
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: gllm-inference-binary
|
3
|
-
Version: 0.5.
|
3
|
+
Version: 0.5.14
|
4
4
|
Summary: A library containing components related to model inferences in Gen AI applications.
|
5
5
|
Author: Henry Wicaksono
|
6
6
|
Author-email: henry.wicaksono@gdplabs.id
|
@@ -17,6 +17,7 @@ Provides-Extra: litellm
|
|
17
17
|
Provides-Extra: openai
|
18
18
|
Provides-Extra: twelvelabs
|
19
19
|
Provides-Extra: voyage
|
20
|
+
Provides-Extra: xai
|
20
21
|
Requires-Dist: aioboto3 (>=15.0.0,<16.0.0) ; extra == "bedrock"
|
21
22
|
Requires-Dist: aiohttp (>=3.12.14,<4.0.0)
|
22
23
|
Requires-Dist: anthropic (>=0.60.0,<0.61.0) ; extra == "anthropic"
|
@@ -32,13 +33,14 @@ Requires-Dist: litellm (>=1.69.2,<2.0.0) ; extra == "litellm"
|
|
32
33
|
Requires-Dist: openai (>=1.98.0,<2.0.0) ; extra == "datasaur" or extra == "openai"
|
33
34
|
Requires-Dist: pandas (>=2.2.3,<3.0.0)
|
34
35
|
Requires-Dist: poetry (>=2.1.3,<3.0.0)
|
35
|
-
Requires-Dist: protobuf (>=
|
36
|
+
Requires-Dist: protobuf (>=6.0.0,<7.0.0)
|
36
37
|
Requires-Dist: python-magic (>=0.4.27,<0.5.0) ; sys_platform != "win32"
|
37
38
|
Requires-Dist: python-magic-bin (>=0.4.14,<0.5.0) ; sys_platform == "win32"
|
38
39
|
Requires-Dist: sentencepiece (>=0.2.0,<0.3.0)
|
39
40
|
Requires-Dist: transformers (==4.52.4) ; extra == "huggingface"
|
40
41
|
Requires-Dist: twelvelabs (>=0.4.4,<0.5.0) ; extra == "twelvelabs"
|
41
42
|
Requires-Dist: voyageai (>=0.3.0,<0.4.0) ; (python_version < "3.13") and (extra == "voyage")
|
43
|
+
Requires-Dist: xai_sdk (>=1.0.0,<2.0.0) ; extra == "xai"
|
42
44
|
Description-Content-Type: text/markdown
|
43
45
|
|
44
46
|
# GLLM Inference
|
@@ -1,14 +1,14 @@
|
|
1
1
|
gllm_inference/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
2
|
gllm_inference/builder/__init__.pyi,sha256=usz2lvfwO4Yk-ZGKXbCWG1cEr3nlQXxMNDNC-2yc1NM,500
|
3
3
|
gllm_inference/builder/build_em_invoker.pyi,sha256=YL71GriZEXn4uxmXBJHWC200QdWRPwUJY_G0kKi5-dk,5352
|
4
|
-
gllm_inference/builder/build_lm_invoker.pyi,sha256=
|
4
|
+
gllm_inference/builder/build_lm_invoker.pyi,sha256=igJdLnWiY5QcdT4EClvgxFGSVZjARpq5hz2FYcBHWEQ,6876
|
5
5
|
gllm_inference/builder/build_lm_request_processor.pyi,sha256=33Gi3onftl-V2e_mkJios5zmXRKSoAVPX3UK7YBExjk,4491
|
6
6
|
gllm_inference/builder/build_output_parser.pyi,sha256=_Lrq-bh1oPsb_Nwkkr_zyEUwIOMysRFZkvEtEM29LZM,936
|
7
7
|
gllm_inference/catalog/__init__.pyi,sha256=JBkPGTyiiZ30GECzJBW-mW8LekWyY2qyzal3eW7ynaM,287
|
8
8
|
gllm_inference/catalog/catalog.pyi,sha256=a4RNG1lKv51GxQpOqh47tz-PAROMPaeP2o5XNLBSZaU,4790
|
9
9
|
gllm_inference/catalog/lm_request_processor_catalog.pyi,sha256=ranHMbG9--DZj9FJRhIUa6U8e-L-Tm-_hSBpzJ6DDs4,5428
|
10
10
|
gllm_inference/catalog/prompt_builder_catalog.pyi,sha256=OU8k_4HbqjZEzHZlzSM3uzGQZJmM2uGD76Csqom0CEQ,3197
|
11
|
-
gllm_inference/constants.pyi,sha256=
|
11
|
+
gllm_inference/constants.pyi,sha256=KDzHmjVYjd0uTHqLgIzgHhLZx99D8jGBIg74eO8KQv0,314
|
12
12
|
gllm_inference/em_invoker/__init__.pyi,sha256=XESsrYo1PZeeHe7AMRyuzKoV7XDD5oN89ZTH01zRf4k,873
|
13
13
|
gllm_inference/em_invoker/azure_openai_em_invoker.pyi,sha256=OEkVu5nv92ITqdhDtgDg4MiLSDRWDmLSnAhYtXpCn6E,4602
|
14
14
|
gllm_inference/em_invoker/em_invoker.pyi,sha256=hiH8FB5R-KxhI8Ds2htF3cjRcIcH92yHPcOdpgc4FDo,4341
|
@@ -30,7 +30,7 @@ gllm_inference/em_invoker/voyage_em_invoker.pyi,sha256=7akaf8GxOA8Trokad0xmlYKr4
|
|
30
30
|
gllm_inference/exceptions/__init__.pyi,sha256=v9uxjW5DssIn7n_bKqT7L83CeqFET2Z45GFOvi78UuE,977
|
31
31
|
gllm_inference/exceptions/error_parser.pyi,sha256=4RkVfS2Fl9kjz_h2bK9eoAeI-Y-VkHcUqXWj68BsYig,2393
|
32
32
|
gllm_inference/exceptions/exceptions.pyi,sha256=5YRackwVNvyOJjOtiVszqu8q87s8ioXTa-XwaYmeiC4,4643
|
33
|
-
gllm_inference/lm_invoker/__init__.pyi,sha256=
|
33
|
+
gllm_inference/lm_invoker/__init__.pyi,sha256=NmQSqObPjevEP1KbbrNnaz4GMh175EVPERZ19vK5Emc,1202
|
34
34
|
gllm_inference/lm_invoker/anthropic_lm_invoker.pyi,sha256=MsF3OmDo0L9aEHuTJYTgsoDILi2B_IgKtPpDcDMduWc,14925
|
35
35
|
gllm_inference/lm_invoker/azure_openai_lm_invoker.pyi,sha256=EV_yrj6mnV_rCDEqSZaIikfw76_rXXyDlC-w_y-m7K0,14603
|
36
36
|
gllm_inference/lm_invoker/bedrock_lm_invoker.pyi,sha256=IuLxgCThOSBHx1AXqnhL6yVu5_JV6hAeGBWWm5P1JCo,12423
|
@@ -49,6 +49,8 @@ gllm_inference/lm_invoker/schema/google.pyi,sha256=AIsNgq0ZZuicHmx4bL7z6q-946T05
|
|
49
49
|
gllm_inference/lm_invoker/schema/langchain.pyi,sha256=l2kHU7S3vmG3-NCt8B26krp_i4Br3waES_CekkgrKSA,409
|
50
50
|
gllm_inference/lm_invoker/schema/openai.pyi,sha256=w_XSzOohX_7vnR81hVXdgDbBqk737LmMAN_AvODGk2I,1902
|
51
51
|
gllm_inference/lm_invoker/schema/openai_compatible.pyi,sha256=m3bL2hVpxI_crURIi1bGDUqMy1Z5OgKBVU_-BkhX1mg,1166
|
52
|
+
gllm_inference/lm_invoker/schema/xai.pyi,sha256=cWnbJmDtllqRH3NXpQbiXgkNBcUXr8ksDSDywcgJebE,632
|
53
|
+
gllm_inference/lm_invoker/xai_lm_invoker.pyi,sha256=wPzjSLLiPb4DB1gJjtCs6URPUN0JCDcIxeNRsmD6tbo,15420
|
52
54
|
gllm_inference/model/__init__.pyi,sha256=qClHIgljqhPPCKlGTKmHsWgYb4_hADybxtC2q1U8a5Q,593
|
53
55
|
gllm_inference/model/em/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
54
56
|
gllm_inference/model/em/google_em.pyi,sha256=ZPN5LmReO0bcTfnZixFooUTzgD-daNFPzfxzZ-5WzQQ,471
|
@@ -72,7 +74,7 @@ gllm_inference/prompt_formatter/mistral_prompt_formatter.pyi,sha256=DgFitxfvCSJf
|
|
72
74
|
gllm_inference/prompt_formatter/openai_prompt_formatter.pyi,sha256=QB7gHddipQuAolUKO01ApZeaRxBtRZzglS5B78mzsV8,1286
|
73
75
|
gllm_inference/prompt_formatter/prompt_formatter.pyi,sha256=UkcPi5ao98OGJyNRsqfhYTlMW-ZLNITaGZUTwzvBzqk,1146
|
74
76
|
gllm_inference/request_processor/__init__.pyi,sha256=hVnfdNZnkTBJHnmLtN3Na4ANP0yK6AstWdIizVr2Apo,227
|
75
|
-
gllm_inference/request_processor/lm_request_processor.pyi,sha256=
|
77
|
+
gllm_inference/request_processor/lm_request_processor.pyi,sha256=VnYc8E3Iayyhw-rPnGPfTKuO3ohgFsS8HPrZJeyES5I,5889
|
76
78
|
gllm_inference/request_processor/uses_lm_mixin.pyi,sha256=He-ytjwv2H5Hn312WFBAlBK96ALKTtDO3AT_80hCGTg,2321
|
77
79
|
gllm_inference/schema/__init__.pyi,sha256=aQx7eKVsFNgJkYtbbKppa9Ww2WfTe0yzl_ewajDCo6w,1363
|
78
80
|
gllm_inference/schema/attachment.pyi,sha256=jApuzjOHJDCz4lr4MlHzBgIndh559nbWu2Xp1fk3hso,3297
|
@@ -80,18 +82,18 @@ gllm_inference/schema/code_exec_result.pyi,sha256=ZTHh6JtRrPIdQ059P1UAiD2L-tAO1_
|
|
80
82
|
gllm_inference/schema/enums.pyi,sha256=Nvc_Qsd8yyiH_tCtymN39O6EZ0DT_wxYHmlKLllxC00,605
|
81
83
|
gllm_inference/schema/lm_output.pyi,sha256=GafJV0KeD-VSwWkwG1oz-uruXrQ7KDZTuoojPCBRpg8,1956
|
82
84
|
gllm_inference/schema/message.pyi,sha256=VP9YppKj2mo1esl9cy6qQO9m2mMHUjTmfGDdyUor880,2220
|
83
|
-
gllm_inference/schema/model_id.pyi,sha256=
|
85
|
+
gllm_inference/schema/model_id.pyi,sha256=0UJS7M91hPlzWuZI3CMGZm9ewYrTxmLUMtIhHqJOg0Q,5481
|
84
86
|
gllm_inference/schema/reasoning.pyi,sha256=SlTuiDw87GdnAn-I6YOPIJRhEBiwQljM46JohG05guQ,562
|
85
87
|
gllm_inference/schema/token_usage.pyi,sha256=1GTQVORV0dBNmD_jix8aVaUqxMKFF04KpLP7y2urqbk,2950
|
86
88
|
gllm_inference/schema/tool_call.pyi,sha256=zQaVxCnkVxOfOEhBidqohU85gb4PRwnwBiygKaunamk,389
|
87
89
|
gllm_inference/schema/tool_result.pyi,sha256=cAG7TVtB4IWJPt8XBBbB92cuY1ZsX9M276bN9aqjcvM,276
|
88
|
-
gllm_inference/schema/type_alias.pyi,sha256=
|
90
|
+
gllm_inference/schema/type_alias.pyi,sha256=cQRlLT5vz9YV50n9x5BmufgqUz0UByInpmAvHSv2WTY,719
|
89
91
|
gllm_inference/utils/__init__.pyi,sha256=npmBmmlBv7cPHMg1hdL3S2_RelD6vk_LhCsGELhN_7s,295
|
90
92
|
gllm_inference/utils/langchain.pyi,sha256=VluQiHkGigDdqLUbhB6vnXiISCP5hHqV0qokYY6dC1A,1164
|
91
93
|
gllm_inference/utils/validation.pyi,sha256=toxBtRp-VItC_X7sNi-GDd7sjibBdWMrR0q01OI2D7k,385
|
92
94
|
gllm_inference.build/.gitignore,sha256=aEiIwOuxfzdCmLZe4oB1JsBmCUxwG8x-u-HBCV9JT8E,1
|
93
|
-
gllm_inference.cpython-312-darwin.so,sha256=
|
94
|
-
gllm_inference.pyi,sha256=
|
95
|
-
gllm_inference_binary-0.5.
|
96
|
-
gllm_inference_binary-0.5.
|
97
|
-
gllm_inference_binary-0.5.
|
95
|
+
gllm_inference.cpython-312-darwin.so,sha256=SyNNjOX7JJUhUMm2moSA-Tor_BxMOWiD0Tx6x2xujVs,3957120
|
96
|
+
gllm_inference.pyi,sha256=Ho74MJb64Q0MQI7xTOf7pmM675HXs3ZQfLKg2kmusDg,3520
|
97
|
+
gllm_inference_binary-0.5.14.dist-info/METADATA,sha256=_PX1mmZ2KxIQu7Tp9zlYLjTwSBl0UzG9ewo8UPe5y6w,4608
|
98
|
+
gllm_inference_binary-0.5.14.dist-info/WHEEL,sha256=eE2zhpXf8mNi4Sj7Wo77hQIVjvfcPTxg9pdEi0RABeA,107
|
99
|
+
gllm_inference_binary-0.5.14.dist-info/RECORD,,
|
File without changes
|