gllm-inference-binary 0.5.34__cp312-cp312-manylinux_2_31_x86_64.whl → 0.5.35__cp312-cp312-manylinux_2_31_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.
Potentially problematic release.
This version of gllm-inference-binary might be problematic. Click here for more details.
- gllm_inference/builder/build_em_invoker.pyi +10 -13
- gllm_inference/builder/build_lm_invoker.pyi +30 -17
- gllm_inference/builder/build_lm_request_processor.pyi +2 -7
- gllm_inference/catalog/lm_request_processor_catalog.pyi +2 -2
- gllm_inference/constants.pyi +1 -0
- gllm_inference/em_invoker/openai_compatible_em_invoker.pyi +5 -60
- gllm_inference/em_invoker/openai_em_invoker.pyi +34 -6
- gllm_inference/lm_invoker/__init__.pyi +2 -1
- gllm_inference/lm_invoker/langchain_lm_invoker.pyi +3 -3
- gllm_inference/lm_invoker/litellm_lm_invoker.pyi +1 -1
- gllm_inference/lm_invoker/openai_chat_completions_lm_invoker.pyi +278 -0
- gllm_inference/lm_invoker/openai_compatible_lm_invoker.pyi +9 -226
- gllm_inference/lm_invoker/openai_lm_invoker.pyi +30 -6
- gllm_inference/lm_invoker/schema/{openai_compatible.pyi → openai_chat_completions.pyi} +2 -2
- gllm_inference/schema/model_id.pyi +30 -25
- gllm_inference.cpython-312-x86_64-linux-gnu.so +0 -0
- gllm_inference.pyi +1 -0
- {gllm_inference_binary-0.5.34.dist-info → gllm_inference_binary-0.5.35.dist-info}/METADATA +1 -1
- {gllm_inference_binary-0.5.34.dist-info → gllm_inference_binary-0.5.35.dist-info}/RECORD +21 -20
- {gllm_inference_binary-0.5.34.dist-info → gllm_inference_binary-0.5.35.dist-info}/WHEEL +0 -0
- {gllm_inference_binary-0.5.34.dist-info → gllm_inference_binary-0.5.35.dist-info}/top_level.txt +0 -0
|
@@ -24,11 +24,8 @@ def build_em_invoker(model_id: str | ModelId, credentials: str | dict[str, Any]
|
|
|
24
24
|
'''Build an embedding model invoker based on the provided configurations.
|
|
25
25
|
|
|
26
26
|
Args:
|
|
27
|
-
model_id (str | ModelId): The model id, can either be a ModelId instance or a string in
|
|
28
|
-
|
|
29
|
-
2. For `openai-compatible` provider: `openai-compatible/base-url:model-name`.
|
|
30
|
-
3. For `langchain` provider: `langchain/<package>.<class>:model-name`.
|
|
31
|
-
4. For other providers: `provider/model-name`.
|
|
27
|
+
model_id (str | ModelId): The model id, can either be a ModelId instance or a string in a format defined
|
|
28
|
+
in the following page: https://gdplabs.gitbook.io/sdk/resources/supported-models#embedding-models-ems
|
|
32
29
|
credentials (str | dict[str, Any] | None, optional): The credentials for the language model. Can either be:
|
|
33
30
|
1. An API key.
|
|
34
31
|
2. A path to a credentials JSON file, currently only supported for Google Vertex AI.
|
|
@@ -83,23 +80,23 @@ def build_em_invoker(model_id: str | ModelId, credentials: str | dict[str, Any]
|
|
|
83
80
|
```
|
|
84
81
|
The credentials can also be provided through the `OPENAI_API_KEY` environment variable.
|
|
85
82
|
|
|
86
|
-
# Using
|
|
83
|
+
# Using OpenAI Embeddings API-compatible endpoints (e.g. vLLM)
|
|
87
84
|
```python
|
|
88
85
|
em_invoker = build_em_invoker(
|
|
89
|
-
model_id="
|
|
90
|
-
credentials="
|
|
86
|
+
model_id="openai/https://my-vllm-url:8000/v1:my-model-name",
|
|
87
|
+
credentials="sk-..."
|
|
91
88
|
)
|
|
92
89
|
```
|
|
93
|
-
The credentials can also be provided through the `
|
|
90
|
+
The credentials can also be provided through the `OPENAI_API_KEY` environment variable.
|
|
94
91
|
|
|
95
|
-
# Using OpenAI
|
|
92
|
+
# Using Azure OpenAI
|
|
96
93
|
```python
|
|
97
94
|
em_invoker = build_em_invoker(
|
|
98
|
-
model_id="openai
|
|
99
|
-
credentials="
|
|
95
|
+
model_id="azure-openai/https://my-resource.openai.azure.com/openai/v1:my-deployment",
|
|
96
|
+
credentials="azure-api-key"
|
|
100
97
|
)
|
|
101
98
|
```
|
|
102
|
-
The credentials can also be provided through the `
|
|
99
|
+
The credentials can also be provided through the `AZURE_OPENAI_API_KEY` environment variable.
|
|
103
100
|
|
|
104
101
|
# Using TwelveLabs
|
|
105
102
|
```python
|
|
@@ -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, XAILMInvoker as XAILMInvoker
|
|
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, OpenAIChatCompletionsLMInvoker as OpenAIChatCompletionsLMInvoker, 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
|
|
@@ -25,13 +25,8 @@ def build_lm_invoker(model_id: str | ModelId, credentials: str | dict[str, Any]
|
|
|
25
25
|
'''Build a language model invoker based on the provided configurations.
|
|
26
26
|
|
|
27
27
|
Args:
|
|
28
|
-
model_id (str | ModelId): The model id, can either be a ModelId instance or a string in
|
|
29
|
-
|
|
30
|
-
2. For `openai-compatible` provider: `openai-compatible/base-url:model-name`.
|
|
31
|
-
3. For `langchain` provider: `langchain/<package>.<class>:model-name`.
|
|
32
|
-
4. For `litellm` provider: `litellm/provider/model-name`.
|
|
33
|
-
5. For `datasaur` provider: `datasaur/deployment-id:model-name`.
|
|
34
|
-
6. For other providers: `provider/model-name`.
|
|
28
|
+
model_id (str | ModelId): The model id, can either be a ModelId instance or a string in a format defined
|
|
29
|
+
in the following page: https://gdplabs.gitbook.io/sdk/resources/supported-models#language-models-lms
|
|
35
30
|
credentials (str | dict[str, Any] | None, optional): The credentials for the language model. Can either be:
|
|
36
31
|
1. An API key.
|
|
37
32
|
2. A path to a credentials JSON file, currently only supported for Google Vertex AI.
|
|
@@ -80,7 +75,7 @@ def build_lm_invoker(model_id: str | ModelId, credentials: str | dict[str, Any]
|
|
|
80
75
|
# Using Google Gen AI (via API key)
|
|
81
76
|
```python
|
|
82
77
|
lm_invoker = build_lm_invoker(
|
|
83
|
-
model_id="google/gemini-
|
|
78
|
+
model_id="google/gemini-2.5-flash-lite",
|
|
84
79
|
credentials="AIzaSyD..."
|
|
85
80
|
)
|
|
86
81
|
```
|
|
@@ -89,7 +84,7 @@ def build_lm_invoker(model_id: str | ModelId, credentials: str | dict[str, Any]
|
|
|
89
84
|
# Using Google Vertex AI (via service account)
|
|
90
85
|
```python
|
|
91
86
|
lm_invoker = build_lm_invoker(
|
|
92
|
-
model_id="google/gemini-
|
|
87
|
+
model_id="google/gemini-2.5-flash-lite",
|
|
93
88
|
credentials="/path/to/google-credentials.json"
|
|
94
89
|
)
|
|
95
90
|
```
|
|
@@ -98,30 +93,48 @@ def build_lm_invoker(model_id: str | ModelId, credentials: str | dict[str, Any]
|
|
|
98
93
|
# Using OpenAI
|
|
99
94
|
```python
|
|
100
95
|
lm_invoker = build_lm_invoker(
|
|
101
|
-
model_id="openai/gpt-
|
|
96
|
+
model_id="openai/gpt-5-nano",
|
|
102
97
|
credentials="sk-..."
|
|
103
98
|
)
|
|
104
99
|
```
|
|
105
100
|
The credentials can also be provided through the `OPENAI_API_KEY` environment variable.
|
|
106
101
|
|
|
107
|
-
# Using
|
|
102
|
+
# Using OpenAI with Chat Completions API
|
|
108
103
|
```python
|
|
109
104
|
lm_invoker = build_lm_invoker(
|
|
110
|
-
model_id="
|
|
111
|
-
credentials="
|
|
105
|
+
model_id="openai-chat-completions/gpt-5-nano",
|
|
106
|
+
credentials="sk-..."
|
|
112
107
|
)
|
|
113
108
|
```
|
|
114
|
-
The credentials can also be provided through the `
|
|
109
|
+
The credentials can also be provided through the `OPENAI_API_KEY` environment variable.
|
|
110
|
+
|
|
111
|
+
# Using OpenAI Responses API-compatible endpoints (e.g. SGLang)
|
|
112
|
+
```python
|
|
113
|
+
lm_invoker = build_lm_invoker(
|
|
114
|
+
model_id="openai/https://my-sglang-url:8000/v1:my-model-name",
|
|
115
|
+
credentials="sk-..."
|
|
116
|
+
)
|
|
117
|
+
```
|
|
118
|
+
The credentials can also be provided through the `OPENAI_API_KEY` environment variable.
|
|
115
119
|
|
|
116
|
-
# Using OpenAI
|
|
120
|
+
# Using OpenAI Chat Completions API-compatible endpoints (e.g. Groq)
|
|
117
121
|
```python
|
|
118
122
|
lm_invoker = build_lm_invoker(
|
|
119
|
-
model_id="openai-
|
|
123
|
+
model_id="openai-chat-completions/https://api.groq.com/openai/v1:llama3-8b-8192",
|
|
120
124
|
credentials="gsk_..."
|
|
121
125
|
)
|
|
122
126
|
```
|
|
123
127
|
The credentials can also be provided through the `OPENAI_API_KEY` environment variable.
|
|
124
128
|
|
|
129
|
+
# Using Azure OpenAI
|
|
130
|
+
```python
|
|
131
|
+
lm_invoker = build_lm_invoker(
|
|
132
|
+
model_id="azure-openai/https://my-resource.openai.azure.com/openai/v1:my-deployment",
|
|
133
|
+
credentials="azure-api-key"
|
|
134
|
+
)
|
|
135
|
+
```
|
|
136
|
+
The credentials can also be provided through the `AZURE_OPENAI_API_KEY` environment variable.
|
|
137
|
+
|
|
125
138
|
# Using LangChain
|
|
126
139
|
```python
|
|
127
140
|
lm_invoker = build_lm_invoker(
|
|
@@ -12,13 +12,8 @@ def build_lm_request_processor(model_id: str | ModelId, credentials: str | dict[
|
|
|
12
12
|
'''Build a language model invoker based on the provided configurations.
|
|
13
13
|
|
|
14
14
|
Args:
|
|
15
|
-
model_id (str | ModelId): The model id, can either be a ModelId instance or a string in
|
|
16
|
-
|
|
17
|
-
2. For `openai-compatible` provider: `openai-compatible/base-url:model-name`.
|
|
18
|
-
3. For `langchain` provider: `langchain/<package>.<class>:model-name`.
|
|
19
|
-
4. For `litellm` provider: `litellm/provider/model-name`.
|
|
20
|
-
5. For `datasaur` provider: `datasaur/base-url`.
|
|
21
|
-
6. For other providers: `provider/model-name`.
|
|
15
|
+
model_id (str | ModelId): The model id, can either be a ModelId instance or a string in a format defined
|
|
16
|
+
in the following page: https://gdplabs.gitbook.io/sdk/resources/supported-models#language-models-lms
|
|
22
17
|
credentials (str | dict[str, Any] | None, optional): The credentials for the language model. Can either be:
|
|
23
18
|
1. An API key.
|
|
24
19
|
2. A path to a credentials JSON file, currently only supported for Google Vertex AI.
|
|
@@ -57,7 +57,7 @@ class LMRequestProcessorCatalog(BaseCatalog[LMRequestProcessor]):
|
|
|
57
57
|
),
|
|
58
58
|
"user_template": "{query}",
|
|
59
59
|
"key_defaults": \'{"context": "<default context>"}\',
|
|
60
|
-
"model_id": "openai/gpt-
|
|
60
|
+
"model_id": "openai/gpt-5-nano",
|
|
61
61
|
"credentials": "OPENAI_API_KEY",
|
|
62
62
|
"config": "",
|
|
63
63
|
"output_parser_type": "none",
|
|
@@ -93,7 +93,7 @@ class LMRequestProcessorCatalog(BaseCatalog[LMRequestProcessor]):
|
|
|
93
93
|
prompt template keys. These default values will be applied when the corresponding keys are not provided
|
|
94
94
|
in the runtime input. If it is empty, the prompt template keys will not have default values.
|
|
95
95
|
3. The `model_id`:
|
|
96
|
-
3.1. Must be filled with the model ID of the LM invoker, e.g. "openai/gpt-
|
|
96
|
+
3.1. Must be filled with the model ID of the LM invoker, e.g. "openai/gpt-5-nano".
|
|
97
97
|
3.2. Can be partially loaded from the environment variable using the "${ENV_VAR_KEY}" syntax,
|
|
98
98
|
e.g. "azure-openai/${AZURE_ENDPOINT}/${AZURE_DEPLOYMENT}".
|
|
99
99
|
3.3. For the available model ID formats, see: https://gdplabs.gitbook.io/sdk/resources/supported-models
|
gllm_inference/constants.pyi
CHANGED
|
@@ -6,8 +6,10 @@ from gllm_inference.em_invoker.schema.openai_compatible import Key as Key
|
|
|
6
6
|
from gllm_inference.schema import ModelId as ModelId, ModelProvider as ModelProvider, TruncationConfig as TruncationConfig
|
|
7
7
|
from typing import Any
|
|
8
8
|
|
|
9
|
+
DEPRECATION_MESSAGE: str
|
|
10
|
+
|
|
9
11
|
class OpenAICompatibleEMInvoker(OpenAIEMInvoker):
|
|
10
|
-
|
|
12
|
+
"""An embedding model invoker to interact with endpoints compatible with OpenAI's embedding API contract.
|
|
11
13
|
|
|
12
14
|
Attributes:
|
|
13
15
|
model_id (str): The model ID of the embedding model.
|
|
@@ -18,65 +20,8 @@ class OpenAICompatibleEMInvoker(OpenAIEMInvoker):
|
|
|
18
20
|
retry_config (RetryConfig): The retry configuration for the embedding model.
|
|
19
21
|
truncation_config (TruncationConfig | None): The truncation configuration for the embedding model.
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
The `OpenAICompatibleEMInvoker` is designed to interact with endpoints that are compatible with OpenAI\'s
|
|
24
|
-
embedding API contract. This includes but are not limited to:
|
|
25
|
-
1. Text Embeddings Inference (https://github.com/huggingface/text-embeddings-inference)
|
|
26
|
-
2. vLLM (https://vllm.ai/)
|
|
27
|
-
When using this invoker, please note that the supported features and capabilities may vary between different
|
|
28
|
-
endpoints and language models. Using features that are not supported by the endpoint will result in an error.
|
|
29
|
-
|
|
30
|
-
Input types:
|
|
31
|
-
The `OpenAICompatibleEMInvoker` only supports text inputs.
|
|
32
|
-
|
|
33
|
-
Output format:
|
|
34
|
-
The `OpenAICompatibleEMInvoker` can embed either:
|
|
35
|
-
1. A single content.
|
|
36
|
-
1. A single content is a single text.
|
|
37
|
-
2. The output will be a `Vector`, representing the embedding of the content.
|
|
38
|
-
|
|
39
|
-
# Example 1: Embedding a text content.
|
|
40
|
-
```python
|
|
41
|
-
text = "This is a text"
|
|
42
|
-
result = await em_invoker.invoke(text)
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
The above examples will return a `Vector` with a size of (embedding_size,).
|
|
46
|
-
|
|
47
|
-
2. A list of contents.
|
|
48
|
-
1. A list of contents is a list of texts.
|
|
49
|
-
2. The output will be a `list[Vector]`, where each element is a `Vector` representing the
|
|
50
|
-
embedding of each single content.
|
|
51
|
-
|
|
52
|
-
# Example: Embedding a list of contents.
|
|
53
|
-
```python
|
|
54
|
-
text1 = "This is a text"
|
|
55
|
-
text2 = "This is another text"
|
|
56
|
-
text3 = "This is yet another text"
|
|
57
|
-
result = await em_invoker.invoke([text1, text2, text3])
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
The above examples will return a `list[Vector]` with a size of (3, embedding_size).
|
|
61
|
-
|
|
62
|
-
Retry and timeout:
|
|
63
|
-
The `OpenAICompatibleEMInvoker` supports retry and timeout configuration.
|
|
64
|
-
By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
|
|
65
|
-
They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
|
|
66
|
-
|
|
67
|
-
Retry config examples:
|
|
68
|
-
```python
|
|
69
|
-
retry_config = RetryConfig(max_retries=0, timeout=0.0) # No retry, no timeout
|
|
70
|
-
retry_config = RetryConfig(max_retries=0, timeout=10.0) # No retry, 10.0 seconds timeout
|
|
71
|
-
retry_config = RetryConfig(max_retries=5, timeout=0.0) # 5 max retries, no timeout
|
|
72
|
-
retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
Usage example:
|
|
76
|
-
```python
|
|
77
|
-
em_invoker = OpenAICompatibleEMInvoker(..., retry_config=retry_config)
|
|
78
|
-
```
|
|
79
|
-
'''
|
|
23
|
+
This class is deprecated and will be removed in v0.6. Please use the `OpenAIEMInvoker` class instead.
|
|
24
|
+
"""
|
|
80
25
|
client: Incomplete
|
|
81
26
|
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, retry_config: RetryConfig | None = None, truncation_config: TruncationConfig | None = None) -> None:
|
|
82
27
|
"""Initializes a new instance of the OpenAICompatibleEMInvoker class.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from _typeshed import Incomplete
|
|
2
2
|
from gllm_core.utils.retry import RetryConfig as RetryConfig
|
|
3
|
-
from gllm_inference.constants import INVOKER_PROPAGATED_MAX_RETRIES as INVOKER_PROPAGATED_MAX_RETRIES
|
|
3
|
+
from gllm_inference.constants import INVOKER_PROPAGATED_MAX_RETRIES as INVOKER_PROPAGATED_MAX_RETRIES, OPENAI_DEFAULT_URL as OPENAI_DEFAULT_URL
|
|
4
4
|
from gllm_inference.em_invoker.em_invoker import BaseEMInvoker as BaseEMInvoker
|
|
5
5
|
from gllm_inference.em_invoker.schema.openai import Key as Key
|
|
6
6
|
from gllm_inference.schema import ModelId as ModelId, ModelProvider as ModelProvider, Vector as Vector
|
|
@@ -21,6 +21,31 @@ class OpenAIEMInvoker(BaseEMInvoker):
|
|
|
21
21
|
retry_config (RetryConfig): The retry configuration for the embedding model.
|
|
22
22
|
truncation_config (TruncationConfig | None): The truncation configuration for the embedding model.
|
|
23
23
|
|
|
24
|
+
Basic usage:
|
|
25
|
+
The `OpenAIEMInvoker` can be used as follows:
|
|
26
|
+
```python
|
|
27
|
+
em_invoker = OpenAIEMInvoker(model_name="text-embedding-3-small")
|
|
28
|
+
result = await em_invoker.invoke("Hi there!")
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
OpenAI compatible endpoints:
|
|
32
|
+
The `OpenAIEMInvoker` can also be used to interact with endpoints that are compatible with
|
|
33
|
+
OpenAI\'s Embeddings API schema. This includes but are not limited to:
|
|
34
|
+
1. Text Embeddings Inference (https://github.com/huggingface/text-embeddings-inference)
|
|
35
|
+
2. vLLM (https://vllm.ai/)
|
|
36
|
+
Please note that the supported features and capabilities may vary between different endpoints and
|
|
37
|
+
language models. Using features that are not supported by the endpoint will result in an error.
|
|
38
|
+
|
|
39
|
+
This customization can be done by setting the `base_url` parameter to the base URL of the endpoint:
|
|
40
|
+
```python
|
|
41
|
+
em_invoker = OpenAIEMInvoker(
|
|
42
|
+
model_name="<model-name>",
|
|
43
|
+
api_key="<your-api-key>",
|
|
44
|
+
base_url="<https://base-url>",
|
|
45
|
+
)
|
|
46
|
+
result = await em_invoker.invoke("Hi there!")
|
|
47
|
+
```
|
|
48
|
+
|
|
24
49
|
Input types:
|
|
25
50
|
The `OpenAIEMInvoker` only supports text inputs.
|
|
26
51
|
|
|
@@ -72,13 +97,16 @@ class OpenAIEMInvoker(BaseEMInvoker):
|
|
|
72
97
|
```
|
|
73
98
|
'''
|
|
74
99
|
client: Incomplete
|
|
75
|
-
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, retry_config: RetryConfig | None = None, truncation_config: TruncationConfig | None = None) -> None:
|
|
76
|
-
|
|
100
|
+
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, retry_config: RetryConfig | None = None, truncation_config: TruncationConfig | None = None) -> None:
|
|
101
|
+
'''Initializes a new instance of the OpenAIEMInvoker class.
|
|
77
102
|
|
|
78
103
|
Args:
|
|
79
104
|
model_name (str): The name of the OpenAI embedding model to be used.
|
|
80
|
-
api_key (str | None, optional): The API key for
|
|
81
|
-
case the `OPENAI_API_KEY` environment variable will be used.
|
|
105
|
+
api_key (str | None, optional): The API key for authenticating with OpenAI. Defaults to None, in which
|
|
106
|
+
case the `OPENAI_API_KEY` environment variable will be used. If the endpoint does not require an
|
|
107
|
+
API key, a dummy value can be passed (e.g. "<empty>").
|
|
108
|
+
base_url (str, optional): The base URL of a custom endpoint that is compatible with OpenAI\'s
|
|
109
|
+
Embeddings API schema. Defaults to OpenAI\'s default URL.
|
|
82
110
|
model_kwargs (dict[str, Any] | None, optional): Additional keyword arguments for the OpenAI client.
|
|
83
111
|
Defaults to None.
|
|
84
112
|
default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
|
|
@@ -87,4 +115,4 @@ class OpenAIEMInvoker(BaseEMInvoker):
|
|
|
87
115
|
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
88
116
|
truncation_config (TruncationConfig | None, optional): Configuration for text truncation behavior.
|
|
89
117
|
Defaults to None, in which case no truncation is applied.
|
|
90
|
-
|
|
118
|
+
'''
|
|
@@ -5,8 +5,9 @@ from gllm_inference.lm_invoker.datasaur_lm_invoker import DatasaurLMInvoker as D
|
|
|
5
5
|
from gllm_inference.lm_invoker.google_lm_invoker import GoogleLMInvoker as GoogleLMInvoker
|
|
6
6
|
from gllm_inference.lm_invoker.langchain_lm_invoker import LangChainLMInvoker as LangChainLMInvoker
|
|
7
7
|
from gllm_inference.lm_invoker.litellm_lm_invoker import LiteLLMLMInvoker as LiteLLMLMInvoker
|
|
8
|
+
from gllm_inference.lm_invoker.openai_chat_completions_lm_invoker import OpenAIChatCompletionsLMInvoker as OpenAIChatCompletionsLMInvoker
|
|
8
9
|
from gllm_inference.lm_invoker.openai_compatible_lm_invoker import OpenAICompatibleLMInvoker as OpenAICompatibleLMInvoker
|
|
9
10
|
from gllm_inference.lm_invoker.openai_lm_invoker import OpenAILMInvoker as OpenAILMInvoker
|
|
10
11
|
from gllm_inference.lm_invoker.xai_lm_invoker import XAILMInvoker as XAILMInvoker
|
|
11
12
|
|
|
12
|
-
__all__ = ['AnthropicLMInvoker', 'AzureOpenAILMInvoker', 'BedrockLMInvoker', 'DatasaurLMInvoker', 'GoogleLMInvoker', 'LangChainLMInvoker', 'LiteLLMLMInvoker', 'OpenAICompatibleLMInvoker', 'OpenAILMInvoker', 'XAILMInvoker']
|
|
13
|
+
__all__ = ['AnthropicLMInvoker', 'AzureOpenAILMInvoker', 'BedrockLMInvoker', 'DatasaurLMInvoker', 'GoogleLMInvoker', 'LangChainLMInvoker', 'LiteLLMLMInvoker', 'OpenAIChatCompletionsLMInvoker', 'OpenAICompatibleLMInvoker', 'OpenAILMInvoker', 'XAILMInvoker']
|
|
@@ -37,7 +37,7 @@ class LangChainLMInvoker(BaseLMInvoker):
|
|
|
37
37
|
```python
|
|
38
38
|
lm_invoker = LangChainLMInvoker(
|
|
39
39
|
model_class_path="langchain_openai.ChatOpenAI",
|
|
40
|
-
model_name="gpt-
|
|
40
|
+
model_name="gpt-5-nano",
|
|
41
41
|
)
|
|
42
42
|
result = await lm_invoker.invoke("Hi there!")
|
|
43
43
|
```
|
|
@@ -50,7 +50,7 @@ class LangChainLMInvoker(BaseLMInvoker):
|
|
|
50
50
|
```python
|
|
51
51
|
from langchain_openai import ChatOpenAI
|
|
52
52
|
|
|
53
|
-
model = ChatOpenAI(model="gpt-
|
|
53
|
+
model = ChatOpenAI(model="gpt-5-nano", api_key="your_api_key")
|
|
54
54
|
lm_invoker = LangChainLMInvoker(model=model)
|
|
55
55
|
```
|
|
56
56
|
|
|
@@ -59,7 +59,7 @@ class LangChainLMInvoker(BaseLMInvoker):
|
|
|
59
59
|
```python
|
|
60
60
|
lm_invoker = LangChainLMInvoker(
|
|
61
61
|
model_class_path="langchain_openai.ChatOpenAI",
|
|
62
|
-
model_name="gpt-
|
|
62
|
+
model_name="gpt-5-nano",
|
|
63
63
|
model_kwargs={"api_key": "your_api_key"}
|
|
64
64
|
)
|
|
65
65
|
```
|
|
@@ -27,7 +27,7 @@ class LiteLLMLMInvoker(OpenAICompatibleLMInvoker):
|
|
|
27
27
|
Basic usage:
|
|
28
28
|
The `LiteLLMLMInvoker` can be used as follows:
|
|
29
29
|
```python
|
|
30
|
-
lm_invoker = LiteLLMLMInvoker(model_id="openai/gpt-
|
|
30
|
+
lm_invoker = LiteLLMLMInvoker(model_id="openai/gpt-5-nano")
|
|
31
31
|
result = await lm_invoker.invoke("Hi there!")
|
|
32
32
|
```
|
|
33
33
|
|
|
@@ -0,0 +1,278 @@
|
|
|
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, 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 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 (AsyncOpenAI): The OpenAI client instance.
|
|
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=0.0) # 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=0.0) # 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
|
+
When streaming is enabled along with reasoning and the provider supports reasoning output, the reasoning token
|
|
211
|
+
will be streamed with the `EventType.DATA` event type.
|
|
212
|
+
|
|
213
|
+
Streaming output example:
|
|
214
|
+
```python
|
|
215
|
+
{"type": "data", "value": \'{"data_type": "thinking_start", "data_value": ""}\', ...}
|
|
216
|
+
{"type": "data", "value": \'{"data_type": "thinking", "data_value": "Let me think "}\', ...}
|
|
217
|
+
{"type": "data", "value": \'{"data_type": "thinking", "data_value": "about it..."}\', ...}
|
|
218
|
+
{"type": "data", "value": \'{"data_type": "thinking_end", "data_value": ""}\', ...}
|
|
219
|
+
{"type": "response", "value": "Golden retriever ", ...}
|
|
220
|
+
{"type": "response", "value": "is a good dog breed.", ...}
|
|
221
|
+
```
|
|
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`: The text response if no additional output is needed.
|
|
228
|
+
2. `LMOutput`: A Pydantic model with the following attributes if any additional output is needed:
|
|
229
|
+
2.1. response (str): The text response.
|
|
230
|
+
2.2. tool_calls (list[ToolCall]): The tool calls, if the `tools` parameter is defined and the language
|
|
231
|
+
model decides to invoke tools. Defaults to an empty list.
|
|
232
|
+
2.3. structured_output (dict[str, Any] | BaseModel | None): The structured output, if the `response_schema`
|
|
233
|
+
parameter is defined. Defaults to None.
|
|
234
|
+
2.4. token_usage (TokenUsage | None): The token usage analytics, if the `output_analytics` parameter is
|
|
235
|
+
set to `True`. Defaults to None.
|
|
236
|
+
2.5. duration (float | None): The duration of the invocation in seconds, if the `output_analytics`
|
|
237
|
+
parameter is set to `True`. Defaults to None.
|
|
238
|
+
2.6. finish_details (dict[str, Any] | None): The details about how the generation finished, if the
|
|
239
|
+
`output_analytics` parameter is set to `True`. Defaults to None.
|
|
240
|
+
2.7. reasoning (list[Reasoning]): The reasoning objects. Currently not supported. Defaults to an empty list.
|
|
241
|
+
2.8. citations (list[Chunk]): The citations. Currently not supported. Defaults to an empty list.
|
|
242
|
+
2.9. code_exec_results (list[CodeExecResult]): The code execution results. Currently not supported.
|
|
243
|
+
Defaults to an empty list.
|
|
244
|
+
2.10. mcp_calls (list[MCPCall]): The MCP calls. Currently not supported. Defaults to an empty list.
|
|
245
|
+
'''
|
|
246
|
+
client: Incomplete
|
|
247
|
+
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) -> None:
|
|
248
|
+
'''Initializes a new instance of the OpenAIChatCompletionsLMInvoker class.
|
|
249
|
+
|
|
250
|
+
Args:
|
|
251
|
+
model_name (str): The name of the OpenAI model.
|
|
252
|
+
api_key (str | None, optional): The API key for authenticating with OpenAI. Defaults to None, in which
|
|
253
|
+
case the `OPENAI_API_KEY` environment variable will be used. If the endpoint does not require an
|
|
254
|
+
API key, a dummy value can be passed (e.g. "<empty>").
|
|
255
|
+
base_url (str, optional): The base URL of a custom endpoint that is compatible with OpenAI\'s
|
|
256
|
+
Chat Completions API schema. Defaults to OpenAI\'s default URL.
|
|
257
|
+
model_kwargs (dict[str, Any] | None, optional): Additional model parameters. Defaults to None.
|
|
258
|
+
default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
|
|
259
|
+
Defaults to None.
|
|
260
|
+
tools (list[Tool | LangChainTool] | None, optional): Tools provided to the model to enable tool calling.
|
|
261
|
+
Defaults to None.
|
|
262
|
+
response_schema (ResponseSchema | None, optional): The schema of the response. If provided, the model will
|
|
263
|
+
output a structured response as defined by the schema. Supports both Pydantic BaseModel and JSON schema
|
|
264
|
+
dictionary. Defaults to None.
|
|
265
|
+
output_analytics (bool, optional): Whether to output the invocation analytics. Defaults to False.
|
|
266
|
+
retry_config (RetryConfig | None, optional): The retry configuration for the language model.
|
|
267
|
+
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
268
|
+
reasoning_effort (str | None, optional): The reasoning effort for the language model. Defaults to None.
|
|
269
|
+
'''
|
|
270
|
+
def set_response_schema(self, response_schema: ResponseSchema | None) -> None:
|
|
271
|
+
"""Sets the response schema for the OpenAI language model.
|
|
272
|
+
|
|
273
|
+
This method sets the response schema for the OpenAI language model.
|
|
274
|
+
Any existing response schema will be replaced.
|
|
275
|
+
|
|
276
|
+
Args:
|
|
277
|
+
response_schema (ResponseSchema | None): The response schema to be used.
|
|
278
|
+
"""
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
from _typeshed import Incomplete
|
|
2
|
-
from gllm_core.event import EventEmitter as EventEmitter
|
|
3
1
|
from gllm_core.schema.tool import Tool as Tool
|
|
4
|
-
from gllm_core.utils
|
|
5
|
-
from gllm_inference.
|
|
6
|
-
from gllm_inference.lm_invoker.
|
|
7
|
-
from gllm_inference.
|
|
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 import validate_string_enum as validate_string_enum
|
|
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
|
|
10
6
|
from langchain_core.tools import Tool as LangChainTool
|
|
11
7
|
from typing import Any
|
|
12
8
|
|
|
13
|
-
|
|
9
|
+
DEPRECATION_MESSAGE: str
|
|
14
10
|
|
|
15
|
-
class OpenAICompatibleLMInvoker(
|
|
16
|
-
|
|
11
|
+
class OpenAICompatibleLMInvoker(OpenAIChatCompletionsLMInvoker):
|
|
12
|
+
"""A language model invoker to interact with endpoints compatible with OpenAI's chat completion API contract.
|
|
17
13
|
|
|
18
14
|
Attributes:
|
|
19
15
|
model_id (str): The model ID of the language model.
|
|
@@ -27,212 +23,8 @@ class OpenAICompatibleLMInvoker(BaseLMInvoker):
|
|
|
27
23
|
output_analytics (bool): Whether to output the invocation analytics.
|
|
28
24
|
retry_config (RetryConfig | None): The retry configuration for the language model.
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
completion API contract. This includes but are not limited to:
|
|
33
|
-
1. DeepInfra (https://deepinfra.com/)
|
|
34
|
-
2. DeepSeek (https://deepseek.com/)
|
|
35
|
-
3. Groq (https://groq.com/)
|
|
36
|
-
4. OpenRouter (https://openrouter.ai/)
|
|
37
|
-
5. Text Generation Inference (https://github.com/huggingface/text-generation-inference)
|
|
38
|
-
6. Together.ai (https://together.ai/)
|
|
39
|
-
7. vLLM (https://vllm.ai/)
|
|
40
|
-
When using this invoker, please note that the supported features and capabilities may vary between different
|
|
41
|
-
endpoints and language models. Using features that are not supported by the endpoint will result in an error.
|
|
42
|
-
|
|
43
|
-
Basic usage:
|
|
44
|
-
The `OpenAICompatibleLMInvoker` can be used as follows:
|
|
45
|
-
```python
|
|
46
|
-
lm_invoker = OpenAICompatibleLMInvoker(
|
|
47
|
-
model_name="llama3-8b-8192",
|
|
48
|
-
base_url="https://api.groq.com/openai/v1",
|
|
49
|
-
api_key="<your-api-key>"
|
|
50
|
-
)
|
|
51
|
-
result = await lm_invoker.invoke("Hi there!")
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
Input types:
|
|
55
|
-
The `OpenAICompatibleLMInvoker` supports the following input types: text, audio, document, and image.
|
|
56
|
-
Non-text inputs can be passed as an `Attachment` object with the `user` role.
|
|
57
|
-
|
|
58
|
-
Usage example:
|
|
59
|
-
```python
|
|
60
|
-
text = "What animal is in this image?"
|
|
61
|
-
image = Attachment.from_path("path/to/local/image.png")
|
|
62
|
-
result = await lm_invoker.invoke([text, image])
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
Tool calling:
|
|
66
|
-
Tool calling is a feature that allows the language model to call tools to perform tasks.
|
|
67
|
-
Tools can be passed to the via the `tools` parameter as a list of `Tool` objects.
|
|
68
|
-
When tools are provided and the model decides to call a tool, the tool calls are stored in the
|
|
69
|
-
`tool_calls` attribute in the output.
|
|
70
|
-
|
|
71
|
-
Usage example:
|
|
72
|
-
```python
|
|
73
|
-
lm_invoker = OpenAICompatibleLMInvoker(..., tools=[tool_1, tool_2])
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
Output example:
|
|
77
|
-
```python
|
|
78
|
-
LMOutput(
|
|
79
|
-
response="Let me call the tools...",
|
|
80
|
-
tool_calls=[
|
|
81
|
-
ToolCall(id="123", name="tool_1", args={"key": "value"}),
|
|
82
|
-
ToolCall(id="456", name="tool_2", args={"key": "value"}),
|
|
83
|
-
]
|
|
84
|
-
)
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
Structured output:
|
|
88
|
-
Structured output is a feature that allows the language model to output a structured response.
|
|
89
|
-
This feature can be enabled by providing a schema to the `response_schema` parameter.
|
|
90
|
-
|
|
91
|
-
The schema must be either a JSON schema dictionary or a Pydantic BaseModel class.
|
|
92
|
-
If JSON schema is used, it must be compatible with Pydantic\'s JSON schema, especially for complex schemas.
|
|
93
|
-
For this reason, it is recommended to create the JSON schema using Pydantic\'s `model_json_schema` method.
|
|
94
|
-
|
|
95
|
-
The language model also doesn\'t need to stream anything when structured output is enabled. Thus, standard
|
|
96
|
-
invocation will be performed regardless of whether the `event_emitter` parameter is provided or not.
|
|
97
|
-
|
|
98
|
-
When enabled, the structured output is stored in the `structured_output` attribute in the output.
|
|
99
|
-
1. If the schema is a JSON schema dictionary, the structured output is a dictionary.
|
|
100
|
-
2. If the schema is a Pydantic BaseModel class, the structured output is a Pydantic model.
|
|
101
|
-
|
|
102
|
-
# Example 1: Using a JSON schema dictionary
|
|
103
|
-
Usage example:
|
|
104
|
-
```python
|
|
105
|
-
schema = {
|
|
106
|
-
"title": "Animal",
|
|
107
|
-
"description": "A description of an animal.",
|
|
108
|
-
"properties": {
|
|
109
|
-
"color": {"title": "Color", "type": "string"},
|
|
110
|
-
"name": {"title": "Name", "type": "string"},
|
|
111
|
-
},
|
|
112
|
-
"required": ["name", "color"],
|
|
113
|
-
"type": "object",
|
|
114
|
-
}
|
|
115
|
-
lm_invoker = OpenAICompatibleLMInvoker(..., response_schema=schema)
|
|
116
|
-
```
|
|
117
|
-
Output example:
|
|
118
|
-
```python
|
|
119
|
-
LMOutput(structured_output={"name": "Golden retriever", "color": "Golden"})
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
# Example 2: Using a Pydantic BaseModel class
|
|
123
|
-
Usage example:
|
|
124
|
-
```python
|
|
125
|
-
class Animal(BaseModel):
|
|
126
|
-
name: str
|
|
127
|
-
color: str
|
|
128
|
-
|
|
129
|
-
lm_invoker = OpenAICompatibleLMInvoker(..., response_schema=Animal)
|
|
130
|
-
```
|
|
131
|
-
Output example:
|
|
132
|
-
```python
|
|
133
|
-
LMOutput(structured_output=Animal(name="Golden retriever", color="Golden"))
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
Analytics tracking:
|
|
137
|
-
Analytics tracking is a feature that allows the module to output additional information about the invocation.
|
|
138
|
-
This feature can be enabled by setting the `output_analytics` parameter to `True`.
|
|
139
|
-
When enabled, the following attributes will be stored in the output:
|
|
140
|
-
1. `token_usage`: The token usage.
|
|
141
|
-
2. `duration`: The duration in seconds.
|
|
142
|
-
3. `finish_details`: The details about how the generation finished.
|
|
143
|
-
|
|
144
|
-
Output example:
|
|
145
|
-
```python
|
|
146
|
-
LMOutput(
|
|
147
|
-
response="Golden retriever is a good dog breed.",
|
|
148
|
-
token_usage=TokenUsage(input_tokens=100, output_tokens=50),
|
|
149
|
-
duration=0.729,
|
|
150
|
-
finish_details={"finish_reason": "stop"},
|
|
151
|
-
)
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
When streaming is enabled, token usage is not supported. Therefore, the `token_usage` attribute will be `None`
|
|
155
|
-
regardless of the value of the `output_analytics` parameter.
|
|
156
|
-
|
|
157
|
-
Retry and timeout:
|
|
158
|
-
The `OpenAICompatibleLMInvoker` supports retry and timeout configuration.
|
|
159
|
-
By default, the max retries is set to 0 and the timeout is set to 30.0 seconds.
|
|
160
|
-
They can be customized by providing a custom `RetryConfig` object to the `retry_config` parameter.
|
|
161
|
-
|
|
162
|
-
Retry config examples:
|
|
163
|
-
```python
|
|
164
|
-
retry_config = RetryConfig(max_retries=0, timeout=0.0) # No retry, no timeout
|
|
165
|
-
retry_config = RetryConfig(max_retries=0, timeout=10.0) # No retry, 10.0 seconds timeout
|
|
166
|
-
retry_config = RetryConfig(max_retries=5, timeout=0.0) # 5 max retries, no timeout
|
|
167
|
-
retry_config = RetryConfig(max_retries=5, timeout=10.0) # 5 max retries, 10.0 seconds timeout
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
Usage example:
|
|
171
|
-
```python
|
|
172
|
-
lm_invoker = OpenAICompatibleLMInvoker(..., retry_config=retry_config)
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
Reasoning:
|
|
176
|
-
Some language models support advanced reasoning capabilities. When using such reasoning-capable models,
|
|
177
|
-
you can configure how much reasoning the model should perform before generating a final response by setting
|
|
178
|
-
reasoning-related parameters.
|
|
179
|
-
|
|
180
|
-
The reasoning effort of reasoning models can be set via the `reasoning_effort` parameter. This parameter
|
|
181
|
-
will guide the models on how many reasoning tokens it should generate before creating a response to the prompt.
|
|
182
|
-
The reasoning effort is only supported by some language models.
|
|
183
|
-
Available options include:
|
|
184
|
-
1. "low": Favors speed and economical token usage.
|
|
185
|
-
2. "medium": Favors a balance between speed and reasoning accuracy.
|
|
186
|
-
3. "high": Favors more complete reasoning at the cost of more tokens generated and slower responses.
|
|
187
|
-
This may differ between models. When not set, the reasoning effort will be equivalent to None by default.
|
|
188
|
-
|
|
189
|
-
When using reasoning models, some providers might output the reasoning summary. These will be stored in the
|
|
190
|
-
`reasoning` attribute in the output.
|
|
191
|
-
|
|
192
|
-
Output example:
|
|
193
|
-
```python
|
|
194
|
-
LMOutput(
|
|
195
|
-
response="Golden retriever is a good dog breed.",
|
|
196
|
-
reasoning=[Reasoning(id="", reasoning="Let me think about it...")],
|
|
197
|
-
)
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
When streaming is enabled along with reasoning and the provider supports reasoning output, the reasoning token
|
|
201
|
-
will be streamed with the `EventType.DATA` event type.
|
|
202
|
-
|
|
203
|
-
Streaming output example:
|
|
204
|
-
```python
|
|
205
|
-
{"type": "data", "value": \'{"data_type": "thinking_start", "data_value": ""}\', ...}
|
|
206
|
-
{"type": "data", "value": \'{"data_type": "thinking", "data_value": "Let me think "}\', ...}
|
|
207
|
-
{"type": "data", "value": \'{"data_type": "thinking", "data_value": "about it..."}\', ...}
|
|
208
|
-
{"type": "data", "value": \'{"data_type": "thinking_end", "data_value": ""}\', ...}
|
|
209
|
-
{"type": "response", "value": "Golden retriever ", ...}
|
|
210
|
-
{"type": "response", "value": "is a good dog breed.", ...}
|
|
211
|
-
|
|
212
|
-
Setting reasoning-related parameters for non-reasoning models will raise an error.
|
|
213
|
-
|
|
214
|
-
Output types:
|
|
215
|
-
The output of the `OpenAICompatibleLMInvoker` can either be:
|
|
216
|
-
1. `str`: The text response if no additional output is needed.
|
|
217
|
-
2. `LMOutput`: A Pydantic model with the following attributes if any additional output is needed:
|
|
218
|
-
2.1. response (str): The text response.
|
|
219
|
-
2.2. tool_calls (list[ToolCall]): The tool calls, if the `tools` parameter is defined and the language
|
|
220
|
-
model decides to invoke tools. Defaults to an empty list.
|
|
221
|
-
2.3. structured_output (dict[str, Any] | BaseModel | None): The structured output, if the `response_schema`
|
|
222
|
-
parameter is defined. Defaults to None.
|
|
223
|
-
2.4. token_usage (TokenUsage | None): The token usage analytics, if the `output_analytics` parameter is
|
|
224
|
-
set to `True`. Defaults to None.
|
|
225
|
-
2.5. duration (float | None): The duration of the invocation in seconds, if the `output_analytics`
|
|
226
|
-
parameter is set to `True`. Defaults to None.
|
|
227
|
-
2.6. finish_details (dict[str, Any] | None): The details about how the generation finished, if the
|
|
228
|
-
`output_analytics` parameter is set to `True`. Defaults to None.
|
|
229
|
-
2.7. reasoning (list[Reasoning]): The reasoning objects. Currently not supported. Defaults to an empty list.
|
|
230
|
-
2.8. citations (list[Chunk]): The citations. Currently not supported. Defaults to an empty list.
|
|
231
|
-
2.9. code_exec_results (list[CodeExecResult]): The code execution results. Currently not supported.
|
|
232
|
-
Defaults to an empty list.
|
|
233
|
-
2.10. mcp_calls (list[MCPCall]): The MCP calls. Currently not supported. Defaults to an empty list.
|
|
234
|
-
'''
|
|
235
|
-
client: Incomplete
|
|
26
|
+
This class is deprecated and will be removed in v0.6. Please use the `OpenAIChatCompletionsLMInvoker` class instead.
|
|
27
|
+
"""
|
|
236
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) -> None:
|
|
237
29
|
'''Initializes a new instance of the OpenAICompatibleLMInvoker class.
|
|
238
30
|
|
|
@@ -255,12 +47,3 @@ class OpenAICompatibleLMInvoker(BaseLMInvoker):
|
|
|
255
47
|
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
256
48
|
reasoning_effort (str | None, optional): The reasoning effort for the language model. Defaults to None.
|
|
257
49
|
'''
|
|
258
|
-
def set_response_schema(self, response_schema: ResponseSchema | None) -> None:
|
|
259
|
-
"""Sets the response schema for the language model hosted on the OpenAI compatible endpoint.
|
|
260
|
-
|
|
261
|
-
This method sets the response schema for the language model hosted on the OpenAI compatible endpoint. Any
|
|
262
|
-
existing response schema will be replaced.
|
|
263
|
-
|
|
264
|
-
Args:
|
|
265
|
-
response_schema (ResponseSchema | None): The response schema to be used.
|
|
266
|
-
"""
|
|
@@ -2,7 +2,7 @@ from _typeshed import Incomplete
|
|
|
2
2
|
from gllm_core.event import EventEmitter as EventEmitter
|
|
3
3
|
from gllm_core.schema.tool import Tool as Tool
|
|
4
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
|
|
5
|
+
from gllm_inference.constants import INVOKER_PROPAGATED_MAX_RETRIES as INVOKER_PROPAGATED_MAX_RETRIES, OPENAI_DEFAULT_URL as OPENAI_DEFAULT_URL
|
|
6
6
|
from gllm_inference.lm_invoker.lm_invoker import BaseLMInvoker as BaseLMInvoker
|
|
7
7
|
from gllm_inference.lm_invoker.schema.openai import InputType as InputType, Key as Key, OutputType as OutputType, ReasoningEffort as ReasoningEffort, ReasoningSummary as ReasoningSummary
|
|
8
8
|
from gllm_inference.schema import Attachment as Attachment, AttachmentType as AttachmentType, CodeExecResult as CodeExecResult, EmitDataType as EmitDataType, LMOutput as LMOutput, MCPCall as MCPCall, MCPServer as MCPServer, 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
|
|
@@ -17,6 +17,10 @@ STREAM_DATA_CONTENT_TYPE_MAP: Incomplete
|
|
|
17
17
|
class OpenAILMInvoker(BaseLMInvoker):
|
|
18
18
|
'''A language model invoker to interact with OpenAI language models.
|
|
19
19
|
|
|
20
|
+
This class provides support for OpenAI\'s Responses API schema, which is recommended by OpenAI as the preferred API
|
|
21
|
+
to use whenever possible. Use this class unless you have a specific reason to use the Chat Completions API instead.
|
|
22
|
+
The Chat Completions API schema is supported through the `OpenAIChatCompletionsLMInvoker` class.
|
|
23
|
+
|
|
20
24
|
Attributes:
|
|
21
25
|
model_id (str): The model ID of the language model.
|
|
22
26
|
model_provider (str): The provider of the language model.
|
|
@@ -39,7 +43,24 @@ class OpenAILMInvoker(BaseLMInvoker):
|
|
|
39
43
|
Basic usage:
|
|
40
44
|
The `OpenAILMInvoker` can be used as follows:
|
|
41
45
|
```python
|
|
42
|
-
lm_invoker = OpenAILMInvoker(model_name="gpt-
|
|
46
|
+
lm_invoker = OpenAILMInvoker(model_name="gpt-5-nano")
|
|
47
|
+
result = await lm_invoker.invoke("Hi there!")
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
OpenAI compatible endpoints:
|
|
51
|
+
The `OpenAILMInvoker` can also be used to interact with endpoints that are compatible with
|
|
52
|
+
OpenAI\'s Responses API schema. This includes but are not limited to:
|
|
53
|
+
1. SGLang (https://github.com/sgl-project/sglang)
|
|
54
|
+
Please note that the supported features and capabilities may vary between different endpoints and
|
|
55
|
+
language models. Using features that are not supported by the endpoint will result in an error.
|
|
56
|
+
|
|
57
|
+
This customization can be done by setting the `base_url` parameter to the base URL of the endpoint:
|
|
58
|
+
```python
|
|
59
|
+
lm_invoker = OpenAILMInvoker(
|
|
60
|
+
model_name="<model-name>",
|
|
61
|
+
api_key="<your-api-key>",
|
|
62
|
+
base_url="<https://base-url>",
|
|
63
|
+
)
|
|
43
64
|
result = await lm_invoker.invoke("Hi there!")
|
|
44
65
|
```
|
|
45
66
|
|
|
@@ -371,13 +392,16 @@ class OpenAILMInvoker(BaseLMInvoker):
|
|
|
371
392
|
decides to invoke MCP tools. Defaults to an empty list.
|
|
372
393
|
'''
|
|
373
394
|
client: Incomplete
|
|
374
|
-
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, reasoning_summary: ReasoningSummary | None = None, mcp_servers: list[MCPServer] | None = None, code_interpreter: bool = False, web_search: bool = False) -> None:
|
|
375
|
-
|
|
395
|
+
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, reasoning_summary: ReasoningSummary | None = None, mcp_servers: list[MCPServer] | None = None, code_interpreter: bool = False, web_search: bool = False) -> None:
|
|
396
|
+
'''Initializes a new instance of the OpenAILMInvoker class.
|
|
376
397
|
|
|
377
398
|
Args:
|
|
378
399
|
model_name (str): The name of the OpenAI model.
|
|
379
400
|
api_key (str | None, optional): The API key for authenticating with OpenAI. Defaults to None, in which
|
|
380
|
-
case the `OPENAI_API_KEY` environment variable will be used.
|
|
401
|
+
case the `OPENAI_API_KEY` environment variable will be used. If the endpoint does not require an
|
|
402
|
+
API key, a dummy value can be passed (e.g. "<empty>").
|
|
403
|
+
base_url (str, optional): The base URL of a custom endpoint that is compatible with OpenAI\'s
|
|
404
|
+
Responses API schema. Defaults to OpenAI\'s default URL.
|
|
381
405
|
model_kwargs (dict[str, Any] | None, optional): Additional model parameters. Defaults to None.
|
|
382
406
|
default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
|
|
383
407
|
Defaults to None.
|
|
@@ -402,7 +426,7 @@ class OpenAILMInvoker(BaseLMInvoker):
|
|
|
402
426
|
ValueError:
|
|
403
427
|
1. `reasoning_effort` is provided, but is not a valid ReasoningEffort.
|
|
404
428
|
2. `reasoning_summary` is provided, but is not a valid ReasoningSummary.
|
|
405
|
-
|
|
429
|
+
'''
|
|
406
430
|
def set_response_schema(self, response_schema: ResponseSchema | None) -> None:
|
|
407
431
|
"""Sets the response schema for the OpenAI language model.
|
|
408
432
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from enum import StrEnum
|
|
2
2
|
|
|
3
3
|
class Key:
|
|
4
|
-
"""Defines valid keys in OpenAI
|
|
4
|
+
"""Defines valid keys in OpenAI Chat Completions."""
|
|
5
5
|
ARGUMENTS: str
|
|
6
6
|
CONTENT: str
|
|
7
7
|
CHOICES: str
|
|
@@ -42,7 +42,7 @@ class Key:
|
|
|
42
42
|
SUMMARY: str
|
|
43
43
|
|
|
44
44
|
class InputType:
|
|
45
|
-
"""Defines valid input types in OpenAI
|
|
45
|
+
"""Defines valid input types in OpenAI Chat Completions."""
|
|
46
46
|
FILE: str
|
|
47
47
|
FUNCTION: str
|
|
48
48
|
IMAGE_URL: str
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
1
2
|
from enum import StrEnum
|
|
2
3
|
from gllm_inference.utils import validate_string_enum as validate_string_enum
|
|
3
4
|
from pydantic import BaseModel
|
|
@@ -16,11 +17,15 @@ class ModelProvider(StrEnum):
|
|
|
16
17
|
LANGCHAIN = 'langchain'
|
|
17
18
|
LITELLM = 'litellm'
|
|
18
19
|
OPENAI = 'openai'
|
|
20
|
+
OPENAI_CHAT_COMPLETIONS = 'openai-chat-completions'
|
|
19
21
|
OPENAI_COMPATIBLE = 'openai-compatible'
|
|
20
22
|
TWELVELABS = 'twelvelabs'
|
|
21
23
|
VOYAGE = 'voyage'
|
|
22
24
|
XAI = 'xai'
|
|
23
25
|
|
|
26
|
+
OPTIONAL_PATH_PROVIDERS: Incomplete
|
|
27
|
+
PATH_SUPPORTING_PROVIDERS: Incomplete
|
|
28
|
+
|
|
24
29
|
class ModelId(BaseModel):
|
|
25
30
|
'''Defines a representation of a valid model id.
|
|
26
31
|
|
|
@@ -32,7 +37,7 @@ class ModelId(BaseModel):
|
|
|
32
37
|
Provider-specific examples:
|
|
33
38
|
# Using Anthropic
|
|
34
39
|
```python
|
|
35
|
-
model_id = ModelId.from_string("anthropic/claude-
|
|
40
|
+
model_id = ModelId.from_string("anthropic/claude-sonnet-4-20250514")
|
|
36
41
|
```
|
|
37
42
|
|
|
38
43
|
# Using Bedrock
|
|
@@ -47,22 +52,32 @@ class ModelId(BaseModel):
|
|
|
47
52
|
|
|
48
53
|
# Using Google
|
|
49
54
|
```python
|
|
50
|
-
model_id = ModelId.from_string("google/gemini-
|
|
55
|
+
model_id = ModelId.from_string("google/gemini-2.5-flash-lite")
|
|
51
56
|
```
|
|
52
57
|
|
|
53
58
|
# Using OpenAI
|
|
54
59
|
```python
|
|
55
|
-
model_id = ModelId.from_string("openai/gpt-
|
|
60
|
+
model_id = ModelId.from_string("openai/gpt-5-nano")
|
|
56
61
|
```
|
|
57
62
|
|
|
58
|
-
# Using
|
|
63
|
+
# Using OpenAI with Chat Completions API
|
|
59
64
|
```python
|
|
60
|
-
model_id = ModelId.from_string("
|
|
65
|
+
model_id = ModelId.from_string("openai-chat-completions/gpt-5-nano")
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
# Using OpenAI Responses API-compatible endpoints (e.g. SGLang)
|
|
69
|
+
```python
|
|
70
|
+
model_id = ModelId.from_string("openai/https://my-sglang-url:8000/v1:my-model-name")
|
|
61
71
|
```
|
|
62
72
|
|
|
63
|
-
# Using OpenAI compatible endpoints (e.g. Groq)
|
|
73
|
+
# Using OpenAI Chat Completions API-compatible endpoints (e.g. Groq)
|
|
64
74
|
```python
|
|
65
|
-
model_id = ModelId.from_string("openai-
|
|
75
|
+
model_id = ModelId.from_string("openai-chat-completions/https://api.groq.com/openai/v1:llama3-8b-8192")
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
# Using Azure OpenAI
|
|
79
|
+
```python
|
|
80
|
+
model_id = ModelId.from_string("azure-openai/https://my-resource.openai.azure.com/openai/v1:my-deployment")
|
|
66
81
|
```
|
|
67
82
|
|
|
68
83
|
# Using Voyage
|
|
@@ -89,7 +104,7 @@ class ModelId(BaseModel):
|
|
|
89
104
|
For the list of supported providers, please refer to the following page:
|
|
90
105
|
https://docs.litellm.ai/docs/providers/
|
|
91
106
|
|
|
92
|
-
# Using
|
|
107
|
+
# Using xAI
|
|
93
108
|
```python
|
|
94
109
|
model_id = ModelId.from_string("xai/grok-4-0709")
|
|
95
110
|
```
|
|
@@ -99,9 +114,9 @@ class ModelId(BaseModel):
|
|
|
99
114
|
Custom model name validation example:
|
|
100
115
|
```python
|
|
101
116
|
validation_map = {
|
|
102
|
-
ModelProvider.ANTHROPIC: {"claude-
|
|
103
|
-
ModelProvider.GOOGLE: {"gemini-
|
|
104
|
-
ModelProvider.OPENAI: {"gpt-
|
|
117
|
+
ModelProvider.ANTHROPIC: {"claude-sonnet-4-20250514"},
|
|
118
|
+
ModelProvider.GOOGLE: {"gemini-2.5-flash-lite"},
|
|
119
|
+
ModelProvider.OPENAI: {"gpt-4.1-nano", "gpt-5-nano"},
|
|
105
120
|
}
|
|
106
121
|
|
|
107
122
|
model_id = ModelId.from_string("...", validation_map)
|
|
@@ -115,13 +130,8 @@ class ModelId(BaseModel):
|
|
|
115
130
|
"""Parse a model id string into a ModelId object.
|
|
116
131
|
|
|
117
132
|
Args:
|
|
118
|
-
model_id (str): The model id to parse. Must be in the the following
|
|
119
|
-
|
|
120
|
-
2. For `openai-compatible` provider: `openai-compatible/base-url:model-name`.
|
|
121
|
-
3. For `langchain` provider: `langchain/<package>.<class>:model-name`.
|
|
122
|
-
4. For `litellm` provider: `litellm/provider/model-name`.
|
|
123
|
-
5. For `datasaur` provider: `datasaur/base-url`.
|
|
124
|
-
6. For other providers: `provider/model-name`.
|
|
133
|
+
model_id (str): The model id to parse. Must be in the format defined in the following page:
|
|
134
|
+
https://gdplabs.gitbook.io/sdk/resources/supported-models
|
|
125
135
|
validation_map (dict[str, set[str]] | None, optional): An optional dictionary that maps provider names to
|
|
126
136
|
sets of valid model names. For the defined model providers, the model names will be validated against
|
|
127
137
|
the set of valid model names. For the undefined model providers, the model name will not be validated.
|
|
@@ -137,11 +147,6 @@ class ModelId(BaseModel):
|
|
|
137
147
|
"""Convert the ModelId object to a string.
|
|
138
148
|
|
|
139
149
|
Returns:
|
|
140
|
-
str: The string representation of the ModelId object. The format is
|
|
141
|
-
|
|
142
|
-
2. For `openai-compatible` provider: `openai-compatible/base-url:model-name`.
|
|
143
|
-
3. For `langchain` provider: `langchain/<package>.<class>:model-name`.
|
|
144
|
-
4. For `litellm` provider: `litellm/provider/model-name`.
|
|
145
|
-
5. For `datasaur` provider: `datasaur/base-url`.
|
|
146
|
-
6. For other providers: `provider/model-name`.
|
|
150
|
+
str: The string representation of the ModelId object. The format is defined in the following page:
|
|
151
|
+
https://gdplabs.gitbook.io/sdk/resources/supported-models
|
|
147
152
|
"""
|
|
Binary file
|
gllm_inference.pyi
CHANGED
|
@@ -27,6 +27,7 @@ import gllm_inference.lm_invoker.DatasaurLMInvoker
|
|
|
27
27
|
import gllm_inference.lm_invoker.GoogleLMInvoker
|
|
28
28
|
import gllm_inference.lm_invoker.LangChainLMInvoker
|
|
29
29
|
import gllm_inference.lm_invoker.LiteLLMLMInvoker
|
|
30
|
+
import gllm_inference.lm_invoker.OpenAIChatCompletionsLMInvoker
|
|
30
31
|
import gllm_inference.lm_invoker.OpenAICompatibleLMInvoker
|
|
31
32
|
import gllm_inference.lm_invoker.OpenAILMInvoker
|
|
32
33
|
import gllm_inference.lm_invoker.XAILMInvoker
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: gllm-inference-binary
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.35
|
|
4
4
|
Summary: A library containing components related to model inferences in Gen AI applications.
|
|
5
5
|
Author-email: Henry Wicaksono <henry.wicaksono@gdplabs.id>, Resti Febrina <resti.febrina@gdplabs.id>
|
|
6
6
|
Requires-Python: <3.14,>=3.11
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
gllm_inference.cpython-312-x86_64-linux-gnu.so,sha256=
|
|
2
|
-
gllm_inference.pyi,sha256=
|
|
1
|
+
gllm_inference.cpython-312-x86_64-linux-gnu.so,sha256=coRWd0bJf8pImXcyFaUzK_W-OtoYPxLrFvx1vBpMuJU,4753176
|
|
2
|
+
gllm_inference.pyi,sha256=bOGYhW7SnMMPCLRRlkVbSq8I8xn8YwHssI1zZoD1lVU,4263
|
|
3
3
|
gllm_inference/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
gllm_inference/constants.pyi,sha256=
|
|
4
|
+
gllm_inference/constants.pyi,sha256=uCf0Rc8GkKwUKeMC5wx5WG_x0iV_piKhjZQl1gNffSQ,291
|
|
5
5
|
gllm_inference/builder/__init__.pyi,sha256=usz2lvfwO4Yk-ZGKXbCWG1cEr3nlQXxMNDNC-2yc1NM,500
|
|
6
|
-
gllm_inference/builder/build_em_invoker.pyi,sha256=
|
|
7
|
-
gllm_inference/builder/build_lm_invoker.pyi,sha256=
|
|
8
|
-
gllm_inference/builder/build_lm_request_processor.pyi,sha256=
|
|
6
|
+
gllm_inference/builder/build_em_invoker.pyi,sha256=Qn8nD0XpzbZgps5FcnLIyubKlrWhHJyhy6jU-68u9oc,5628
|
|
7
|
+
gllm_inference/builder/build_lm_invoker.pyi,sha256=3hiIurQ3TC7kEZPflJ6_byCNnEdcd5BEIz07ii4TAzY,7292
|
|
8
|
+
gllm_inference/builder/build_lm_request_processor.pyi,sha256=KbQkcPa8C-yzyelht4mWLP8kDmh17itAT3tn8ZJB6pg,4144
|
|
9
9
|
gllm_inference/builder/build_output_parser.pyi,sha256=_Lrq-bh1oPsb_Nwkkr_zyEUwIOMysRFZkvEtEM29LZM,936
|
|
10
10
|
gllm_inference/catalog/__init__.pyi,sha256=JBkPGTyiiZ30GECzJBW-mW8LekWyY2qyzal3eW7ynaM,287
|
|
11
11
|
gllm_inference/catalog/catalog.pyi,sha256=a4RNG1lKv51GxQpOqh47tz-PAROMPaeP2o5XNLBSZaU,4790
|
|
12
|
-
gllm_inference/catalog/lm_request_processor_catalog.pyi,sha256=
|
|
12
|
+
gllm_inference/catalog/lm_request_processor_catalog.pyi,sha256=WW1j8jWujnatF0c9rCk94CyobtFe3gOky2vjoGCV6nw,5424
|
|
13
13
|
gllm_inference/catalog/prompt_builder_catalog.pyi,sha256=OU8k_4HbqjZEzHZlzSM3uzGQZJmM2uGD76Csqom0CEQ,3197
|
|
14
14
|
gllm_inference/em_invoker/__init__.pyi,sha256=83QVCkMjS2-jMKdAvmZska4LuJ-un755lAxjuVSLZ9o,987
|
|
15
15
|
gllm_inference/em_invoker/azure_openai_em_invoker.pyi,sha256=Tp92kRqUmB2FpqdnWdJXDGZ_ibOzgFeZAEey4coaD5E,4933
|
|
@@ -17,8 +17,8 @@ gllm_inference/em_invoker/bedrock_em_invoker.pyi,sha256=77omAUXnGU_62KPC5sKOnWTw
|
|
|
17
17
|
gllm_inference/em_invoker/em_invoker.pyi,sha256=KGjLiAWGIA3ziV50zMwSzx6lTVUbYspQCl4LFxqbDlY,5101
|
|
18
18
|
gllm_inference/em_invoker/google_em_invoker.pyi,sha256=VVpizDo47kznqRk07t6e-Lp_K6Ojfn5KDkIKoqn2boE,6822
|
|
19
19
|
gllm_inference/em_invoker/langchain_em_invoker.pyi,sha256=BhZjkYZoxQXPJjP0PgA8W0xrtwiqDkW5E6NpGit0h1E,3498
|
|
20
|
-
gllm_inference/em_invoker/openai_compatible_em_invoker.pyi,sha256=
|
|
21
|
-
gllm_inference/em_invoker/openai_em_invoker.pyi,sha256=
|
|
20
|
+
gllm_inference/em_invoker/openai_compatible_em_invoker.pyi,sha256=WMJTEYdkRh5Mro8hcnZ1TIrL6rXk7bDYmsKzjGU8wwA,2848
|
|
21
|
+
gllm_inference/em_invoker/openai_em_invoker.pyi,sha256=m7zhI75nXXa9OwZSSnt59Aoy-V2KuApUI2EESm1Puqk,6162
|
|
22
22
|
gllm_inference/em_invoker/twelevelabs_em_invoker.pyi,sha256=9F37VuLYTH5xsPSS_uzhrsPJug0QifX_qh2GwG0jSTU,5345
|
|
23
23
|
gllm_inference/em_invoker/voyage_em_invoker.pyi,sha256=zJZqMvvFKu3sHdrNM773UYjfHVlnwE2w2BmvdFcHzV0,5515
|
|
24
24
|
gllm_inference/em_invoker/langchain/__init__.pyi,sha256=VYGKE5OgU0my1RlhgzkU_A7-GLGnUDDnNFuctuRwILE,148
|
|
@@ -35,17 +35,18 @@ gllm_inference/exceptions/__init__.pyi,sha256=Upcuj7od2lkbdueQ0iMT2ktFYYi-KKTynT
|
|
|
35
35
|
gllm_inference/exceptions/error_parser.pyi,sha256=IOfa--NpLUW5E9Qq0mwWi6ZpTAbUyyNe6iAqunBNGLI,1999
|
|
36
36
|
gllm_inference/exceptions/exceptions.pyi,sha256=Bv996qLa_vju0Qjf4GewMxdkq8CV9LRZb0S6289DldA,5725
|
|
37
37
|
gllm_inference/exceptions/provider_error_map.pyi,sha256=P1WnhWkM103FW6hqMfNZBOmYSWOmsJtll3VQV8DGb8E,1210
|
|
38
|
-
gllm_inference/lm_invoker/__init__.pyi,sha256=
|
|
38
|
+
gllm_inference/lm_invoker/__init__.pyi,sha256=IGF3h8Z7Yr0bLrkDMRTDVPNBU6Y3liJabW3acjstJDY,1374
|
|
39
39
|
gllm_inference/lm_invoker/anthropic_lm_invoker.pyi,sha256=rJeQ9jpUIvcf5z1BB9Lksqf37ZgUzcnFqDMstOl3-kk,17235
|
|
40
40
|
gllm_inference/lm_invoker/azure_openai_lm_invoker.pyi,sha256=7zF8pj3LbuOwu1QArPX0ra6IrqUq5AkkGbC_wXiGhlA,15027
|
|
41
41
|
gllm_inference/lm_invoker/bedrock_lm_invoker.pyi,sha256=uZ9wpzOKSOvgu1ICMLqEXcrOE3RIbUmqHmgtuwBekPg,12802
|
|
42
42
|
gllm_inference/lm_invoker/datasaur_lm_invoker.pyi,sha256=J_tfnIgVDr-zQ7YE5_TKMyZyA336ly04g1l-ZKnr1As,9315
|
|
43
43
|
gllm_inference/lm_invoker/google_lm_invoker.pyi,sha256=4-3CwfBcDh6thxkidRcYbGVp9bCDkQTemat6VBHsUC8,17164
|
|
44
|
-
gllm_inference/lm_invoker/langchain_lm_invoker.pyi,sha256=
|
|
45
|
-
gllm_inference/lm_invoker/litellm_lm_invoker.pyi,sha256=
|
|
44
|
+
gllm_inference/lm_invoker/langchain_lm_invoker.pyi,sha256=Bxi9hT4-sIZTz-VhAlxd5JyjAjQZQbUq2xtGhUL6oIs,13705
|
|
45
|
+
gllm_inference/lm_invoker/litellm_lm_invoker.pyi,sha256=5dEgqLvMB04W30PO2MEUJ4h7rEMmM7ETdQ7LOlLpeXg,13238
|
|
46
46
|
gllm_inference/lm_invoker/lm_invoker.pyi,sha256=hjolpN8BzUrhgy8MSpnYxhrlWPJO1LXeCFGlBhQ-eBw,8152
|
|
47
|
-
gllm_inference/lm_invoker/
|
|
48
|
-
gllm_inference/lm_invoker/
|
|
47
|
+
gllm_inference/lm_invoker/openai_chat_completions_lm_invoker.pyi,sha256=IPx3HXbvEti0LIXBEq1ZPUk6FChVtzBpmISslC9F_Qo,15736
|
|
48
|
+
gllm_inference/lm_invoker/openai_compatible_lm_invoker.pyi,sha256=PFOqWhLGHFcoZROW-yreldVaZjHKTzPhuZY2ELM6_SY,3837
|
|
49
|
+
gllm_inference/lm_invoker/openai_lm_invoker.pyi,sha256=oqd50KXEScC3HnS14UhcmPDBgFqL7fw6p1OqGloyxEs,23627
|
|
49
50
|
gllm_inference/lm_invoker/xai_lm_invoker.pyi,sha256=rV8D3E730OUmwK7jELKSziMUl7MnpbfxMAvMuq8-Aew,15687
|
|
50
51
|
gllm_inference/lm_invoker/batch/__init__.pyi,sha256=W4W-_yfk7lL20alREJai6GnwuQvdlKRfwQCX4mQK4XI,127
|
|
51
52
|
gllm_inference/lm_invoker/batch/batch_operations.pyi,sha256=Oo7hoyPSfPZdy1mXvSdvtRndvq-XTIbPIjEoGvJj5C0,5372
|
|
@@ -56,7 +57,7 @@ gllm_inference/lm_invoker/schema/datasaur.pyi,sha256=aA4DhTXIezwLvFzphR24a5ueVln
|
|
|
56
57
|
gllm_inference/lm_invoker/schema/google.pyi,sha256=AIsNgq0ZZuicHmx4bL7z6q-946T05nWts3HUeA8hhHQ,505
|
|
57
58
|
gllm_inference/lm_invoker/schema/langchain.pyi,sha256=rZcIxuvABI4pKfyVvkRBRqfJJogZ67EFPydpubHt49c,429
|
|
58
59
|
gllm_inference/lm_invoker/schema/openai.pyi,sha256=oju4itbH6mm-yMCqX3m-448XJra4cg6oHHq7abYGM_g,2187
|
|
59
|
-
gllm_inference/lm_invoker/schema/
|
|
60
|
+
gllm_inference/lm_invoker/schema/openai_chat_completions.pyi,sha256=RyULzoGmIHuPwIwlSCg6dFdAYrHhZ0OttNxP2TCMWY8,1164
|
|
60
61
|
gllm_inference/lm_invoker/schema/xai.pyi,sha256=cWnbJmDtllqRH3NXpQbiXgkNBcUXr8ksDSDywcgJebE,632
|
|
61
62
|
gllm_inference/model/__init__.pyi,sha256=qClHIgljqhPPCKlGTKmHsWgYb4_hADybxtC2q1U8a5Q,593
|
|
62
63
|
gllm_inference/model/em/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -94,7 +95,7 @@ gllm_inference/schema/lm_input.pyi,sha256=A5pjz1id6tP9XRNhzQrbmzd66C_q3gzo0UP8rC
|
|
|
94
95
|
gllm_inference/schema/lm_output.pyi,sha256=15y-M0lpqM_fSlErPKiN1Pj-ikl5NtFBcWLMYsRidt8,2182
|
|
95
96
|
gllm_inference/schema/mcp.pyi,sha256=Vwu8E2BDl6FvvnI42gIyY3Oki1BdwRE3Uh3aV0rmhQU,1014
|
|
96
97
|
gllm_inference/schema/message.pyi,sha256=VP9YppKj2mo1esl9cy6qQO9m2mMHUjTmfGDdyUor880,2220
|
|
97
|
-
gllm_inference/schema/model_id.pyi,sha256=
|
|
98
|
+
gllm_inference/schema/model_id.pyi,sha256=y61SGPXHvQDGA9krg29pX58EE8HwLrb6XEKNo1ZNGVE,5256
|
|
98
99
|
gllm_inference/schema/reasoning.pyi,sha256=SlTuiDw87GdnAn-I6YOPIJRhEBiwQljM46JohG05guQ,562
|
|
99
100
|
gllm_inference/schema/token_usage.pyi,sha256=1GTQVORV0dBNmD_jix8aVaUqxMKFF04KpLP7y2urqbk,2950
|
|
100
101
|
gllm_inference/schema/tool_call.pyi,sha256=zQaVxCnkVxOfOEhBidqohU85gb4PRwnwBiygKaunamk,389
|
|
@@ -105,7 +106,7 @@ gllm_inference/utils/io_utils.pyi,sha256=7kUTacHAVRYoemFUOjCH7-Qmw-YsQGd6rGYxjf_
|
|
|
105
106
|
gllm_inference/utils/langchain.pyi,sha256=VluQiHkGigDdqLUbhB6vnXiISCP5hHqV0qokYY6dC1A,1164
|
|
106
107
|
gllm_inference/utils/validation.pyi,sha256=toxBtRp-VItC_X7sNi-GDd7sjibBdWMrR0q01OI2D7k,385
|
|
107
108
|
gllm_inference.build/.gitignore,sha256=aEiIwOuxfzdCmLZe4oB1JsBmCUxwG8x-u-HBCV9JT8E,1
|
|
108
|
-
gllm_inference_binary-0.5.
|
|
109
|
-
gllm_inference_binary-0.5.
|
|
110
|
-
gllm_inference_binary-0.5.
|
|
111
|
-
gllm_inference_binary-0.5.
|
|
109
|
+
gllm_inference_binary-0.5.35.dist-info/METADATA,sha256=JtNz8vJg6sEu2MkCc6uZEmk7c3m5dGQADzei_1sq7E0,5636
|
|
110
|
+
gllm_inference_binary-0.5.35.dist-info/WHEEL,sha256=nvMz4aD6kW281G6ZJCbqAgYrkKc1h4b3not015Wcvhc,108
|
|
111
|
+
gllm_inference_binary-0.5.35.dist-info/top_level.txt,sha256=FpOjtN80F-qVNgbScXSEyqa0w09FYn6301iq6qt69IQ,15
|
|
112
|
+
gllm_inference_binary-0.5.35.dist-info/RECORD,,
|
|
File without changes
|
{gllm_inference_binary-0.5.34.dist-info → gllm_inference_binary-0.5.35.dist-info}/top_level.txt
RENAMED
|
File without changes
|