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.
- gllm_inference/__init__.pyi +0 -0
- gllm_inference/builder/__init__.pyi +6 -0
- gllm_inference/builder/_build_invoker.pyi +28 -0
- gllm_inference/builder/build_em_invoker.pyi +130 -0
- gllm_inference/builder/build_lm_invoker.pyi +213 -0
- gllm_inference/builder/build_lm_request_processor.pyi +88 -0
- gllm_inference/builder/build_output_parser.pyi +29 -0
- gllm_inference/catalog/__init__.pyi +4 -0
- gllm_inference/catalog/catalog.pyi +121 -0
- gllm_inference/catalog/lm_request_processor_catalog.pyi +112 -0
- gllm_inference/catalog/prompt_builder_catalog.pyi +82 -0
- gllm_inference/constants.pyi +13 -0
- gllm_inference/em_invoker/__init__.pyi +12 -0
- gllm_inference/em_invoker/azure_openai_em_invoker.pyi +88 -0
- gllm_inference/em_invoker/bedrock_em_invoker.pyi +118 -0
- gllm_inference/em_invoker/cohere_em_invoker.pyi +128 -0
- gllm_inference/em_invoker/em_invoker.pyi +90 -0
- gllm_inference/em_invoker/google_em_invoker.pyi +129 -0
- gllm_inference/em_invoker/jina_em_invoker.pyi +103 -0
- gllm_inference/em_invoker/langchain/__init__.pyi +3 -0
- gllm_inference/em_invoker/langchain/em_invoker_embeddings.pyi +84 -0
- gllm_inference/em_invoker/langchain_em_invoker.pyi +46 -0
- gllm_inference/em_invoker/openai_compatible_em_invoker.pyi +41 -0
- gllm_inference/em_invoker/openai_em_invoker.pyi +118 -0
- gllm_inference/em_invoker/schema/__init__.pyi +0 -0
- gllm_inference/em_invoker/schema/bedrock.pyi +29 -0
- gllm_inference/em_invoker/schema/cohere.pyi +20 -0
- gllm_inference/em_invoker/schema/google.pyi +9 -0
- gllm_inference/em_invoker/schema/jina.pyi +29 -0
- gllm_inference/em_invoker/schema/langchain.pyi +5 -0
- gllm_inference/em_invoker/schema/openai.pyi +7 -0
- gllm_inference/em_invoker/schema/openai_compatible.pyi +7 -0
- gllm_inference/em_invoker/schema/twelvelabs.pyi +17 -0
- gllm_inference/em_invoker/schema/voyage.pyi +15 -0
- gllm_inference/em_invoker/twelevelabs_em_invoker.pyi +101 -0
- gllm_inference/em_invoker/voyage_em_invoker.pyi +104 -0
- gllm_inference/exceptions/__init__.pyi +4 -0
- gllm_inference/exceptions/error_parser.pyi +41 -0
- gllm_inference/exceptions/exceptions.pyi +132 -0
- gllm_inference/exceptions/provider_error_map.pyi +24 -0
- gllm_inference/lm_invoker/__init__.pyi +14 -0
- gllm_inference/lm_invoker/anthropic_lm_invoker.pyi +334 -0
- gllm_inference/lm_invoker/azure_openai_lm_invoker.pyi +254 -0
- gllm_inference/lm_invoker/batch/__init__.pyi +3 -0
- gllm_inference/lm_invoker/batch/batch_operations.pyi +127 -0
- gllm_inference/lm_invoker/bedrock_lm_invoker.pyi +226 -0
- gllm_inference/lm_invoker/datasaur_lm_invoker.pyi +157 -0
- gllm_inference/lm_invoker/google_lm_invoker.pyi +336 -0
- gllm_inference/lm_invoker/langchain_lm_invoker.pyi +251 -0
- gllm_inference/lm_invoker/litellm_lm_invoker.pyi +244 -0
- gllm_inference/lm_invoker/lm_invoker.pyi +164 -0
- gllm_inference/lm_invoker/openai_chat_completions_lm_invoker.pyi +272 -0
- gllm_inference/lm_invoker/openai_compatible_lm_invoker.pyi +52 -0
- gllm_inference/lm_invoker/openai_lm_invoker.pyi +433 -0
- gllm_inference/lm_invoker/portkey_lm_invoker.pyi +260 -0
- gllm_inference/lm_invoker/schema/__init__.pyi +0 -0
- gllm_inference/lm_invoker/schema/anthropic.pyi +56 -0
- gllm_inference/lm_invoker/schema/bedrock.pyi +53 -0
- gllm_inference/lm_invoker/schema/datasaur.pyi +14 -0
- gllm_inference/lm_invoker/schema/google.pyi +24 -0
- gllm_inference/lm_invoker/schema/langchain.pyi +23 -0
- gllm_inference/lm_invoker/schema/openai.pyi +106 -0
- gllm_inference/lm_invoker/schema/openai_chat_completions.pyi +62 -0
- gllm_inference/lm_invoker/schema/portkey.pyi +31 -0
- gllm_inference/lm_invoker/schema/xai.pyi +31 -0
- gllm_inference/lm_invoker/xai_lm_invoker.pyi +289 -0
- gllm_inference/model/__init__.pyi +12 -0
- gllm_inference/model/em/__init__.pyi +0 -0
- gllm_inference/model/em/cohere_em.pyi +17 -0
- gllm_inference/model/em/google_em.pyi +16 -0
- gllm_inference/model/em/jina_em.pyi +22 -0
- gllm_inference/model/em/openai_em.pyi +15 -0
- gllm_inference/model/em/twelvelabs_em.pyi +13 -0
- gllm_inference/model/em/voyage_em.pyi +20 -0
- gllm_inference/model/lm/__init__.pyi +0 -0
- gllm_inference/model/lm/anthropic_lm.pyi +22 -0
- gllm_inference/model/lm/google_lm.pyi +18 -0
- gllm_inference/model/lm/openai_lm.pyi +27 -0
- gllm_inference/model/lm/xai_lm.pyi +19 -0
- gllm_inference/output_parser/__init__.pyi +3 -0
- gllm_inference/output_parser/json_output_parser.pyi +60 -0
- gllm_inference/output_parser/output_parser.pyi +27 -0
- gllm_inference/prompt_builder/__init__.pyi +3 -0
- gllm_inference/prompt_builder/format_strategy/__init__.pyi +4 -0
- gllm_inference/prompt_builder/format_strategy/format_strategy.pyi +55 -0
- gllm_inference/prompt_builder/format_strategy/jinja_format_strategy.pyi +45 -0
- gllm_inference/prompt_builder/format_strategy/string_format_strategy.pyi +20 -0
- gllm_inference/prompt_builder/prompt_builder.pyi +69 -0
- gllm_inference/prompt_formatter/__init__.pyi +7 -0
- gllm_inference/prompt_formatter/agnostic_prompt_formatter.pyi +49 -0
- gllm_inference/prompt_formatter/huggingface_prompt_formatter.pyi +55 -0
- gllm_inference/prompt_formatter/llama_prompt_formatter.pyi +59 -0
- gllm_inference/prompt_formatter/mistral_prompt_formatter.pyi +53 -0
- gllm_inference/prompt_formatter/openai_prompt_formatter.pyi +35 -0
- gllm_inference/prompt_formatter/prompt_formatter.pyi +30 -0
- gllm_inference/realtime_chat/__init__.pyi +3 -0
- gllm_inference/realtime_chat/google_realtime_chat.pyi +205 -0
- gllm_inference/realtime_chat/input_streamer/__init__.pyi +4 -0
- gllm_inference/realtime_chat/input_streamer/input_streamer.pyi +36 -0
- gllm_inference/realtime_chat/input_streamer/keyboard_input_streamer.pyi +27 -0
- gllm_inference/realtime_chat/input_streamer/linux_mic_input_streamer.pyi +36 -0
- gllm_inference/realtime_chat/output_streamer/__init__.pyi +4 -0
- gllm_inference/realtime_chat/output_streamer/console_output_streamer.pyi +21 -0
- gllm_inference/realtime_chat/output_streamer/linux_speaker_output_streamer.pyi +42 -0
- gllm_inference/realtime_chat/output_streamer/output_streamer.pyi +33 -0
- gllm_inference/realtime_chat/realtime_chat.pyi +28 -0
- gllm_inference/request_processor/__init__.pyi +4 -0
- gllm_inference/request_processor/lm_request_processor.pyi +101 -0
- gllm_inference/request_processor/uses_lm_mixin.pyi +130 -0
- gllm_inference/schema/__init__.pyi +18 -0
- gllm_inference/schema/activity.pyi +64 -0
- gllm_inference/schema/attachment.pyi +88 -0
- gllm_inference/schema/code_exec_result.pyi +14 -0
- gllm_inference/schema/config.pyi +15 -0
- gllm_inference/schema/enums.pyi +69 -0
- gllm_inference/schema/events.pyi +105 -0
- gllm_inference/schema/lm_input.pyi +4 -0
- gllm_inference/schema/lm_output.pyi +44 -0
- gllm_inference/schema/mcp.pyi +31 -0
- gllm_inference/schema/message.pyi +52 -0
- gllm_inference/schema/model_id.pyi +176 -0
- gllm_inference/schema/reasoning.pyi +15 -0
- gllm_inference/schema/token_usage.pyi +75 -0
- gllm_inference/schema/tool_call.pyi +14 -0
- gllm_inference/schema/tool_result.pyi +11 -0
- gllm_inference/schema/type_alias.pyi +11 -0
- gllm_inference/utils/__init__.pyi +5 -0
- gllm_inference/utils/io_utils.pyi +26 -0
- gllm_inference/utils/langchain.pyi +30 -0
- gllm_inference/utils/validation.pyi +12 -0
- gllm_inference.build/.gitignore +1 -0
- gllm_inference.cpython-313-darwin.so +0 -0
- gllm_inference.pyi +157 -0
- gllm_inference_binary-0.5.51b3.dist-info/METADATA +138 -0
- gllm_inference_binary-0.5.51b3.dist-info/RECORD +137 -0
- gllm_inference_binary-0.5.51b3.dist-info/WHEEL +5 -0
- gllm_inference_binary-0.5.51b3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,272 @@
|
|
|
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 INVOKER_PROPAGATED_MAX_RETRIES as INVOKER_PROPAGATED_MAX_RETRIES, OPENAI_DEFAULT_URL as OPENAI_DEFAULT_URL
|
|
6
|
+
from gllm_inference.lm_invoker.lm_invoker import BaseLMInvoker as BaseLMInvoker
|
|
7
|
+
from gllm_inference.lm_invoker.schema.openai_chat_completions import InputType as InputType, Key as Key, ReasoningEffort as ReasoningEffort
|
|
8
|
+
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
|
|
9
|
+
from gllm_inference.utils 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 OpenAIChatCompletionsLMInvoker(BaseLMInvoker):
|
|
16
|
+
'''A language model invoker to interact with OpenAI language models using the Chat Completions API.
|
|
17
|
+
|
|
18
|
+
This class provides support for OpenAI\'s Chat Completions API schema. Use this class only when you have
|
|
19
|
+
a specific reason to use the Chat Completions API over the Responses API, as OpenAI recommends using
|
|
20
|
+
the Responses API whenever possible. The Responses API schema is supported through the `OpenAILMInvoker` class.
|
|
21
|
+
|
|
22
|
+
Attributes:
|
|
23
|
+
model_id (str): The model ID of the language model.
|
|
24
|
+
model_provider (str): The provider of the language model.
|
|
25
|
+
model_name (str): The name of the language model.
|
|
26
|
+
client_kwargs (dict[str, Any]): The keyword arguments for the OpenAI client.
|
|
27
|
+
default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the model.
|
|
28
|
+
tools (list[Tool]): The list of tools provided to the model to enable tool calling.
|
|
29
|
+
response_schema (ResponseSchema | None): The schema of the response. If provided, the model will output a
|
|
30
|
+
structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema dictionary.
|
|
31
|
+
output_analytics (bool): Whether to output the invocation analytics.
|
|
32
|
+
retry_config (RetryConfig | None): The retry configuration for the language model.
|
|
33
|
+
|
|
34
|
+
Basic usage:
|
|
35
|
+
The `OpenAIChatCompletionsLMInvoker` can be used as follows:
|
|
36
|
+
```python
|
|
37
|
+
lm_invoker = OpenAIChatCompletionsLMInvoker(model_name="gpt-5-nano")
|
|
38
|
+
result = await lm_invoker.invoke("Hi there!")
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
OpenAI compatible endpoints:
|
|
42
|
+
The `OpenAIChatCompletionsLMInvoker` can also be used to interact with endpoints that are compatible with
|
|
43
|
+
OpenAI\'s Chat Completions API schema. This includes but are not limited to:
|
|
44
|
+
1. DeepInfra (https://deepinfra.com/)
|
|
45
|
+
2. DeepSeek (https://deepseek.com/)
|
|
46
|
+
3. Groq (https://groq.com/)
|
|
47
|
+
4. OpenRouter (https://openrouter.ai/)
|
|
48
|
+
5. Text Generation Inference (https://github.com/huggingface/text-generation-inference)
|
|
49
|
+
6. Together.ai (https://together.ai/)
|
|
50
|
+
7. vLLM (https://vllm.ai/)
|
|
51
|
+
Please note that the supported features and capabilities may vary between different endpoints and
|
|
52
|
+
language models. Using features that are not supported by the endpoint will result in an error.
|
|
53
|
+
|
|
54
|
+
This customization can be done by setting the `base_url` parameter to the base URL of the endpoint:
|
|
55
|
+
```python
|
|
56
|
+
lm_invoker = OpenAIChatCompletionsLMInvoker(
|
|
57
|
+
model_name="llama3-8b-8192",
|
|
58
|
+
api_key="<your-api-key>",
|
|
59
|
+
base_url="https://api.groq.com/openai/v1",
|
|
60
|
+
)
|
|
61
|
+
result = await lm_invoker.invoke("Hi there!")
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Input types:
|
|
65
|
+
The `OpenAIChatCompletionsLMInvoker` supports the following input types: text, audio, document, and image.
|
|
66
|
+
Non-text inputs can be passed as an `Attachment` object with the `user` role.
|
|
67
|
+
|
|
68
|
+
Usage example:
|
|
69
|
+
```python
|
|
70
|
+
text = "What animal is in this image?"
|
|
71
|
+
image = Attachment.from_path("path/to/local/image.png")
|
|
72
|
+
result = await lm_invoker.invoke([text, image])
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Tool calling:
|
|
76
|
+
Tool calling is a feature that allows the language model to call tools to perform tasks.
|
|
77
|
+
Tools can be passed to the via the `tools` parameter as a list of `Tool` objects.
|
|
78
|
+
When tools are provided and the model decides to call a tool, the tool calls are stored in the
|
|
79
|
+
`tool_calls` attribute in the output.
|
|
80
|
+
|
|
81
|
+
Usage example:
|
|
82
|
+
```python
|
|
83
|
+
lm_invoker = OpenAIChatCompletionsLMInvoker(..., tools=[tool_1, tool_2])
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Output example:
|
|
87
|
+
```python
|
|
88
|
+
LMOutput(
|
|
89
|
+
response="Let me call the tools...",
|
|
90
|
+
tool_calls=[
|
|
91
|
+
ToolCall(id="123", name="tool_1", args={"key": "value"}),
|
|
92
|
+
ToolCall(id="456", name="tool_2", args={"key": "value"}),
|
|
93
|
+
]
|
|
94
|
+
)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Structured output:
|
|
98
|
+
Structured output is a feature that allows the language model to output a structured response.
|
|
99
|
+
This feature can be enabled by providing a schema to the `response_schema` parameter.
|
|
100
|
+
|
|
101
|
+
The schema must be either a JSON schema dictionary or a Pydantic BaseModel class.
|
|
102
|
+
If JSON schema is used, it must be compatible with Pydantic\'s JSON schema, especially for complex schemas.
|
|
103
|
+
For this reason, it is recommended to create the JSON schema using Pydantic\'s `model_json_schema` method.
|
|
104
|
+
|
|
105
|
+
The language model also doesn\'t need to stream anything when structured output is enabled. Thus, standard
|
|
106
|
+
invocation will be performed regardless of whether the `event_emitter` parameter is provided or not.
|
|
107
|
+
|
|
108
|
+
When enabled, the structured output is stored in the `structured_output` attribute in the output.
|
|
109
|
+
1. If the schema is a JSON schema dictionary, the structured output is a dictionary.
|
|
110
|
+
2. If the schema is a Pydantic BaseModel class, the structured output is a Pydantic model.
|
|
111
|
+
|
|
112
|
+
# Example 1: Using a JSON schema dictionary
|
|
113
|
+
Usage example:
|
|
114
|
+
```python
|
|
115
|
+
schema = {
|
|
116
|
+
"title": "Animal",
|
|
117
|
+
"description": "A description of an animal.",
|
|
118
|
+
"properties": {
|
|
119
|
+
"color": {"title": "Color", "type": "string"},
|
|
120
|
+
"name": {"title": "Name", "type": "string"},
|
|
121
|
+
},
|
|
122
|
+
"required": ["name", "color"],
|
|
123
|
+
"type": "object",
|
|
124
|
+
}
|
|
125
|
+
lm_invoker = OpenAIChatCompletionsLMInvoker(..., response_schema=schema)
|
|
126
|
+
```
|
|
127
|
+
Output example:
|
|
128
|
+
```python
|
|
129
|
+
LMOutput(structured_output={"name": "Golden retriever", "color": "Golden"})
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
# Example 2: Using a Pydantic BaseModel class
|
|
133
|
+
Usage example:
|
|
134
|
+
```python
|
|
135
|
+
class Animal(BaseModel):
|
|
136
|
+
name: str
|
|
137
|
+
color: str
|
|
138
|
+
|
|
139
|
+
lm_invoker = OpenAIChatCompletionsLMInvoker(..., response_schema=Animal)
|
|
140
|
+
```
|
|
141
|
+
Output example:
|
|
142
|
+
```python
|
|
143
|
+
LMOutput(structured_output=Animal(name="Golden retriever", color="Golden"))
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Analytics tracking:
|
|
147
|
+
Analytics tracking is a feature that allows the module to output additional information about the invocation.
|
|
148
|
+
This feature can be enabled by setting the `output_analytics` parameter to `True`.
|
|
149
|
+
When enabled, the following attributes will be stored in the output:
|
|
150
|
+
1. `token_usage`: The token usage.
|
|
151
|
+
2. `duration`: The duration in seconds.
|
|
152
|
+
3. `finish_details`: The details about how the generation finished.
|
|
153
|
+
|
|
154
|
+
Output example:
|
|
155
|
+
```python
|
|
156
|
+
LMOutput(
|
|
157
|
+
response="Golden retriever is a good dog breed.",
|
|
158
|
+
token_usage=TokenUsage(input_tokens=100, output_tokens=50),
|
|
159
|
+
duration=0.729,
|
|
160
|
+
finish_details={"finish_reason": "stop"},
|
|
161
|
+
)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
When streaming is enabled, token usage is not supported. Therefore, the `token_usage` attribute will be `None`
|
|
165
|
+
regardless of the value of the `output_analytics` parameter.
|
|
166
|
+
|
|
167
|
+
Retry and timeout:
|
|
168
|
+
The `OpenAIChatCompletionsLMInvoker` supports retry and timeout configuration.
|
|
169
|
+
By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
|
|
170
|
+
They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
|
|
171
|
+
|
|
172
|
+
Retry config examples:
|
|
173
|
+
```python
|
|
174
|
+
retry_config = RetryConfig(max_retries=0, timeout=None) # No retry, no timeout
|
|
175
|
+
retry_config = RetryConfig(max_retries=0, timeout=10.0) # No retry, 10.0 seconds timeout
|
|
176
|
+
retry_config = RetryConfig(max_retries=5, timeout=None) # 5 max retries, no timeout
|
|
177
|
+
retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Usage example:
|
|
181
|
+
```python
|
|
182
|
+
lm_invoker = OpenAIChatCompletionsLMInvoker(..., retry_config=retry_config)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Reasoning:
|
|
186
|
+
Some language models support advanced reasoning capabilities. When using such reasoning-capable models,
|
|
187
|
+
you can configure how much reasoning the model should perform before generating a final response by setting
|
|
188
|
+
reasoning-related parameters.
|
|
189
|
+
|
|
190
|
+
The reasoning effort of reasoning models can be set via the `reasoning_effort` parameter. This parameter
|
|
191
|
+
will guide the models on how many reasoning tokens it should generate before creating a response to the prompt.
|
|
192
|
+
The reasoning effort is only supported by some language models.
|
|
193
|
+
Available options include:
|
|
194
|
+
1. "low": Favors speed and economical token usage.
|
|
195
|
+
2. "medium": Favors a balance between speed and reasoning accuracy.
|
|
196
|
+
3. "high": Favors more complete reasoning at the cost of more tokens generated and slower responses.
|
|
197
|
+
This may differ between models. When not set, the reasoning effort will be equivalent to None by default.
|
|
198
|
+
|
|
199
|
+
When using reasoning models, some providers might output the reasoning summary. These will be stored in the
|
|
200
|
+
`reasoning` attribute in the output.
|
|
201
|
+
|
|
202
|
+
Output example:
|
|
203
|
+
```python
|
|
204
|
+
LMOutput(
|
|
205
|
+
response="Golden retriever is a good dog breed.",
|
|
206
|
+
reasoning=[Reasoning(id="", reasoning="Let me think about it...")],
|
|
207
|
+
)
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Streaming output example:
|
|
211
|
+
```python
|
|
212
|
+
{"type": "thinking_start", "value": ""}\', ...}
|
|
213
|
+
{"type": "thinking", "value": "Let me think "}\', ...}
|
|
214
|
+
{"type": "thinking", "value": "about it..."}\', ...}
|
|
215
|
+
{"type": "thinking_end", "value": ""}\', ...}
|
|
216
|
+
{"type": "response", "value": "Golden retriever ", ...}
|
|
217
|
+
{"type": "response", "value": "is a good dog breed.", ...}
|
|
218
|
+
```
|
|
219
|
+
Note: By default, the thinking token will be streamed with the legacy `EventType.DATA` event type.
|
|
220
|
+
To use the new simplified streamed event format, set the `simplify_events` parameter to `True` during
|
|
221
|
+
LM invoker initialization. The legacy event format support will be removed in v0.6.
|
|
222
|
+
|
|
223
|
+
Setting reasoning-related parameters for non-reasoning models will raise an error.
|
|
224
|
+
|
|
225
|
+
Output types:
|
|
226
|
+
The output of the `OpenAIChatCompletionsLMInvoker` can either be:
|
|
227
|
+
1. `str`: A text response.
|
|
228
|
+
2. `LMOutput`: A Pydantic model that may contain the following attributes:
|
|
229
|
+
2.1. response (str)
|
|
230
|
+
2.2. tool_calls (list[ToolCall])
|
|
231
|
+
2.3. structured_output (dict[str, Any] | BaseModel | None)
|
|
232
|
+
2.4. token_usage (TokenUsage | None)
|
|
233
|
+
2.5. duration (float | None)
|
|
234
|
+
2.6. finish_details (dict[str, Any])
|
|
235
|
+
2.7. reasoning (list[Reasoning])
|
|
236
|
+
'''
|
|
237
|
+
client_kwargs: Incomplete
|
|
238
|
+
def __init__(self, model_name: str, api_key: str | None = None, base_url: str = ..., 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, simplify_events: bool = False) -> None:
|
|
239
|
+
'''Initializes a new instance of the OpenAIChatCompletionsLMInvoker class.
|
|
240
|
+
|
|
241
|
+
Args:
|
|
242
|
+
model_name (str): The name of the OpenAI model.
|
|
243
|
+
api_key (str | None, optional): The API key for authenticating with OpenAI. Defaults to None, in which
|
|
244
|
+
case the `OPENAI_API_KEY` environment variable will be used. If the endpoint does not require an
|
|
245
|
+
API key, a dummy value can be passed (e.g. "<empty>").
|
|
246
|
+
base_url (str, optional): The base URL of a custom endpoint that is compatible with OpenAI\'s
|
|
247
|
+
Chat Completions API schema. Defaults to OpenAI\'s default URL.
|
|
248
|
+
model_kwargs (dict[str, Any] | None, optional): Additional model parameters. Defaults to None.
|
|
249
|
+
default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
|
|
250
|
+
Defaults to None.
|
|
251
|
+
tools (list[Tool | LangChainTool] | None, optional): Tools provided to the model to enable tool calling.
|
|
252
|
+
Defaults to None.
|
|
253
|
+
response_schema (ResponseSchema | None, optional): The schema of the response. If provided, the model will
|
|
254
|
+
output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema
|
|
255
|
+
dictionary. Defaults to None.
|
|
256
|
+
output_analytics (bool, optional): Whether to output the invocation analytics. Defaults to False.
|
|
257
|
+
retry_config (RetryConfig | None, optional): The retry configuration for the language model.
|
|
258
|
+
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
259
|
+
reasoning_effort (str | None, optional): The reasoning effort for the language model. Defaults to None.
|
|
260
|
+
simplify_events (bool, optional): Temporary parameter to control the streamed events format.
|
|
261
|
+
When True, uses the simplified events format. When False, uses the legacy events format for
|
|
262
|
+
backward compatibility. Will be removed in v0.6. Defaults to False.
|
|
263
|
+
'''
|
|
264
|
+
def set_response_schema(self, response_schema: ResponseSchema | None) -> None:
|
|
265
|
+
"""Sets the response schema for the OpenAI language model.
|
|
266
|
+
|
|
267
|
+
This method sets the response schema for the OpenAI language model.
|
|
268
|
+
Any existing response schema will be replaced.
|
|
269
|
+
|
|
270
|
+
Args:
|
|
271
|
+
response_schema (ResponseSchema | None): The response schema to be used.
|
|
272
|
+
"""
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from gllm_core.schema.tool import Tool as Tool
|
|
2
|
+
from gllm_core.utils import RetryConfig as RetryConfig
|
|
3
|
+
from gllm_inference.lm_invoker.openai_chat_completions_lm_invoker import OpenAIChatCompletionsLMInvoker as OpenAIChatCompletionsLMInvoker
|
|
4
|
+
from gllm_inference.lm_invoker.schema.openai_chat_completions import ReasoningEffort as ReasoningEffort
|
|
5
|
+
from gllm_inference.schema import ResponseSchema as ResponseSchema
|
|
6
|
+
from langchain_core.tools import Tool as LangChainTool
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
DEPRECATION_MESSAGE: str
|
|
10
|
+
|
|
11
|
+
class OpenAICompatibleLMInvoker(OpenAIChatCompletionsLMInvoker):
|
|
12
|
+
"""A language model invoker to interact with endpoints compatible with OpenAI's chat completion API contract.
|
|
13
|
+
|
|
14
|
+
Attributes:
|
|
15
|
+
model_id (str): The model ID of the language model.
|
|
16
|
+
model_provider (str): The provider of the language model.
|
|
17
|
+
model_name (str): The name of the language model.
|
|
18
|
+
client_kwargs (dict[str, Any]): The keyword arguments for the OpenAI client.
|
|
19
|
+
default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the model.
|
|
20
|
+
tools (list[Tool]): The list of tools provided to the model to enable tool calling.
|
|
21
|
+
response_schema (ResponseSchema | None): The schema of the response. If provided, the model will output a
|
|
22
|
+
structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema dictionary.
|
|
23
|
+
output_analytics (bool): Whether to output the invocation analytics.
|
|
24
|
+
retry_config (RetryConfig | None): The retry configuration for the language model.
|
|
25
|
+
|
|
26
|
+
This class is deprecated and will be removed in v0.6. Please use the `OpenAIChatCompletionsLMInvoker` class instead.
|
|
27
|
+
"""
|
|
28
|
+
def __init__(self, model_name: str, base_url: str, api_key: str | None = None, model_kwargs: dict[str, Any] | None = None, default_hyperparameters: dict[str, Any] | None = None, 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, simplify_events: bool = False) -> None:
|
|
29
|
+
'''Initializes a new instance of the OpenAICompatibleLMInvoker class.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
model_name (str): The name of the language model hosted on the OpenAI compatible endpoint.
|
|
33
|
+
base_url (str): The base URL for the OpenAI compatible endpoint.
|
|
34
|
+
api_key (str | None, optional): The API key for authenticating with the OpenAI compatible endpoint.
|
|
35
|
+
Defaults to None, in which case the `OPENAI_API_KEY` environment variable will be used.
|
|
36
|
+
If the endpoint does not require an API key, a dummy value can be passed (e.g. "<empty>").
|
|
37
|
+
model_kwargs (dict[str, Any] | None, optional): Additional model parameters. Defaults to None.
|
|
38
|
+
default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
|
|
39
|
+
Defaults to None.
|
|
40
|
+
tools (list[Tool | LangChainTool] | None, optional): Tools provided to the model to enable tool calling.
|
|
41
|
+
Defaults to None.
|
|
42
|
+
response_schema (ResponseSchema | None, optional): The schema of the response. If provided, the model will
|
|
43
|
+
output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema
|
|
44
|
+
dictionary. Defaults to None.
|
|
45
|
+
output_analytics (bool, optional): Whether to output the invocation analytics. Defaults to False.
|
|
46
|
+
retry_config (RetryConfig | None, optional): The retry configuration for the language model.
|
|
47
|
+
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
48
|
+
reasoning_effort (str | None, optional): The reasoning effort for the language model. Defaults to None.
|
|
49
|
+
simplify_events (bool, optional): Temporary parameter to control the streamed events format.
|
|
50
|
+
When True, uses the simplified events format. When False, uses the legacy events format for
|
|
51
|
+
backward compatibility. Will be removed in v0.6. Defaults to False.
|
|
52
|
+
'''
|