gllm-inference-binary 0.5.65__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.
- 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 +222 -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 +12 -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 +127 -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 +15 -0
- gllm_inference/lm_invoker/anthropic_lm_invoker.pyi +320 -0
- gllm_inference/lm_invoker/azure_openai_lm_invoker.pyi +237 -0
- gllm_inference/lm_invoker/batch/__init__.pyi +3 -0
- gllm_inference/lm_invoker/batch/batch_operations.pyi +128 -0
- gllm_inference/lm_invoker/bedrock_lm_invoker.pyi +212 -0
- gllm_inference/lm_invoker/datasaur_lm_invoker.pyi +157 -0
- gllm_inference/lm_invoker/google_lm_invoker.pyi +421 -0
- gllm_inference/lm_invoker/langchain_lm_invoker.pyi +239 -0
- gllm_inference/lm_invoker/litellm_lm_invoker.pyi +224 -0
- gllm_inference/lm_invoker/lm_invoker.pyi +183 -0
- gllm_inference/lm_invoker/openai_chat_completions_lm_invoker.pyi +252 -0
- gllm_inference/lm_invoker/openai_compatible_lm_invoker.pyi +52 -0
- gllm_inference/lm_invoker/openai_lm_invoker.pyi +437 -0
- gllm_inference/lm_invoker/portkey_lm_invoker.pyi +296 -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 +36 -0
- gllm_inference/lm_invoker/schema/langchain.pyi +23 -0
- gllm_inference/lm_invoker/schema/openai.pyi +109 -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/sea_lion_lm_invoker.pyi +48 -0
- gllm_inference/lm_invoker/xai_lm_invoker.pyi +252 -0
- gllm_inference/model/__init__.pyi +13 -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/sea_lion_lm.pyi +16 -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 +73 -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 +19 -0
- gllm_inference/schema/activity.pyi +64 -0
- gllm_inference/schema/attachment.pyi +102 -0
- gllm_inference/schema/code_exec_result.pyi +14 -0
- gllm_inference/schema/config.pyi +15 -0
- gllm_inference/schema/enums.pyi +82 -0
- gllm_inference/schema/events.pyi +105 -0
- gllm_inference/schema/formatter.pyi +31 -0
- gllm_inference/schema/lm_input.pyi +4 -0
- gllm_inference/schema/lm_output.pyi +266 -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 +15 -0
- gllm_inference.build/.gitignore +1 -0
- gllm_inference.cpython-313-darwin.so +0 -0
- gllm_inference.pyi +156 -0
- gllm_inference_binary-0.5.65.dist-info/METADATA +138 -0
- gllm_inference_binary-0.5.65.dist-info/RECORD +140 -0
- gllm_inference_binary-0.5.65.dist-info/WHEEL +5 -0
- gllm_inference_binary-0.5.65.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,296 @@
|
|
|
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 SECONDS_TO_MILLISECONDS as SECONDS_TO_MILLISECONDS
|
|
6
|
+
from gllm_inference.lm_invoker.openai_chat_completions_lm_invoker import OpenAIChatCompletionsLMInvoker as OpenAIChatCompletionsLMInvoker
|
|
7
|
+
from gllm_inference.lm_invoker.schema.portkey import InputType as InputType, Key as Key
|
|
8
|
+
from gllm_inference.schema import AttachmentType as AttachmentType, LMOutput as LMOutput, ModelId as ModelId, ModelProvider as ModelProvider, ResponseSchema as ResponseSchema
|
|
9
|
+
from langchain_core.tools import Tool as LangChainTool
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
MIN_THINKING_BUDGET: int
|
|
13
|
+
SUPPORTED_ATTACHMENTS: Incomplete
|
|
14
|
+
VALID_AUTH_METHODS: str
|
|
15
|
+
logger: Incomplete
|
|
16
|
+
|
|
17
|
+
class PortkeyLMInvoker(OpenAIChatCompletionsLMInvoker):
|
|
18
|
+
'''A language model invoker to interact with Portkey\'s Universal API.
|
|
19
|
+
|
|
20
|
+
This class provides support for Portkey’s Universal AI Gateway, which enables unified access to
|
|
21
|
+
multiple providers (e.g., OpenAI, Anthropic, Google, Cohere, Bedrock) via a single API key.
|
|
22
|
+
The `PortkeyLMInvoker` is compatible with all Portkey model routing configurations, including
|
|
23
|
+
model catalog entries, direct providers, and pre-defined configs.
|
|
24
|
+
|
|
25
|
+
Attributes:
|
|
26
|
+
model_id (str): The model ID of the language model.
|
|
27
|
+
model_provider (str): The provider of the language model.
|
|
28
|
+
model_name (str): The catalog name of the language model.
|
|
29
|
+
client_kwargs (dict[str, Any]): The keyword arguments for the Portkey client.
|
|
30
|
+
default_hyperparameters (dict[str, Any]): Default hyperparameters for invoking the model.
|
|
31
|
+
tools (list[Tool]): The list of tools provided to the model to enable tool calling.
|
|
32
|
+
response_schema (ResponseSchema | None): The schema of the response. If provided, the model will output a
|
|
33
|
+
structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema dictionary.
|
|
34
|
+
output_analytics (bool): Whether to output the invocation analytics.
|
|
35
|
+
retry_config (RetryConfig): The retry configuration for the language model.
|
|
36
|
+
thinking (bool): Whether to enable thinking mode for supported models.
|
|
37
|
+
thinking_budget (int): The maximum reasoning token budget for thinking mode.
|
|
38
|
+
|
|
39
|
+
Basic usage:
|
|
40
|
+
The `PortkeyLMInvoker` supports multiple authentication methods with strict precedence order.
|
|
41
|
+
Authentication methods are mutually exclusive and cannot be combined.
|
|
42
|
+
|
|
43
|
+
**Authentication Precedence (Highest to Lowest):**
|
|
44
|
+
1. **Config ID Authentication (Highest precedence)**
|
|
45
|
+
Use a pre-configured routing setup from Portkey’s dashboard.
|
|
46
|
+
```python
|
|
47
|
+
lm_invoker = PortkeyLMInvoker(
|
|
48
|
+
portkey_api_key="<your-portkey-api-key>",
|
|
49
|
+
config="pc-openai-4f6905",
|
|
50
|
+
)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
2. **Model Catalog Authentication**
|
|
54
|
+
Provider name must match the provider name set in the model catalog.
|
|
55
|
+
More details to set up the model catalog can be found in https://portkey.ai/docs/product/model-catalog#model-catalog.
|
|
56
|
+
There are two ways to specify the model name:
|
|
57
|
+
|
|
58
|
+
2.1. Using Combined Model Name Format
|
|
59
|
+
Specify the `model_name` in \'@provider-name/model-name\' format.
|
|
60
|
+
```python
|
|
61
|
+
lm_invoker = PortkeyLMInvoker(
|
|
62
|
+
portkey_api_key="<your-portkey-api-key>",
|
|
63
|
+
model_name="@openai-custom/gpt-4o"
|
|
64
|
+
)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
2.2. Using Separate Provider and Model Name Parameters
|
|
68
|
+
Specify the `provider` in \'@provider-name\' format and `model_name` separately.
|
|
69
|
+
```python
|
|
70
|
+
lm_invoker = PortkeyLMInvoker(
|
|
71
|
+
portkey_api_key="<your-portkey-api-key>",
|
|
72
|
+
provider="@openai-custom",
|
|
73
|
+
model_name="gpt-4o",
|
|
74
|
+
)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
3. **Direct Provider Authentication**
|
|
78
|
+
Use the `provider` in \'provider-name\' format and `model_name` parameters.
|
|
79
|
+
```python
|
|
80
|
+
lm_invoker = PortkeyLMInvoker(
|
|
81
|
+
portkey_api_key="<your-portkey-api-key>",
|
|
82
|
+
provider="openai",
|
|
83
|
+
model_name="gpt-4o",
|
|
84
|
+
api_key="sk-...",
|
|
85
|
+
)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Custom Host:
|
|
89
|
+
You can also use the `custom_host` parameter to override the default host. This is available
|
|
90
|
+
for all authentication methods except for Config ID authentication.
|
|
91
|
+
```python
|
|
92
|
+
lm_invoker = PortkeyLMInvoker(..., custom_host="https://your-custom-endpoint.com")
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Input types:
|
|
96
|
+
The `PortkeyLMInvoker` supports text, image, document, and audio inputs.
|
|
97
|
+
Non-text inputs can be passed as an `Attachment` object with the `user` role.
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
text = "What animal is in this image?"
|
|
101
|
+
image = Attachment.from_path("path/to/image.png")
|
|
102
|
+
result = await lm_invoker.invoke([text, image])
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Text output:
|
|
106
|
+
The `PortkeyLMInvoker` generates text outputs by default.
|
|
107
|
+
Text outputs are stored in the `outputs` attribute of the `LMOutput` object and can be accessed
|
|
108
|
+
via the `texts` (all text outputs) or `text` (first text output) properties.
|
|
109
|
+
|
|
110
|
+
Output example:
|
|
111
|
+
```python
|
|
112
|
+
LMOutput(outputs=[LMOutputItem(type="text", output="Hello, there!")])
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Structured output:
|
|
116
|
+
The `PortkeyLMInvoker` can be configured to generate structured outputs.
|
|
117
|
+
This feature can be enabled by providing a schema to the `response_schema` parameter.
|
|
118
|
+
|
|
119
|
+
Structured outputs are stored in the `outputs` attribute of the `LMOutput` object and can be accessed
|
|
120
|
+
via the `structureds` (all structured outputs) or `structured` (first structured output) properties.
|
|
121
|
+
|
|
122
|
+
The schema must either be one of the following:
|
|
123
|
+
1. A Pydantic BaseModel class
|
|
124
|
+
The structured output will be a Pydantic model.
|
|
125
|
+
2. A JSON schema dictionary
|
|
126
|
+
JSON dictionary schema must be compatible with Pydantic\'s JSON schema, especially for complex schemas.
|
|
127
|
+
Thus, it is recommended to create the JSON schema using Pydantic\'s `model_json_schema` method.
|
|
128
|
+
The structured output will be a dictionary.
|
|
129
|
+
|
|
130
|
+
Usage example:
|
|
131
|
+
```python
|
|
132
|
+
class Animal(BaseModel):
|
|
133
|
+
name: str
|
|
134
|
+
color: str
|
|
135
|
+
|
|
136
|
+
json_schema = Animal.model_json_schema()
|
|
137
|
+
|
|
138
|
+
lm_invoker = PortkeyLMInvoker(..., response_schema=Animal) # Using Pydantic BaseModel class
|
|
139
|
+
lm_invoker = PortkeyLMInvoker(..., response_schema=json_schema) # Using JSON schema dictionary
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Output example:
|
|
143
|
+
```python
|
|
144
|
+
# Using Pydantic BaseModel class outputs a Pydantic model
|
|
145
|
+
LMOutput(outputs=[LMOutputItem(type="structured", output=Animal(name="dog", color="white"))])
|
|
146
|
+
|
|
147
|
+
# Using JSON schema dictionary outputs a dictionary
|
|
148
|
+
LMOutput(outputs=[LMOutputItem(type="structured", output={"name": "dog", "color": "white"})])
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
When structured output is enabled, streaming is disabled.
|
|
152
|
+
|
|
153
|
+
Tool calling:
|
|
154
|
+
The `PortkeyLMInvoker` can be configured to call tools to perform certain tasks.
|
|
155
|
+
This feature can be enabled by providing a list of `Tool` objects to the `tools` parameter.
|
|
156
|
+
|
|
157
|
+
Tool calls outputs are stored in the `outputs` attribute of the `LMOutput` object and
|
|
158
|
+
can be accessed via the `tool_calls` property.
|
|
159
|
+
|
|
160
|
+
Usage example:
|
|
161
|
+
```python
|
|
162
|
+
lm_invoker = PortkeyLMInvoker(..., tools=[tool_1, tool_2])
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Output example:
|
|
166
|
+
```python
|
|
167
|
+
LMOutput(
|
|
168
|
+
outputs=[
|
|
169
|
+
LMOutputItem(type="text", output="I\'m using tools..."),
|
|
170
|
+
LMOutputItem(type="tool_call", output=ToolCall(id="123", name="tool_1", args={"key": "value"})),
|
|
171
|
+
LMOutputItem(type="tool_call", output=ToolCall(id="456", name="tool_2", args={"key": "value"})),
|
|
172
|
+
]
|
|
173
|
+
)
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Thinking:
|
|
177
|
+
The `PortkeyLMInvoker` can be configured to perform step-by-step thinking process before answering.
|
|
178
|
+
This feature can be enabled by setting the `thinking` parameter to `True`.
|
|
179
|
+
|
|
180
|
+
Thinking outputs are stored in the `outputs` attribute of the `LMOutput` object
|
|
181
|
+
and can be accessed via the `thinkings` property.
|
|
182
|
+
|
|
183
|
+
Usage example:
|
|
184
|
+
```python
|
|
185
|
+
lm_invoker = PortkeyLMInvoker(..., thinking=True, thinking_budget=1024)
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Output example:
|
|
189
|
+
```python
|
|
190
|
+
LMOutput(
|
|
191
|
+
outputs=[
|
|
192
|
+
LMOutputItem(type="thinking", output=Reasoning(type="thinking", reasoning="I\'m thinking...", ...)),
|
|
193
|
+
LMOutputItem(type="text", output="Golden retriever is a good dog breed."),
|
|
194
|
+
]
|
|
195
|
+
)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Streaming output example:
|
|
199
|
+
```python
|
|
200
|
+
{"type": "thinking_start", "value": "", ...}
|
|
201
|
+
{"type": "thinking", "value": "I\'m ", ...}
|
|
202
|
+
{"type": "thinking", "value": "thinking...", ...}
|
|
203
|
+
{"type": "thinking_end", "value": "", ...}
|
|
204
|
+
{"type": "response", "value": "Golden retriever ", ...}
|
|
205
|
+
{"type": "response", "value": "is a good dog breed.", ...}
|
|
206
|
+
```
|
|
207
|
+
Note: By default, the thinking token will be streamed with the legacy `EventType.DATA` event type.
|
|
208
|
+
To use the new simplified streamed event format, set the `simplify_events` parameter to `True` during
|
|
209
|
+
LM invoker initialization. The legacy event format support will be removed in v0.6.
|
|
210
|
+
|
|
211
|
+
The amount of tokens allocated for the thinking process can be set via the `thinking_budget` parameter.
|
|
212
|
+
For more information, please refer to the following documentation:
|
|
213
|
+
https://portkey.ai/docs/product/ai-gateway/multimodal-capabilities/thinking-mode.
|
|
214
|
+
|
|
215
|
+
Thinking is only available for certain models depending on capabilities
|
|
216
|
+
|
|
217
|
+
Analytics tracking:
|
|
218
|
+
The `PortkeyLMInvoker` can be configured to output additional information about the invocation.
|
|
219
|
+
This feature can be enabled by setting the `output_analytics` parameter to `True`.
|
|
220
|
+
|
|
221
|
+
When enabled, the following attributes will be stored in the output:
|
|
222
|
+
1. `token_usage`: The token usage.
|
|
223
|
+
2. `duration`: The duration in seconds.
|
|
224
|
+
3. `finish_details`: The details about how the generation finished.
|
|
225
|
+
|
|
226
|
+
Output example:
|
|
227
|
+
```python
|
|
228
|
+
LMOutput(
|
|
229
|
+
outputs=[...],
|
|
230
|
+
token_usage=TokenUsage(input_tokens=100, output_tokens=50),
|
|
231
|
+
duration=0.729,
|
|
232
|
+
finish_details={"stop_reason": "end_turn"},
|
|
233
|
+
)
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
When streaming is enabled, token usage is not supported.
|
|
237
|
+
|
|
238
|
+
Retry and timeout:
|
|
239
|
+
The `PortkeyLMInvoker` supports retry and timeout configuration.
|
|
240
|
+
By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
|
|
241
|
+
They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
|
|
242
|
+
|
|
243
|
+
Retry config examples:
|
|
244
|
+
```python
|
|
245
|
+
retry_config = RetryConfig(max_retries=0, timeout=None) # No retry, no timeout
|
|
246
|
+
retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Usage example:
|
|
250
|
+
```python
|
|
251
|
+
lm_invoker = PortkeyLMInvoker(..., retry_config=retry_config)
|
|
252
|
+
```
|
|
253
|
+
'''
|
|
254
|
+
model_kwargs: Incomplete
|
|
255
|
+
thinking: Incomplete
|
|
256
|
+
thinking_budget: Incomplete
|
|
257
|
+
client_kwargs: Incomplete
|
|
258
|
+
client: Incomplete
|
|
259
|
+
def __init__(self, model_name: str | None = None, portkey_api_key: str | None = None, provider: str | None = None, api_key: str | None = None, config: str | None = None, custom_host: 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, thinking: bool | None = None, thinking_budget: int | None = None, simplify_events: bool = False) -> None:
|
|
260
|
+
"""Initializes a new instance of the PortkeyLMInvoker class.
|
|
261
|
+
|
|
262
|
+
Args:
|
|
263
|
+
model_name (str | None, optional): The name of the model to use. Acceptable formats:
|
|
264
|
+
1. 'model' for direct authentication,
|
|
265
|
+
2. '@provider-slug/model' for model catalog authentication.
|
|
266
|
+
Defaults to None.
|
|
267
|
+
portkey_api_key (str | None, optional): The Portkey API key. Defaults to None, in which
|
|
268
|
+
case the `PORTKEY_API_KEY` environment variable will be used.
|
|
269
|
+
provider (str | None, optional): Provider name or catalog slug. Acceptable formats:
|
|
270
|
+
1. '@provider-slug' for model catalog authentication (no api_key needed),
|
|
271
|
+
2. 'provider' for direct authentication (requires api_key).
|
|
272
|
+
Will be combined with model_name if model name is not in the format '@provider-slug/model'.
|
|
273
|
+
Defaults to None.
|
|
274
|
+
api_key (str | None, optional): Provider's API key for direct authentication.
|
|
275
|
+
Must be used with 'provider' parameter (without '@' prefix). Not needed for catalog providers.
|
|
276
|
+
Defaults to None.
|
|
277
|
+
config (str | None, optional): Portkey config ID for complex routing configurations,
|
|
278
|
+
load balancing, or fallback scenarios. Defaults to None.
|
|
279
|
+
custom_host (str | None, optional): Custom host URL for self-hosted or custom endpoints.
|
|
280
|
+
Can be combined with catalog providers. Defaults to None.
|
|
281
|
+
model_kwargs (dict[str, Any] | None, optional): Additional model parameters and authentication.
|
|
282
|
+
Defaults to None.
|
|
283
|
+
default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for model
|
|
284
|
+
invocation (temperature, max_tokens, etc.). Defaults to None.
|
|
285
|
+
tools (list[Tool | LangChainTool] | None, optional): Tools for enabling tool calling functionality.
|
|
286
|
+
Defaults to None.
|
|
287
|
+
response_schema (ResponseSchema | None, optional): Schema for structured output generation.
|
|
288
|
+
Defaults to None.
|
|
289
|
+
output_analytics (bool, optional): Whether to output detailed invocation analytics including
|
|
290
|
+
token usage and timing. Defaults to False.
|
|
291
|
+
retry_config (RetryConfig | None, optional): Configuration for retry behavior on failures.
|
|
292
|
+
Defaults to None.
|
|
293
|
+
thinking (bool | None, optional): Whether to enable thinking mode. Defaults to None.
|
|
294
|
+
thinking_budget (int | None, optional): Thinking budget in tokens. Defaults to None.
|
|
295
|
+
simplify_events (bool, optional): Whether to use simplified event schemas. Defaults to False.
|
|
296
|
+
"""
|
|
File without changes
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
class Key:
|
|
2
|
+
"""Defines valid keys in Anthropic."""
|
|
3
|
+
BUDGET_TOKENS: str
|
|
4
|
+
CONTENT: str
|
|
5
|
+
DATA: str
|
|
6
|
+
DESCRIPTION: str
|
|
7
|
+
ID: str
|
|
8
|
+
INPUT: str
|
|
9
|
+
INPUT_SCHEMA: str
|
|
10
|
+
MAX_RETRIES: str
|
|
11
|
+
MEDIA_TYPE: str
|
|
12
|
+
MAX_TOKENS: str
|
|
13
|
+
NAME: str
|
|
14
|
+
PARAMETERS: str
|
|
15
|
+
ROLE: str
|
|
16
|
+
SIGNATURE: str
|
|
17
|
+
SOURCE: str
|
|
18
|
+
STATUS: str
|
|
19
|
+
STOP_REASON: str
|
|
20
|
+
SYSTEM: str
|
|
21
|
+
TIMEOUT: str
|
|
22
|
+
THINKING: str
|
|
23
|
+
TOOLS: str
|
|
24
|
+
TOOL_CHOICE: str
|
|
25
|
+
TOOL_USE_ID: str
|
|
26
|
+
TEXT: str
|
|
27
|
+
TYPE: str
|
|
28
|
+
|
|
29
|
+
class InputType:
|
|
30
|
+
"""Defines valid input types in Anthropic."""
|
|
31
|
+
BASE64: str
|
|
32
|
+
ENABLED: str
|
|
33
|
+
REDACTED_THINKING: str
|
|
34
|
+
TEXT: str
|
|
35
|
+
THINKING: str
|
|
36
|
+
TOOL: str
|
|
37
|
+
TOOL_RESULT: str
|
|
38
|
+
TOOL_USE: str
|
|
39
|
+
|
|
40
|
+
class OutputType:
|
|
41
|
+
"""Defines valid output types in Anthropic."""
|
|
42
|
+
CANCELING: str
|
|
43
|
+
CONTENT_BLOCK_DELTA: str
|
|
44
|
+
CONTENT_BLOCK_START: str
|
|
45
|
+
CONTENT_BLOCK_STOP: str
|
|
46
|
+
ENDED: str
|
|
47
|
+
ERRORED: str
|
|
48
|
+
IN_PROGRESS: str
|
|
49
|
+
MESSAGE_STOP: str
|
|
50
|
+
REDACTED_THINKING: str
|
|
51
|
+
SUCCEEDED: str
|
|
52
|
+
TEXT: str
|
|
53
|
+
TEXT_DELTA: str
|
|
54
|
+
THINKING: str
|
|
55
|
+
THINKING_DELTA: str
|
|
56
|
+
TOOL_USE: str
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
class Key:
|
|
2
|
+
"""Defines valid keys in Bedrock."""
|
|
3
|
+
BYTES: str
|
|
4
|
+
CONTENT: str
|
|
5
|
+
CONTENT_BLOCK_INDEX: str
|
|
6
|
+
DELTA: str
|
|
7
|
+
DESCRIPTION: str
|
|
8
|
+
ERROR: str
|
|
9
|
+
CODE: str
|
|
10
|
+
FORMAT: str
|
|
11
|
+
FUNCTION: str
|
|
12
|
+
HTTP_STATUS_CODE: str
|
|
13
|
+
INFERENCE_CONFIG: str
|
|
14
|
+
INPUT: str
|
|
15
|
+
INPUT_SCHEMA: str
|
|
16
|
+
INPUT_TOKENS: str
|
|
17
|
+
JSON: str
|
|
18
|
+
MESSAGE: str
|
|
19
|
+
NAME: str
|
|
20
|
+
RESPONSE: str
|
|
21
|
+
OUTPUT: str
|
|
22
|
+
OUTPUT_TOKENS: str
|
|
23
|
+
PARAMETERS: str
|
|
24
|
+
RESPONSE_METADATA: str
|
|
25
|
+
ROLE: str
|
|
26
|
+
SOURCE: str
|
|
27
|
+
START: str
|
|
28
|
+
STOP_REASON: str
|
|
29
|
+
STREAM: str
|
|
30
|
+
SYSTEM: str
|
|
31
|
+
TEXT: str
|
|
32
|
+
TOOL: str
|
|
33
|
+
TOOLS: str
|
|
34
|
+
TOOL_CHOICE: str
|
|
35
|
+
TOOL_CONFIG: str
|
|
36
|
+
TOOL_SPEC: str
|
|
37
|
+
TOOL_USE_ID: str
|
|
38
|
+
USAGE: str
|
|
39
|
+
|
|
40
|
+
class InputType:
|
|
41
|
+
"""Defines valid input types in Bedrock."""
|
|
42
|
+
TEXT: str
|
|
43
|
+
TOOL_RESULT: str
|
|
44
|
+
TOOL_USE: str
|
|
45
|
+
|
|
46
|
+
class OutputType:
|
|
47
|
+
"""Defines valid output types in Bedrock."""
|
|
48
|
+
CONTENT_BLOCK_START: str
|
|
49
|
+
CONTENT_BLOCK_DELTA: str
|
|
50
|
+
MESSAGE_STOP: str
|
|
51
|
+
METADATA: str
|
|
52
|
+
TEXT: str
|
|
53
|
+
TOOL_USE: str
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
class Key:
|
|
2
|
+
"""Defines valid keys in Google."""
|
|
3
|
+
ARGS: str
|
|
4
|
+
CONTENT: str
|
|
5
|
+
FINISH_MESSAGE: str
|
|
6
|
+
FINISH_REASON: str
|
|
7
|
+
FUNCTION: str
|
|
8
|
+
FUNCTION_CALL: str
|
|
9
|
+
HTTP_OPTIONS: str
|
|
10
|
+
ID: str
|
|
11
|
+
NAME: str
|
|
12
|
+
RETRY_OPTIONS: str
|
|
13
|
+
STATUS: str
|
|
14
|
+
SYSTEM_INSTRUCTION: str
|
|
15
|
+
THINKING_CONFIG: str
|
|
16
|
+
TIMEOUT: str
|
|
17
|
+
TOOLS: str
|
|
18
|
+
RESPONSE_SCHEMA: str
|
|
19
|
+
RESPONSE_MIME_TYPE: str
|
|
20
|
+
VERTEXAI: str
|
|
21
|
+
CUSTOM_REQUEST_IDS: str
|
|
22
|
+
|
|
23
|
+
class InputType:
|
|
24
|
+
"""Defines valid input types in Google."""
|
|
25
|
+
APPLICATION_JSON: str
|
|
26
|
+
MODEL: str
|
|
27
|
+
USER: str
|
|
28
|
+
|
|
29
|
+
class JobState:
|
|
30
|
+
"""Defines valid output types in Google."""
|
|
31
|
+
JOB_STATE_CANCELLED: str
|
|
32
|
+
JOB_STATE_EXPIRED: str
|
|
33
|
+
JOB_STATE_FAILED: str
|
|
34
|
+
JOB_STATE_PENDING: str
|
|
35
|
+
JOB_STATE_RUNNING: str
|
|
36
|
+
JOB_STATE_SUCCEEDED: str
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
class Key:
|
|
2
|
+
"""Defines valid keys in LangChain."""
|
|
3
|
+
ARGS: str
|
|
4
|
+
ERROR_CODE: str
|
|
5
|
+
FINISH_REASON: str
|
|
6
|
+
ID: str
|
|
7
|
+
IMAGE_URL: str
|
|
8
|
+
INPUT_TOKENS: str
|
|
9
|
+
MAX_RETRIES: str
|
|
10
|
+
NAME: str
|
|
11
|
+
OUTPUT_TOKENS: str
|
|
12
|
+
PARSED: str
|
|
13
|
+
RAW: str
|
|
14
|
+
TEXT: str
|
|
15
|
+
TIMEOUT: str
|
|
16
|
+
TYPE: str
|
|
17
|
+
URL: str
|
|
18
|
+
|
|
19
|
+
class InputType:
|
|
20
|
+
"""Defines valid input types in LangChain."""
|
|
21
|
+
IMAGE_URL: str
|
|
22
|
+
TEXT: str
|
|
23
|
+
TOOL_CALL: str
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
from enum import StrEnum
|
|
2
|
+
|
|
3
|
+
class Key:
|
|
4
|
+
"""Defines valid keys in OpenAI."""
|
|
5
|
+
ALLOWED_TOOLS: str
|
|
6
|
+
API_KEY: str
|
|
7
|
+
ARGS: str
|
|
8
|
+
ARGUMENTS: str
|
|
9
|
+
BASE_URL: str
|
|
10
|
+
CALL_ID: str
|
|
11
|
+
CONTAINER: str
|
|
12
|
+
CONTENT: str
|
|
13
|
+
DEFAULT: str
|
|
14
|
+
DEFS: str
|
|
15
|
+
DESCRIPTION: str
|
|
16
|
+
EFFORT: str
|
|
17
|
+
FILE_DATA: str
|
|
18
|
+
FILENAME: str
|
|
19
|
+
FORMAT: str
|
|
20
|
+
ID: str
|
|
21
|
+
IMAGE_GENERATION_CALL: str
|
|
22
|
+
IMAGE_URL: str
|
|
23
|
+
INCLUDE: str
|
|
24
|
+
INCOMPLETE_DETAILS: str
|
|
25
|
+
INSTRUCTIONS: str
|
|
26
|
+
JSON_SCHEMA: str
|
|
27
|
+
MAX_RETRIES: str
|
|
28
|
+
NAME: str
|
|
29
|
+
OUTPUT: str
|
|
30
|
+
PARAMETERS: str
|
|
31
|
+
REASON: str
|
|
32
|
+
REASONING: str
|
|
33
|
+
ROLE: str
|
|
34
|
+
SCHEMA: str
|
|
35
|
+
REQUIRE_APPROVAL: str
|
|
36
|
+
REQUIRED: str
|
|
37
|
+
SERVER_LABEL: str
|
|
38
|
+
SERVER_NAME: str
|
|
39
|
+
SERVER_URL: str
|
|
40
|
+
STATUS: str
|
|
41
|
+
STRICT: str
|
|
42
|
+
SUMMARY: str
|
|
43
|
+
TEXT: str
|
|
44
|
+
TIMEOUT: str
|
|
45
|
+
TITLE: str
|
|
46
|
+
TOOL_NAME: str
|
|
47
|
+
TOOLS: str
|
|
48
|
+
TYPE: str
|
|
49
|
+
|
|
50
|
+
class InputType:
|
|
51
|
+
"""Defines valid input types in OpenAI."""
|
|
52
|
+
AUTO: str
|
|
53
|
+
CODE_INTERPRETER: str
|
|
54
|
+
CODE_INTERPRETER_CALL_OUTPUTS: str
|
|
55
|
+
FUNCTION: str
|
|
56
|
+
FUNCTION_CALL: str
|
|
57
|
+
FUNCTION_CALL_OUTPUT: str
|
|
58
|
+
IMAGE_GENERATION: str
|
|
59
|
+
INPUT_FILE: str
|
|
60
|
+
INPUT_IMAGE: str
|
|
61
|
+
INPUT_TEXT: str
|
|
62
|
+
JSON_SCHEMA: str
|
|
63
|
+
MCP: str
|
|
64
|
+
MCP_CALL: str
|
|
65
|
+
NEVER: str
|
|
66
|
+
NULL: str
|
|
67
|
+
OUTPUT_TEXT: str
|
|
68
|
+
REASONING: str
|
|
69
|
+
SUMMARY_TEXT: str
|
|
70
|
+
WEB_SEARCH_PREVIEW: str
|
|
71
|
+
|
|
72
|
+
class OutputType:
|
|
73
|
+
"""Defines valid output types in OpenAI."""
|
|
74
|
+
CODE_INTERPRETER_CALL: str
|
|
75
|
+
CODE_INTERPRETER_CALL_DELTA: str
|
|
76
|
+
CODE_INTERPRETER_CALL_DONE: str
|
|
77
|
+
CODE_INTERPRETER_CALL_IN_PROGRESS: str
|
|
78
|
+
COMPLETED: str
|
|
79
|
+
CONTAINER_FILE_CITATION: str
|
|
80
|
+
FIND_IN_PAGE: str
|
|
81
|
+
FUNCTION_CALL: str
|
|
82
|
+
IMAGE: str
|
|
83
|
+
IMAGE_GENERATION_CALL: str
|
|
84
|
+
INCOMPLETE: str
|
|
85
|
+
ITEM_DONE: str
|
|
86
|
+
MCP_CALL: str
|
|
87
|
+
MCP_LIST_TOOLS: str
|
|
88
|
+
MESSAGE: str
|
|
89
|
+
OPEN_PAGE: str
|
|
90
|
+
REASONING: str
|
|
91
|
+
REASONING_ADDED: str
|
|
92
|
+
REASONING_DELTA: str
|
|
93
|
+
REASONING_DONE: str
|
|
94
|
+
REFUSAL: str
|
|
95
|
+
SEARCH: str
|
|
96
|
+
TEXT_DELTA: str
|
|
97
|
+
WEB_SEARCH_CALL: str
|
|
98
|
+
|
|
99
|
+
class ReasoningEffort(StrEnum):
|
|
100
|
+
"""Defines the reasoning effort for reasoning models."""
|
|
101
|
+
HIGH = 'high'
|
|
102
|
+
MEDIUM = 'medium'
|
|
103
|
+
LOW = 'low'
|
|
104
|
+
MINIMAL = 'minimal'
|
|
105
|
+
|
|
106
|
+
class ReasoningSummary(StrEnum):
|
|
107
|
+
"""Defines the reasoning summary for reasoning models."""
|
|
108
|
+
AUTO = 'auto'
|
|
109
|
+
DETAILED = 'detailed'
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from enum import StrEnum
|
|
2
|
+
|
|
3
|
+
class Key:
|
|
4
|
+
"""Defines valid keys in OpenAI Chat Completions."""
|
|
5
|
+
API_KEY: str
|
|
6
|
+
ARGUMENTS: str
|
|
7
|
+
BASE_URL: str
|
|
8
|
+
CONTENT: str
|
|
9
|
+
CHOICES: str
|
|
10
|
+
DATA: str
|
|
11
|
+
DEFS: str
|
|
12
|
+
DESCRIPTION: str
|
|
13
|
+
EFFORT: str
|
|
14
|
+
FILE: str
|
|
15
|
+
FILE_DATA: str
|
|
16
|
+
FILENAME: str
|
|
17
|
+
FINISH_REASON: str
|
|
18
|
+
FORMAT: str
|
|
19
|
+
FUNCTION: str
|
|
20
|
+
ID: str
|
|
21
|
+
IMAGE_URL: str
|
|
22
|
+
INPUT_AUDIO: str
|
|
23
|
+
JSON_SCHEMA: str
|
|
24
|
+
MAX_RETRIES: str
|
|
25
|
+
MESSAGE: str
|
|
26
|
+
NAME: str
|
|
27
|
+
PARAMETERS: str
|
|
28
|
+
RESPONSE_FORMAT: str
|
|
29
|
+
ROLE: str
|
|
30
|
+
SCHEMA: str
|
|
31
|
+
STRICT: str
|
|
32
|
+
TEXT: str
|
|
33
|
+
TIMEOUT: str
|
|
34
|
+
TITLE: str
|
|
35
|
+
TOOLS: str
|
|
36
|
+
TOOL_CALLS: str
|
|
37
|
+
TOOL_CALL_ID: str
|
|
38
|
+
TYPE: str
|
|
39
|
+
URL: str
|
|
40
|
+
USAGE: str
|
|
41
|
+
REASONING: str
|
|
42
|
+
REASONING_CONTENT: str
|
|
43
|
+
REASONING_EFFORT: str
|
|
44
|
+
SUMMARY: str
|
|
45
|
+
|
|
46
|
+
class InputType:
|
|
47
|
+
"""Defines valid input types in OpenAI Chat Completions."""
|
|
48
|
+
FILE: str
|
|
49
|
+
FUNCTION: str
|
|
50
|
+
IMAGE_URL: str
|
|
51
|
+
INPUT_AUDIO: str
|
|
52
|
+
JSON_SCHEMA: str
|
|
53
|
+
TEXT: str
|
|
54
|
+
TOOL: str
|
|
55
|
+
REASONING: str
|
|
56
|
+
SUMMARY_TEXT: str
|
|
57
|
+
|
|
58
|
+
class ReasoningEffort(StrEnum):
|
|
59
|
+
"""Defines the reasoning effort for reasoning models."""
|
|
60
|
+
HIGH = 'high'
|
|
61
|
+
MEDIUM = 'medium'
|
|
62
|
+
LOW = 'low'
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
class Key:
|
|
2
|
+
"""Valid keys in Portkey."""
|
|
3
|
+
AUTHORIZATION: str
|
|
4
|
+
BUDGET_TOKENS: str
|
|
5
|
+
CONFIG: str
|
|
6
|
+
CONTENT: str
|
|
7
|
+
CONTENT_BLOCKS: str
|
|
8
|
+
CUSTOM_HOST: str
|
|
9
|
+
DELTA: str
|
|
10
|
+
MAX_RETRIES: str
|
|
11
|
+
MODEL: str
|
|
12
|
+
PROVIDER: str
|
|
13
|
+
PROVIDER_MODEL: str
|
|
14
|
+
REQUEST_TIMEOUT: str
|
|
15
|
+
RESPONSE_FORMAT: str
|
|
16
|
+
STRICT_OPEN_AI_COMPLIANCE: str
|
|
17
|
+
THINKING: str
|
|
18
|
+
TOOLS: str
|
|
19
|
+
TYPE: str
|
|
20
|
+
USAGE: str
|
|
21
|
+
|
|
22
|
+
class InputType:
|
|
23
|
+
"""Valid input types in Portkey."""
|
|
24
|
+
ENABLED: str
|
|
25
|
+
|
|
26
|
+
class AuthConfig:
|
|
27
|
+
"""Authentication configuration keys."""
|
|
28
|
+
CONFIG: str
|
|
29
|
+
MODEL: str
|
|
30
|
+
PROVIDER_AUTH: str
|
|
31
|
+
PROVIDER_CUSTOM_HOST: str
|