gllm-inference-binary 0.4.60__cp312-cp312-manylinux_2_31_x86_64.whl → 0.5.6__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_lm_request_processor.pyi +7 -6
- gllm_inference/catalog/catalog.pyi +34 -38
- gllm_inference/catalog/lm_request_processor_catalog.pyi +51 -42
- gllm_inference/catalog/prompt_builder_catalog.pyi +27 -42
- gllm_inference/constants.pyi +1 -3
- gllm_inference/em_invoker/__init__.pyi +1 -4
- gllm_inference/em_invoker/azure_openai_em_invoker.pyi +1 -1
- gllm_inference/em_invoker/em_invoker.pyi +7 -26
- gllm_inference/em_invoker/google_em_invoker.pyi +2 -2
- gllm_inference/em_invoker/langchain/__init__.pyi +1 -2
- gllm_inference/em_invoker/langchain_em_invoker.pyi +3 -13
- gllm_inference/em_invoker/openai_compatible_em_invoker.pyi +1 -1
- gllm_inference/em_invoker/openai_em_invoker.pyi +2 -2
- gllm_inference/em_invoker/twelevelabs_em_invoker.pyi +3 -19
- gllm_inference/em_invoker/voyage_em_invoker.pyi +3 -6
- gllm_inference/lm_invoker/__init__.pyi +1 -4
- gllm_inference/lm_invoker/anthropic_lm_invoker.pyi +8 -30
- gllm_inference/lm_invoker/azure_openai_lm_invoker.pyi +6 -19
- gllm_inference/lm_invoker/bedrock_lm_invoker.pyi +7 -15
- gllm_inference/lm_invoker/datasaur_lm_invoker.pyi +8 -15
- gllm_inference/lm_invoker/google_lm_invoker.pyi +8 -22
- gllm_inference/lm_invoker/langchain_lm_invoker.pyi +9 -22
- gllm_inference/lm_invoker/litellm_lm_invoker.pyi +7 -14
- gllm_inference/lm_invoker/lm_invoker.pyi +18 -19
- gllm_inference/lm_invoker/openai_compatible_lm_invoker.pyi +12 -25
- gllm_inference/lm_invoker/openai_lm_invoker.pyi +19 -25
- gllm_inference/lm_invoker/schema/datasaur.pyi +2 -0
- gllm_inference/prompt_builder/__init__.pyi +1 -6
- gllm_inference/prompt_builder/prompt_builder.pyi +17 -107
- gllm_inference/prompt_formatter/agnostic_prompt_formatter.pyi +4 -4
- gllm_inference/prompt_formatter/huggingface_prompt_formatter.pyi +4 -4
- gllm_inference/prompt_formatter/llama_prompt_formatter.pyi +3 -3
- gllm_inference/prompt_formatter/mistral_prompt_formatter.pyi +3 -3
- gllm_inference/prompt_formatter/openai_prompt_formatter.pyi +4 -4
- gllm_inference/prompt_formatter/prompt_formatter.pyi +4 -4
- gllm_inference/request_processor/lm_request_processor.pyi +12 -25
- gllm_inference/request_processor/uses_lm_mixin.pyi +4 -10
- gllm_inference/schema/__init__.pyi +11 -4
- gllm_inference/schema/attachment.pyi +88 -0
- gllm_inference/schema/code_exec_result.pyi +14 -0
- gllm_inference/schema/enums.pyi +9 -9
- gllm_inference/schema/lm_output.pyi +36 -0
- gllm_inference/schema/message.pyi +52 -0
- gllm_inference/schema/model_id.pyi +1 -1
- gllm_inference/schema/reasoning.pyi +15 -0
- gllm_inference/schema/token_usage.pyi +11 -0
- gllm_inference/schema/tool_call.pyi +14 -0
- gllm_inference/schema/tool_result.pyi +11 -0
- gllm_inference/schema/type_alias.pyi +6 -8
- gllm_inference/utils/__init__.pyi +2 -3
- gllm_inference/utils/validation.pyi +12 -0
- gllm_inference.cpython-312-x86_64-linux-gnu.so +0 -0
- gllm_inference.pyi +8 -42
- {gllm_inference_binary-0.4.60.dist-info → gllm_inference_binary-0.5.6.dist-info}/METADATA +2 -9
- gllm_inference_binary-0.5.6.dist-info/RECORD +93 -0
- gllm_inference/builder/model_id.pyi +0 -13
- gllm_inference/catalog/component_map.pyi +0 -8
- gllm_inference/em_invoker/google_generativeai_em_invoker.pyi +0 -32
- gllm_inference/em_invoker/google_vertexai_em_invoker.pyi +0 -34
- gllm_inference/em_invoker/langchain/tei_embeddings.pyi +0 -71
- gllm_inference/em_invoker/tei_em_invoker.pyi +0 -48
- gllm_inference/lm_invoker/google_generativeai_lm_invoker.pyi +0 -51
- gllm_inference/lm_invoker/google_vertexai_lm_invoker.pyi +0 -54
- gllm_inference/lm_invoker/tgi_lm_invoker.pyi +0 -34
- gllm_inference/multimodal_em_invoker/__init__.pyi +0 -4
- gllm_inference/multimodal_em_invoker/google_vertexai_multimodal_em_invoker.pyi +0 -52
- gllm_inference/multimodal_em_invoker/multimodal_em_invoker.pyi +0 -35
- gllm_inference/multimodal_em_invoker/twelvelabs_multimodal_em_invoker.pyi +0 -49
- gllm_inference/multimodal_lm_invoker/__init__.pyi +0 -7
- gllm_inference/multimodal_lm_invoker/anthropic_multimodal_lm_invoker.pyi +0 -44
- gllm_inference/multimodal_lm_invoker/azure_openai_multimodal_lm_invoker.pyi +0 -41
- gllm_inference/multimodal_lm_invoker/google_generativeai_multimodal_lm_invoker.pyi +0 -30
- gllm_inference/multimodal_lm_invoker/google_vertexai_multimodal_lm_invoker.pyi +0 -67
- gllm_inference/multimodal_lm_invoker/multimodal_lm_invoker.pyi +0 -51
- gllm_inference/multimodal_lm_invoker/openai_multimodal_lm_invoker.pyi +0 -43
- gllm_inference/multimodal_prompt_builder/__init__.pyi +0 -3
- gllm_inference/multimodal_prompt_builder/multimodal_prompt_builder.pyi +0 -57
- gllm_inference/prompt_builder/agnostic_prompt_builder.pyi +0 -34
- gllm_inference/prompt_builder/huggingface_prompt_builder.pyi +0 -44
- gllm_inference/prompt_builder/llama_prompt_builder.pyi +0 -41
- gllm_inference/prompt_builder/mistral_prompt_builder.pyi +0 -41
- gllm_inference/prompt_builder/openai_prompt_builder.pyi +0 -35
- gllm_inference/schema/model_io.pyi +0 -178
- gllm_inference/utils/openai_multimodal_lm_helper.pyi +0 -36
- gllm_inference/utils/retry.pyi +0 -4
- gllm_inference/utils/utils.pyi +0 -142
- gllm_inference_binary-0.4.60.dist-info/RECORD +0 -115
- {gllm_inference_binary-0.4.60.dist-info → gllm_inference_binary-0.5.6.dist-info}/WHEEL +0 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
from _typeshed import Incomplete
|
|
2
2
|
from gllm_inference.builder.build_lm_invoker import build_lm_invoker as build_lm_invoker
|
|
3
3
|
from gllm_inference.builder.build_output_parser import build_output_parser as build_output_parser
|
|
4
|
-
from gllm_inference.output_parser.output_parser import BaseOutputParser as BaseOutputParser
|
|
5
4
|
from gllm_inference.prompt_builder import PromptBuilder as PromptBuilder
|
|
6
5
|
from gllm_inference.request_processor.lm_request_processor import LMRequestProcessor as LMRequestProcessor
|
|
7
6
|
from gllm_inference.schema.model_id import ModelId as ModelId
|
|
@@ -9,7 +8,7 @@ from typing import Any
|
|
|
9
8
|
|
|
10
9
|
logger: Incomplete
|
|
11
10
|
|
|
12
|
-
def build_lm_request_processor(model_id: str | ModelId, credentials: str | dict[str, Any] | None = None, config: dict[str, Any] | None = None, system_template: str = '', user_template: str = '',
|
|
11
|
+
def build_lm_request_processor(model_id: str | ModelId, credentials: str | dict[str, Any] | None = None, config: dict[str, Any] | None = None, system_template: str = '', user_template: str = '', key_defaults: dict[str, Any] | None = None, output_parser_type: str = 'none') -> LMRequestProcessor:
|
|
13
12
|
'''Build a language model invoker based on the provided configurations.
|
|
14
13
|
|
|
15
14
|
Args:
|
|
@@ -30,10 +29,11 @@ def build_lm_request_processor(model_id: str | ModelId, credentials: str | dict[
|
|
|
30
29
|
Defaults to an empty string.
|
|
31
30
|
user_template (str): The user prompt template. May contain placeholders enclosed in curly braces `{}`.
|
|
32
31
|
Defaults to an empty string.
|
|
32
|
+
key_defaults (dict[str, str] | None, optional): Default values for the keys in the prompt templates.
|
|
33
|
+
Applied when the corresponding keys are not provided in the runtime input.
|
|
34
|
+
Defaults to None, in which case no default values will be assigned to the keys.
|
|
33
35
|
output_parser_type (str, optional): The type of output parser to use. Supports "json" and "none".
|
|
34
36
|
Defaults to "none".
|
|
35
|
-
output_parser (BaseOutputParser | None, optional): Deprecated parameter to pass an output parser.
|
|
36
|
-
Will be removed in v0.5.0. Defaults to None.
|
|
37
37
|
|
|
38
38
|
Returns:
|
|
39
39
|
LMRequestProcessor: The initialized language model request processor.
|
|
@@ -66,13 +66,14 @@ def build_lm_request_processor(model_id: str | ModelId, credentials: str | dict[
|
|
|
66
66
|
)
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
# With
|
|
69
|
+
# With custom prompt builder configuration
|
|
70
70
|
```python
|
|
71
71
|
lm_request_processor = build_lm_request_processor(
|
|
72
72
|
model_id="openai/gpt-4o-mini",
|
|
73
73
|
credentials="sk-...",
|
|
74
|
-
system_template="Talk like a
|
|
74
|
+
system_template="Talk like a {role}.",
|
|
75
75
|
user_template="{query}",
|
|
76
|
+
key_defaults={"role": "pirate"},
|
|
76
77
|
)
|
|
77
78
|
```
|
|
78
79
|
|
|
@@ -13,46 +13,42 @@ class BaseCatalog(ABC, BaseModel, Generic[T], arbitrary_types_allowed=True, meta
|
|
|
13
13
|
Attributes:
|
|
14
14
|
components (dict[str, T]): A dictionary containing the components.
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
```python
|
|
48
|
-
catalog = BaseCatalog.from_records(
|
|
49
|
-
records=[
|
|
16
|
+
Initialization:
|
|
17
|
+
# Example 1: Load from Google Sheets using client email and private key
|
|
18
|
+
```python
|
|
19
|
+
catalog = BaseCatalog.from_gsheets(
|
|
20
|
+
sheet_id="...",
|
|
21
|
+
worksheet_id="...",
|
|
22
|
+
client_email="...",
|
|
23
|
+
private_key="...",
|
|
24
|
+
)
|
|
25
|
+
component = catalog.name
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
# Example 2: Load from Google Sheets using credential file
|
|
29
|
+
```python
|
|
30
|
+
catalog = BaseCatalog.from_gsheets(
|
|
31
|
+
sheet_id="...",
|
|
32
|
+
worksheet_id="...",
|
|
33
|
+
credential_file_path="...",
|
|
34
|
+
)
|
|
35
|
+
component = catalog.name
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
# Example 3: Load from CSV
|
|
39
|
+
```python
|
|
40
|
+
catalog = BaseCatalog.from_csv(csv_path="...")
|
|
41
|
+
component = catalog.name
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
# Example 4: Load from records
|
|
45
|
+
```python
|
|
46
|
+
records = [
|
|
50
47
|
{"name": "...", "col_1": "...", "col_2": "..."},
|
|
51
48
|
{"name": "...", "col_1": "...", "col_2": "..."},
|
|
52
|
-
]
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
component = catalog.name
|
|
49
|
+
]
|
|
50
|
+
catalog = BaseCatalog.from_records(records=records)
|
|
51
|
+
component = catalog.name
|
|
56
52
|
```
|
|
57
53
|
'''
|
|
58
54
|
components: dict[str, T]
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
from _typeshed import Incomplete
|
|
2
|
-
from gllm_inference.builder import build_lm_request_processor as build_lm_request_processor
|
|
3
|
-
from gllm_inference.catalog.catalog import BaseCatalog as BaseCatalog
|
|
4
|
-
from gllm_inference.catalog.component_map import LM_INVOKER_TYPE_MAP as LM_INVOKER_TYPE_MAP, PROMPT_BUILDER_TYPE_MAP as PROMPT_BUILDER_TYPE_MAP
|
|
5
|
-
from gllm_inference.lm_invoker.lm_invoker import BaseLMInvoker as BaseLMInvoker
|
|
6
|
-
from gllm_inference.multimodal_lm_invoker.multimodal_lm_invoker import BaseMultimodalLMInvoker as BaseMultimodalLMInvoker
|
|
7
|
-
from gllm_inference.multimodal_prompt_builder.multimodal_prompt_builder import MultimodalPromptBuilder as MultimodalPromptBuilder
|
|
8
|
-
from gllm_inference.output_parser.output_parser import BaseOutputParser as BaseOutputParser
|
|
9
|
-
from gllm_inference.prompt_builder.prompt_builder import BasePromptBuilder as BasePromptBuilder, PromptBuilder as PromptBuilder
|
|
2
|
+
from gllm_inference.builder import build_lm_request_processor as build_lm_request_processor
|
|
3
|
+
from gllm_inference.catalog.catalog import BaseCatalog as BaseCatalog
|
|
10
4
|
from gllm_inference.request_processor import LMRequestProcessor as LMRequestProcessor
|
|
11
5
|
|
|
12
6
|
MODEL_ID_ENV_VAR_REGEX_PATTERN: str
|
|
13
7
|
LM_REQUEST_PROCESSOR_REQUIRED_COLUMNS: Incomplete
|
|
14
8
|
CONFIG_SCHEMA_MAP: Incomplete
|
|
9
|
+
logger: Incomplete
|
|
15
10
|
|
|
16
11
|
class LMRequestProcessorCatalog(BaseCatalog[LMRequestProcessor]):
|
|
17
12
|
'''Loads multiple LM request processors from certain sources.
|
|
@@ -52,52 +47,66 @@ class LMRequestProcessorCatalog(BaseCatalog[LMRequestProcessor]):
|
|
|
52
47
|
|
|
53
48
|
# Example 4: Load from record
|
|
54
49
|
```python
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
50
|
+
records=[
|
|
51
|
+
{
|
|
52
|
+
"name": "answer_question",
|
|
53
|
+
"system_template": (
|
|
54
|
+
"You are helpful assistant.\\n"
|
|
55
|
+
"Answer the following question based on the provided context.\\n"
|
|
56
|
+
"```{context}```"
|
|
57
|
+
),
|
|
58
|
+
"user_template": "{query}",
|
|
59
|
+
"key_defaults": \'{"context": "<default context>"}\',
|
|
60
|
+
"model_id": "openai/gpt-4.1-nano",
|
|
61
|
+
"credentials": "OPENAI_API_KEY",
|
|
62
|
+
"config": "",
|
|
63
|
+
"output_parser_type": "none",
|
|
64
|
+
},
|
|
65
|
+
]
|
|
66
|
+
catalog = LMRequestProcessorCatalog.from_records(records=records)
|
|
67
|
+
lm_request_processor = catalog.answer_question
|
|
66
68
|
```
|
|
67
69
|
|
|
68
70
|
Template Format Example:
|
|
69
71
|
# Example 1: Google Sheets
|
|
70
|
-
For an example of how a Google Sheets file can be formatted to be loaded using LMRequestProcessorCatalog,
|
|
71
|
-
|
|
72
|
+
For an example of how a Google Sheets file can be formatted to be loaded using LMRequestProcessorCatalog, see:
|
|
73
|
+
https://docs.google.com/spreadsheets/d/1CX9i45yEinv1UdB3s6uHNMj7mxr2-s1NFHfFDvMsq0E/edit?usp=drive_link
|
|
72
74
|
|
|
73
75
|
# Example 2: CSV
|
|
74
76
|
For an example of how a CSV file can be formatted to be loaded using LMRequestProcessorCatalog, see:
|
|
75
|
-
https://drive.google.com/file/d/
|
|
77
|
+
https://drive.google.com/file/d/1_2rSoxh3CR2KZxIyUmpowMrt0Lm0YqAb/view?usp=drive_link
|
|
76
78
|
|
|
77
79
|
Template Explanation:
|
|
78
80
|
The required columns are:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
1. name (str): The name of the LM request processor.
|
|
82
|
+
2. system_template (str): The system template of the prompt builder.
|
|
83
|
+
3. user_template (str): The user template of the prompt builder.
|
|
84
|
+
4. key_defaults (json_str): The default values for the prompt template keys.
|
|
85
|
+
5. model_id (str): The model ID of the LM invoker.
|
|
86
|
+
6. credentials (str | json_str): The credentials of the LM invoker.
|
|
87
|
+
7. config (json_str): The additional configuration of the LM invoker.
|
|
88
|
+
8. output_parser_type (str): The type of the output parser.
|
|
86
89
|
|
|
87
90
|
Important Notes:
|
|
88
91
|
1. At least one of `system_template` or `user_template` must be filled.
|
|
89
|
-
2.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
2. `key_defaults` is optional. If filled, must be a dictionary containing the default values for the
|
|
93
|
+
prompt template keys. These default values will be applied when the corresponding keys are not provided
|
|
94
|
+
in the runtime input. If it is empty, the prompt template keys will not have default values.
|
|
95
|
+
3. The `model_id`:
|
|
96
|
+
3.1. Must be filled with the model ID of the LM invoker, e.g. "openai/gpt-4.1-nano".
|
|
97
|
+
3.2. Can be partially loaded from the environment variable using the "${ENV_VAR_KEY}" syntax,
|
|
92
98
|
e.g. "azure-openai/${AZURE_ENDPOINT}/${AZURE_DEPLOYMENT}".
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
99
|
+
3.3. For the available model ID formats, see: https://gdplabs.gitbook.io/sdk/resources/supported-models
|
|
100
|
+
4. `credentials` is optional. If it is filled, it can either be:
|
|
101
|
+
4.1. An environment variable name containing the API key (e.g. OPENAI_API_KEY).
|
|
102
|
+
4.2. An environment variable name containing the path to a credentials JSON file
|
|
103
|
+
(e.g. GOOGLE_CREDENTIALS_FILE_PATH). Currently only supported for Google Vertex AI.
|
|
104
|
+
4.3. A dictionary of credentials, with each value being an environment variable name corresponding to the
|
|
105
|
+
credential (e.g. {"api_key": "OPENAI_API_KEY"}). Currently supported for Bedrock and LangChain.
|
|
106
|
+
If it is empty, the LM invoker will use the default credentials loaded from the environment variables.
|
|
107
|
+
5. `config` is optional. If filled, must be a dictionary containing the configuration for the LM invoker.
|
|
108
|
+
If it is empty, the LM invoker will use the default configuration.
|
|
109
|
+
6. `output_parser_type` can either be:
|
|
110
|
+
6.1. none: No output parser will be used.
|
|
111
|
+
6.2. json: The JSONOutputParser will be used.
|
|
103
112
|
'''
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
from _typeshed import Incomplete
|
|
2
|
-
from gllm_inference.catalog.catalog import BaseCatalog as BaseCatalog
|
|
3
|
-
from gllm_inference.
|
|
4
|
-
from gllm_inference.multimodal_prompt_builder import MultimodalPromptBuilder as MultimodalPromptBuilder
|
|
5
|
-
from gllm_inference.prompt_builder.prompt_builder import BasePromptBuilder as BasePromptBuilder, PromptBuilder as PromptBuilder
|
|
2
|
+
from gllm_inference.catalog.catalog import BaseCatalog as BaseCatalog
|
|
3
|
+
from gllm_inference.prompt_builder.prompt_builder import PromptBuilder as PromptBuilder
|
|
6
4
|
|
|
7
|
-
PROMPT_BUILDER_MODEL_PARAM_MAP: Incomplete
|
|
8
5
|
PROMPT_BUILDER_REQUIRED_COLUMNS: Incomplete
|
|
6
|
+
logger: Incomplete
|
|
9
7
|
|
|
10
|
-
class PromptBuilderCatalog(BaseCatalog[
|
|
8
|
+
class PromptBuilderCatalog(BaseCatalog[PromptBuilder]):
|
|
11
9
|
'''Loads multiple prompt builders from certain sources.
|
|
12
10
|
|
|
13
11
|
Attributes:
|
|
14
|
-
components (dict[str,
|
|
15
|
-
Dictionary of the loaded prompt builders.
|
|
12
|
+
components (dict[str, PromptBuilder]): Dictionary of the loaded prompt builders.
|
|
16
13
|
|
|
17
14
|
Initialization:
|
|
18
15
|
# Example 1: Load from Google Sheets using client email and private key
|
|
@@ -23,7 +20,6 @@ class PromptBuilderCatalog(BaseCatalog[BasePromptBuilder | MultimodalPromptBuild
|
|
|
23
20
|
client_email="...",
|
|
24
21
|
private_key="...",
|
|
25
22
|
)
|
|
26
|
-
|
|
27
23
|
prompt_builder = catalog.name
|
|
28
24
|
```
|
|
29
25
|
|
|
@@ -34,42 +30,30 @@ class PromptBuilderCatalog(BaseCatalog[BasePromptBuilder | MultimodalPromptBuild
|
|
|
34
30
|
worksheet_id="...",
|
|
35
31
|
credential_file_path="...",
|
|
36
32
|
)
|
|
37
|
-
|
|
38
33
|
prompt_builder = catalog.name
|
|
39
34
|
```
|
|
40
35
|
|
|
41
36
|
# Example 3: Load from CSV
|
|
42
37
|
```python
|
|
43
38
|
catalog = PromptBuilderCatalog.from_csv(csv_path="...")
|
|
44
|
-
|
|
45
39
|
prompt_builder = catalog.name
|
|
46
40
|
```
|
|
47
41
|
|
|
48
42
|
# Example 4: Load from records
|
|
49
43
|
```python
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"name": "draft_document",
|
|
64
|
-
"system": (
|
|
65
|
-
"You are an AI expert.\\nDraft a document following the provided format and context.\\n\\n"
|
|
66
|
-
"Format:\\n```{format}```\\n\\nContext:\\n```{context}```"
|
|
67
|
-
),
|
|
68
|
-
"user": "User instruction:\\n{query}"
|
|
69
|
-
},
|
|
70
|
-
]
|
|
71
|
-
)
|
|
72
|
-
|
|
44
|
+
records=[
|
|
45
|
+
{
|
|
46
|
+
"name": "answer_question",
|
|
47
|
+
"system": (
|
|
48
|
+
"You are helpful assistant.\\n"
|
|
49
|
+
"Answer the following question based on the provided context.\\n"
|
|
50
|
+
"```{context}```"
|
|
51
|
+
),
|
|
52
|
+
"user": "{query}",
|
|
53
|
+
"key_defaults": \'{"context": "<default context>"}\',
|
|
54
|
+
},
|
|
55
|
+
]
|
|
56
|
+
catalog = PromptBuilderCatalog.from_records(records=records)
|
|
73
57
|
prompt_builder = catalog.answer_question
|
|
74
58
|
```
|
|
75
59
|
|
|
@@ -80,18 +64,19 @@ class PromptBuilderCatalog(BaseCatalog[BasePromptBuilder | MultimodalPromptBuild
|
|
|
80
64
|
|
|
81
65
|
# Example 2: CSV
|
|
82
66
|
For an example of how a CSV file can be formatted to be loaded using PromptBuilderCatalog, see:
|
|
83
|
-
https://drive.google.com/file/d/
|
|
67
|
+
https://drive.google.com/file/d/1KQgddMdbcZBZmroQFtjSl-TKLohq84Fz/view?usp=drive_link
|
|
84
68
|
|
|
85
69
|
|
|
86
70
|
Template explanation:
|
|
87
71
|
The required columns are:
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
72
|
+
1. name (str): The name of the prompt builder.
|
|
73
|
+
2. system (str): The system template of the prompt builder.
|
|
74
|
+
3. user (str): The user template of the prompt builder.
|
|
75
|
+
4. key_defaults (json_str): The default values for the prompt template keys.
|
|
91
76
|
|
|
92
77
|
Important Notes:
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
78
|
+
1. At least one of the `system` and `user` columns must be filled.
|
|
79
|
+
2. `key_defaults` is optional. If filled, must be a dictionary containing the default values for the
|
|
80
|
+
prompt template keys. These default values will be applied when the corresponding keys are not provided
|
|
81
|
+
in the runtime input. If it is empty, the prompt template keys will not have default values.
|
|
97
82
|
'''
|
gllm_inference/constants.pyi
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
from _typeshed import Incomplete
|
|
2
2
|
|
|
3
|
-
ALL_EXTENSIONS: str
|
|
4
3
|
DEFAULT_AZURE_OPENAI_API_VERSION: str
|
|
5
4
|
DOCUMENT_MIME_TYPES: Incomplete
|
|
6
5
|
GOOGLE_SCOPES: Incomplete
|
|
6
|
+
INVOKER_DEFAULT_TIMEOUT: float
|
|
7
7
|
HEX_REPR_LENGTH: int
|
|
8
|
-
MESSAGE_TUPLE_LENGTH: int
|
|
9
|
-
DEFAULT_CONTENT_PLACEHOLDER_TYPE: str
|
|
10
8
|
HTTP_STATUS_CODE_PATTERNS: Incomplete
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
from gllm_inference.em_invoker.azure_openai_em_invoker import AzureOpenAIEMInvoker as AzureOpenAIEMInvoker
|
|
2
2
|
from gllm_inference.em_invoker.google_em_invoker import GoogleEMInvoker as GoogleEMInvoker
|
|
3
|
-
from gllm_inference.em_invoker.google_generativeai_em_invoker import GoogleGenerativeAIEMInvoker as GoogleGenerativeAIEMInvoker
|
|
4
|
-
from gllm_inference.em_invoker.google_vertexai_em_invoker import GoogleVertexAIEMInvoker as GoogleVertexAIEMInvoker
|
|
5
3
|
from gllm_inference.em_invoker.langchain_em_invoker import LangChainEMInvoker as LangChainEMInvoker
|
|
6
4
|
from gllm_inference.em_invoker.openai_compatible_em_invoker import OpenAICompatibleEMInvoker as OpenAICompatibleEMInvoker
|
|
7
5
|
from gllm_inference.em_invoker.openai_em_invoker import OpenAIEMInvoker as OpenAIEMInvoker
|
|
8
|
-
from gllm_inference.em_invoker.tei_em_invoker import TEIEMInvoker as TEIEMInvoker
|
|
9
6
|
from gllm_inference.em_invoker.twelevelabs_em_invoker import TwelveLabsEMInvoker as TwelveLabsEMInvoker
|
|
10
7
|
from gllm_inference.em_invoker.voyage_em_invoker import VoyageEMInvoker as VoyageEMInvoker
|
|
11
8
|
|
|
12
|
-
__all__ = ['AzureOpenAIEMInvoker', 'GoogleEMInvoker', '
|
|
9
|
+
__all__ = ['AzureOpenAIEMInvoker', 'GoogleEMInvoker', 'LangChainEMInvoker', 'OpenAIEMInvoker', 'OpenAICompatibleEMInvoker', 'TwelveLabsEMInvoker', 'VoyageEMInvoker']
|
|
@@ -81,5 +81,5 @@ class AzureOpenAIEMInvoker(OpenAIEMInvoker):
|
|
|
81
81
|
default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
|
|
82
82
|
Defaults to None.
|
|
83
83
|
retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
|
|
84
|
-
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout
|
|
84
|
+
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
85
85
|
"""
|
|
@@ -2,14 +2,11 @@ import abc
|
|
|
2
2
|
from _typeshed import Incomplete
|
|
3
3
|
from abc import ABC
|
|
4
4
|
from gllm_core.utils.retry import RetryConfig
|
|
5
|
-
from gllm_inference.constants import
|
|
5
|
+
from gllm_inference.constants import DOCUMENT_MIME_TYPES as DOCUMENT_MIME_TYPES, INVOKER_DEFAULT_TIMEOUT as INVOKER_DEFAULT_TIMEOUT
|
|
6
6
|
from gllm_inference.exceptions import parse_error_message as parse_error_message
|
|
7
7
|
from gllm_inference.schema import Attachment as Attachment, AttachmentType as AttachmentType, EMContent as EMContent, ModelId as ModelId, Vector as Vector
|
|
8
|
-
from langchain_core.embeddings import Embeddings as Embeddings
|
|
9
8
|
from typing import Any
|
|
10
9
|
|
|
11
|
-
DEPRECATED_DETAILS: str
|
|
12
|
-
|
|
13
10
|
class BaseEMInvoker(ABC, metaclass=abc.ABCMeta):
|
|
14
11
|
"""A base class for embedding model invokers used in Gen AI applications.
|
|
15
12
|
|
|
@@ -24,22 +21,18 @@ class BaseEMInvoker(ABC, metaclass=abc.ABCMeta):
|
|
|
24
21
|
"""
|
|
25
22
|
default_hyperparameters: Incomplete
|
|
26
23
|
retry_config: Incomplete
|
|
27
|
-
def __init__(self, model_id: ModelId, default_hyperparameters: dict[str, Any] | None = None,
|
|
28
|
-
|
|
24
|
+
def __init__(self, model_id: ModelId, default_hyperparameters: dict[str, Any] | None = None, supported_attachments: set[str] | None = None, retry_config: RetryConfig | None = None) -> None:
|
|
25
|
+
"""Initializes a new instance of the BaseEMInvoker class.
|
|
29
26
|
|
|
30
27
|
Args:
|
|
31
28
|
model_id (ModelId): The model ID of the embedding model.
|
|
32
29
|
default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the
|
|
33
30
|
embedding model. Defaults to None, in which case an empty dictionary is used.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
the set of valid file extensions for the corresponding mime type. Defaults to None, in which case an
|
|
37
|
-
empty dictionary is used.
|
|
31
|
+
supported_attachments (set[str] | None, optional): A set of supported attachment types. Defaults to None,
|
|
32
|
+
in which case an empty set is used (indicating that no attachments are supported).
|
|
38
33
|
retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
|
|
39
|
-
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout
|
|
40
|
-
|
|
41
|
-
embedding model. Defaults to None.
|
|
42
|
-
'''
|
|
34
|
+
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
35
|
+
"""
|
|
43
36
|
@property
|
|
44
37
|
def model_id(self) -> str:
|
|
45
38
|
"""The model ID of the embedding model.
|
|
@@ -88,15 +81,3 @@ class BaseEMInvoker(ABC, metaclass=abc.ABCMeta):
|
|
|
88
81
|
TimeoutError: If the invocation times out.
|
|
89
82
|
ValueError: If the input content is invalid.
|
|
90
83
|
"""
|
|
91
|
-
def to_langchain(self) -> Embeddings:
|
|
92
|
-
"""Converts the current embedding model invoker to an instance of LangChain `Embeddings` object.
|
|
93
|
-
|
|
94
|
-
This method converts the EM invoker to an instance of LangChain's `Embeddings` object.
|
|
95
|
-
This method requires the appropriate `langchain-<provider>` package to be installed.
|
|
96
|
-
|
|
97
|
-
Returns:
|
|
98
|
-
Embeddings: An instance of LangChain `Embeddings` object.
|
|
99
|
-
|
|
100
|
-
Raises:
|
|
101
|
-
ValueError: If `langchain_module_name` or `langchain_class_name` is missing.
|
|
102
|
-
"""
|
|
@@ -5,7 +5,7 @@ from gllm_inference.em_invoker.em_invoker import BaseEMInvoker as BaseEMInvoker
|
|
|
5
5
|
from gllm_inference.schema import ModelId as ModelId, ModelProvider as ModelProvider, Vector as Vector
|
|
6
6
|
from typing import Any
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
SUPPORTED_ATTACHMENTS: Incomplete
|
|
9
9
|
|
|
10
10
|
class GoogleEMInvoker(BaseEMInvoker):
|
|
11
11
|
'''An embedding model invoker to interact with Google embedding models.
|
|
@@ -115,7 +115,7 @@ class GoogleEMInvoker(BaseEMInvoker):
|
|
|
115
115
|
default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
|
|
116
116
|
Defaults to None.
|
|
117
117
|
retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
|
|
118
|
-
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout
|
|
118
|
+
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
119
119
|
|
|
120
120
|
Note:
|
|
121
121
|
If neither `api_key` nor `credentials_path` is provided, Google Gen AI will be used by default.
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
from gllm_inference.em_invoker.langchain.em_invoker_embeddings import EMInvokerEmbeddings as EMInvokerEmbeddings
|
|
2
|
-
from gllm_inference.em_invoker.langchain.tei_embeddings import TEIEmbeddings as TEIEmbeddings
|
|
3
2
|
|
|
4
|
-
__all__ = ['EMInvokerEmbeddings'
|
|
3
|
+
__all__ = ['EMInvokerEmbeddings']
|
|
@@ -6,7 +6,7 @@ from gllm_inference.utils import load_langchain_model as load_langchain_model, p
|
|
|
6
6
|
from langchain_core.embeddings import Embeddings as Embeddings
|
|
7
7
|
from typing import Any
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
SUPPORTED_ATTACHMENTS: Incomplete
|
|
10
10
|
|
|
11
11
|
class LangChainEMInvoker(BaseEMInvoker):
|
|
12
12
|
"""A language model invoker to interact with LangChain's Embeddings.
|
|
@@ -19,7 +19,7 @@ class LangChainEMInvoker(BaseEMInvoker):
|
|
|
19
19
|
retry_config (RetryConfig): The retry configuration for the embedding model.
|
|
20
20
|
"""
|
|
21
21
|
model: Incomplete
|
|
22
|
-
def __init__(self, model: Embeddings | None = None, model_class_path: str | None = None, model_name: str | None = None, model_kwargs: dict[str, Any] | None = None, default_hyperparameters: dict[str, Any] | None = None, retry_config: RetryConfig | None = None
|
|
22
|
+
def __init__(self, model: Embeddings | None = None, model_class_path: str | None = None, model_name: str | None = None, model_kwargs: dict[str, Any] | None = None, default_hyperparameters: dict[str, Any] | None = None, retry_config: RetryConfig | None = None) -> None:
|
|
23
23
|
'''Initializes a new instance of the LangChainEMInvoker class.
|
|
24
24
|
|
|
25
25
|
Args:
|
|
@@ -35,15 +35,5 @@ class LangChainEMInvoker(BaseEMInvoker):
|
|
|
35
35
|
default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
|
|
36
36
|
Defaults to None.
|
|
37
37
|
retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
|
|
38
|
-
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout
|
|
39
|
-
em (Embeddings | None, optional): Deprecated parameter to pass the LangChain\'s Embeddings instance.
|
|
40
|
-
Equivalent to the `model` parameter. Retained for backward compatibility. Defaults to None.
|
|
38
|
+
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
41
39
|
'''
|
|
42
|
-
def to_langchain(self) -> Embeddings:
|
|
43
|
-
"""Converts the current embedding model invoker to an instance of LangChain `Embeddings` object.
|
|
44
|
-
|
|
45
|
-
This method converts the EM invoker to an instance of LangChain's `Embeddings` object.
|
|
46
|
-
|
|
47
|
-
Returns:
|
|
48
|
-
Embeddings: An instance of LangChain `Embeddings` object.
|
|
49
|
-
"""
|
|
@@ -86,5 +86,5 @@ class OpenAICompatibleEMInvoker(OpenAIEMInvoker):
|
|
|
86
86
|
default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
|
|
87
87
|
Defaults to None.
|
|
88
88
|
retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
|
|
89
|
-
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout
|
|
89
|
+
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
90
90
|
"""
|
|
@@ -4,7 +4,7 @@ from gllm_inference.em_invoker.em_invoker import BaseEMInvoker as BaseEMInvoker
|
|
|
4
4
|
from gllm_inference.schema import ModelId as ModelId, ModelProvider as ModelProvider, Vector as Vector
|
|
5
5
|
from typing import Any
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
SUPPORTED_ATTACHMENTS: Incomplete
|
|
8
8
|
|
|
9
9
|
class OpenAIEMInvoker(BaseEMInvoker):
|
|
10
10
|
'''An embedding model invoker to interact with OpenAI embedding models.
|
|
@@ -80,5 +80,5 @@ class OpenAIEMInvoker(BaseEMInvoker):
|
|
|
80
80
|
default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
|
|
81
81
|
Defaults to None.
|
|
82
82
|
retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
|
|
83
|
-
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout
|
|
83
|
+
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
84
84
|
"""
|
|
@@ -3,10 +3,9 @@ from gllm_core.utils.retry import RetryConfig as RetryConfig
|
|
|
3
3
|
from gllm_inference.em_invoker.em_invoker import BaseEMInvoker as BaseEMInvoker
|
|
4
4
|
from gllm_inference.em_invoker.schema.twelvelabs import InputType as InputType, Key as Key, OutputType as OutputType
|
|
5
5
|
from gllm_inference.schema import Attachment as Attachment, AttachmentType as AttachmentType, EMContent as EMContent, ModelId as ModelId, ModelProvider as ModelProvider, Vector as Vector
|
|
6
|
-
from langchain_core.embeddings import Embeddings as Embeddings
|
|
7
6
|
from typing import Any
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
SUPPORTED_ATTACHMENTS: Incomplete
|
|
10
9
|
|
|
11
10
|
class TwelveLabsEMInvoker(BaseEMInvoker):
|
|
12
11
|
'''An embedding model invoker to interact with TwelveLabs embedding models.
|
|
@@ -20,10 +19,7 @@ class TwelveLabsEMInvoker(BaseEMInvoker):
|
|
|
20
19
|
retry_config (RetryConfig): The retry configuration for the embedding model.
|
|
21
20
|
|
|
22
21
|
Input types:
|
|
23
|
-
The `TwelveLabsEMInvoker` supports the following input types:
|
|
24
|
-
1. Text.
|
|
25
|
-
2. Audio: ".mp3", ".wav", and ".flac".
|
|
26
|
-
3. Image: ".png", ".jpeg", and ".jpg".
|
|
22
|
+
The `TwelveLabsEMInvoker` supports the following input types: text, audio, and image.
|
|
27
23
|
Non-text inputs must be passed as a `Attachment` object.
|
|
28
24
|
|
|
29
25
|
Output format:
|
|
@@ -98,17 +94,5 @@ class TwelveLabsEMInvoker(BaseEMInvoker):
|
|
|
98
94
|
default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
|
|
99
95
|
Defaults to None.
|
|
100
96
|
retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
|
|
101
|
-
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout
|
|
102
|
-
"""
|
|
103
|
-
def to_langchain(self) -> Embeddings:
|
|
104
|
-
"""Converts the current embedding model invoker to an instance of LangChain `Embeddings` object.
|
|
105
|
-
|
|
106
|
-
This method converts the EM invoker to an instance of LangChain's `Embeddings` object.
|
|
107
|
-
However, the TwelveLabsEMInvoker is not supported by LangChain.
|
|
108
|
-
|
|
109
|
-
Returns:
|
|
110
|
-
Embeddings: An instance of LangChain `Embeddings` object.
|
|
111
|
-
|
|
112
|
-
Raises:
|
|
113
|
-
NotImplementedError: The TwelveLabsEMInvoker is not supported by LangChain.
|
|
97
|
+
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
114
98
|
"""
|
|
@@ -5,7 +5,7 @@ from gllm_inference.em_invoker.schema.voyage import InputType as InputType, Key
|
|
|
5
5
|
from gllm_inference.schema import Attachment as Attachment, AttachmentType as AttachmentType, EMContent as EMContent, ModelId as ModelId, ModelProvider as ModelProvider, Vector as Vector
|
|
6
6
|
from typing import Any
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
SUPPORTED_ATTACHMENTS: Incomplete
|
|
9
9
|
MAX_PYTHON_MINOR_VERSION: int
|
|
10
10
|
|
|
11
11
|
class VoyageEMInvoker(BaseEMInvoker):
|
|
@@ -20,10 +20,7 @@ class VoyageEMInvoker(BaseEMInvoker):
|
|
|
20
20
|
retry_config (RetryConfig): The retry configuration for the embedding model.
|
|
21
21
|
|
|
22
22
|
Input types:
|
|
23
|
-
The `VoyageEMInvoker` supports the following input types:
|
|
24
|
-
1. Text.
|
|
25
|
-
2. Image: ".png", ".jpeg", and ".jpg".
|
|
26
|
-
3. A tuple containing text and image.
|
|
23
|
+
The `VoyageEMInvoker` supports the following input types: text, image, and a tuple containing text and image.
|
|
27
24
|
Non-text inputs must be passed as a `Attachment` object.
|
|
28
25
|
|
|
29
26
|
Output format:
|
|
@@ -99,5 +96,5 @@ class VoyageEMInvoker(BaseEMInvoker):
|
|
|
99
96
|
default_hyperparameters (dict[str, Any] | None, optional): Default hyperparameters for invoking the model.
|
|
100
97
|
Defaults to None.
|
|
101
98
|
retry_config (RetryConfig | None, optional): The retry configuration for the embedding model.
|
|
102
|
-
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout
|
|
99
|
+
Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used.
|
|
103
100
|
"""
|