gllm-inference-binary 0.4.62__cp313-cp313-win_amd64.whl → 0.5.1__cp313-cp313-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gllm_inference/builder/build_lm_request_processor.pyi +1 -4
- gllm_inference/catalog/catalog.pyi +34 -38
- gllm_inference/catalog/lm_request_processor_catalog.pyi +4 -10
- gllm_inference/catalog/prompt_builder_catalog.pyi +25 -37
- gllm_inference/constants.pyi +0 -3
- gllm_inference/em_invoker/__init__.pyi +1 -4
- gllm_inference/em_invoker/em_invoker.pyi +6 -25
- gllm_inference/em_invoker/google_em_invoker.pyi +1 -1
- gllm_inference/em_invoker/langchain/__init__.pyi +1 -2
- gllm_inference/em_invoker/langchain_em_invoker.pyi +2 -12
- gllm_inference/em_invoker/openai_em_invoker.pyi +1 -1
- gllm_inference/em_invoker/twelevelabs_em_invoker.pyi +2 -18
- gllm_inference/em_invoker/voyage_em_invoker.pyi +2 -5
- gllm_inference/lm_invoker/__init__.pyi +1 -4
- gllm_inference/lm_invoker/anthropic_lm_invoker.pyi +7 -29
- gllm_inference/lm_invoker/azure_openai_lm_invoker.pyi +5 -18
- gllm_inference/lm_invoker/bedrock_lm_invoker.pyi +6 -14
- gllm_inference/lm_invoker/datasaur_lm_invoker.pyi +7 -14
- gllm_inference/lm_invoker/google_lm_invoker.pyi +7 -21
- gllm_inference/lm_invoker/langchain_lm_invoker.pyi +8 -21
- gllm_inference/lm_invoker/litellm_lm_invoker.pyi +6 -13
- gllm_inference/lm_invoker/lm_invoker.pyi +17 -18
- gllm_inference/lm_invoker/openai_compatible_lm_invoker.pyi +8 -22
- gllm_inference/lm_invoker/openai_lm_invoker.pyi +18 -24
- gllm_inference/prompt_builder/__init__.pyi +1 -6
- gllm_inference/prompt_builder/prompt_builder.pyi +9 -102
- 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 +76 -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.cp313-win_amd64.pyd +0 -0
- gllm_inference.pyi +9 -43
- {gllm_inference_binary-0.4.62.dist-info → gllm_inference_binary-0.5.1.dist-info}/METADATA +1 -8
- gllm_inference_binary-0.5.1.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.62.dist-info/RECORD +0 -115
- {gllm_inference_binary-0.4.62.dist-info → gllm_inference_binary-0.5.1.dist-info}/WHEEL +0 -0
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import abc
|
|
2
1
|
from _typeshed import Incomplete
|
|
3
|
-
from
|
|
4
|
-
from gllm_inference.constants import MESSAGE_TUPLE_LENGTH as MESSAGE_TUPLE_LENGTH
|
|
5
|
-
from gllm_inference.schema import Attachment as Attachment, MultimodalContent as MultimodalContent, MultimodalPrompt as MultimodalPrompt, PromptRole as PromptRole
|
|
6
|
-
from gllm_inference.utils import get_prompt_keys as get_prompt_keys, validate_prompt_builder_kwargs as validate_prompt_builder_kwargs
|
|
2
|
+
from gllm_inference.schema import Message as Message, MessageContent as MessageContent, MessageRole as MessageRole
|
|
7
3
|
from typing import Any
|
|
8
4
|
|
|
9
|
-
|
|
10
|
-
DEPRECATION_MESSAGE: str
|
|
5
|
+
KEY_EXTRACTOR_REGEX: Incomplete
|
|
11
6
|
|
|
12
7
|
class PromptBuilder:
|
|
13
8
|
"""A prompt builder class used in Gen AI applications.
|
|
@@ -36,111 +31,23 @@ class PromptBuilder:
|
|
|
36
31
|
Raises:
|
|
37
32
|
ValueError: If both `system_template` and `user_template` are empty.
|
|
38
33
|
"""
|
|
39
|
-
def format(self, history:
|
|
40
|
-
"""Formats the prompt templates into a
|
|
34
|
+
def format(self, history: list[Message] | None = None, extra_contents: list[MessageContent] | None = None, **kwargs: Any) -> list[Message]:
|
|
35
|
+
"""Formats the prompt templates into a list of messages.
|
|
41
36
|
|
|
42
37
|
This method processes each prompt template, replacing the placeholders in the template content with the
|
|
43
38
|
corresponding values from `kwargs`. If any required key is missing from `kwargs`, it raises a `ValueError`.
|
|
44
|
-
It also handles the provided history and extra contents. It formats the prompt as a
|
|
39
|
+
It also handles the provided history and extra contents. It formats the prompt as a list of messages.
|
|
45
40
|
|
|
46
41
|
Args:
|
|
47
|
-
history (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
the user message. Defaults to None.
|
|
51
|
-
attachments (list[Attachment] | None, optional): Deprecated parameter to handle attachments.
|
|
52
|
-
Will be removed in v0.5.0. Defaults to None.
|
|
42
|
+
history (list[Message] | None, optional): The history to be included in the prompt. Defaults to None.
|
|
43
|
+
extra_contents (list[MessageContent] | None, optional): The extra contents to be included in the user
|
|
44
|
+
message. Defaults to None.
|
|
53
45
|
**kwargs (Any): A dictionary of placeholder values to be injected into the prompt templates.
|
|
54
46
|
Values must be either a string or an object that can be serialized to a string.
|
|
55
47
|
|
|
56
48
|
Returns:
|
|
57
|
-
|
|
49
|
+
list[Message]: A formatted list of messages.
|
|
58
50
|
|
|
59
51
|
Raises:
|
|
60
52
|
ValueError: If a required key for the prompt template is missing from `kwargs`.
|
|
61
53
|
"""
|
|
62
|
-
|
|
63
|
-
class BasePromptBuilder(ABC, metaclass=abc.ABCMeta):
|
|
64
|
-
"""A base class for prompt builders used in Gen AI applications.
|
|
65
|
-
|
|
66
|
-
Attributes:
|
|
67
|
-
system_template (str): The system prompt template. May contain placeholders enclosed in curly braces `{}`.
|
|
68
|
-
user_template (str): The user prompt template. May contain placeholders enclosed in curly braces `{}`.
|
|
69
|
-
prompt_key_set (set[str]): A set of expected keys that must be present in the prompt templates.
|
|
70
|
-
ignore_extra_keys (bool): Whether to ignore extra keys when formatting the prompt.
|
|
71
|
-
"""
|
|
72
|
-
system_template: Incomplete
|
|
73
|
-
user_template: Incomplete
|
|
74
|
-
prompt_key_set: Incomplete
|
|
75
|
-
ignore_extra_keys: Incomplete
|
|
76
|
-
logger: Incomplete
|
|
77
|
-
def __init__(self, system_template: str = '', user_template: str = '', ignore_extra_keys: bool = False) -> None:
|
|
78
|
-
"""Initializes a new instance of the BasePromptBuilder class.
|
|
79
|
-
|
|
80
|
-
Args:
|
|
81
|
-
system_template (str, optional): The system prompt template. May contain placeholders enclosed in curly
|
|
82
|
-
braces `{}`. Defaults to an empty string.
|
|
83
|
-
user_template (str, optional): The user prompt template. May contain placeholders enclosed in curly
|
|
84
|
-
braces `{}`. Defaults to an empty string.
|
|
85
|
-
ignore_extra_keys (bool, optional): Whether to ignore extra keys when formatting the prompt.
|
|
86
|
-
Defaults to False.
|
|
87
|
-
|
|
88
|
-
Raises:
|
|
89
|
-
ValueError: If both `system_template` and `user_template` are empty.
|
|
90
|
-
"""
|
|
91
|
-
def format_as_message_list(self, history: list[tuple[PromptRole, list[Any] | str]] | None = None, attachments: list[Attachment] | None = None, system_multimodal_contents: list[Any] | None = None, user_multimodal_contents: list[Any] | None = None, is_multimodal: bool | None = None, **kwargs: Any) -> list[tuple[PromptRole, list[Any] | str]]:
|
|
92
|
-
"""Formats the prompt templates as a list of message tuples (role, formatted content).
|
|
93
|
-
|
|
94
|
-
This method processes each prompt template, replacing the placeholders in the template content with the
|
|
95
|
-
corresponding values from `kwargs`. If a required key is missing from `kwargs`, it raises a `ValueError`. It
|
|
96
|
-
returns a list of tuples, where each tuple consists of a role and the corresponding formatted prompt content.
|
|
97
|
-
|
|
98
|
-
Args:
|
|
99
|
-
history (list[tuple[PromptRole, list[Any] | str]] | None, optional): The optional chat history to be
|
|
100
|
-
included in the prompt. Defaults to None.
|
|
101
|
-
attachments (list[Attachment] | None, optional): The optional attachments to be included in the prompt.
|
|
102
|
-
Defaults to None.
|
|
103
|
-
system_multimodal_contents (list[Any] | None, optional): Deprecated parameter to handle attachments.
|
|
104
|
-
Will be removed in v0.5.0. Defaults to None.
|
|
105
|
-
user_multimodal_contents (list[Any] | None, optional): Deprecated parameter to handle attachments.
|
|
106
|
-
Will be removed in v0.5.0. Defaults to None.
|
|
107
|
-
is_multimodal (bool | None, optional): Whether the prompt supports multimodal inputs. Will be deprecated in
|
|
108
|
-
v0.5.0, in which multimodality will always be True. Defaults to None.
|
|
109
|
-
**kwargs (Any): A dictionary of placeholder values to be injected into the prompt templates.
|
|
110
|
-
|
|
111
|
-
Returns:
|
|
112
|
-
list[tuple[PromptRole, list[Any] | str]]: A list of tuples, each containing a role and the corresponding
|
|
113
|
-
formatted prompt content.
|
|
114
|
-
|
|
115
|
-
Raises:
|
|
116
|
-
ValueError: If a required key for the prompt template is missing from `kwargs`.
|
|
117
|
-
ValueError: If multimodal contents are provided when `is_multimodal` is False.
|
|
118
|
-
"""
|
|
119
|
-
def format_as_string(self, history: list[tuple[PromptRole, str]] | None = None, **kwargs: Any) -> str:
|
|
120
|
-
"""Formats the prompt as a string.
|
|
121
|
-
|
|
122
|
-
This method formats the prompt as a string by first converting the prompt templates to a list of messages and
|
|
123
|
-
then formatting the message list as a string.
|
|
124
|
-
|
|
125
|
-
Args:
|
|
126
|
-
history (list[tuple[PromptRole, str]] | None, optional): The optional chat history to be included in the
|
|
127
|
-
prompt. Defaults to None.
|
|
128
|
-
**kwargs (Any): A dictionary of placeholder values to be injected into the prompt templates.
|
|
129
|
-
|
|
130
|
-
Returns:
|
|
131
|
-
str: The formatted prompt with the placeholders replaced by the provided values.
|
|
132
|
-
|
|
133
|
-
Raises:
|
|
134
|
-
ValueError: If any required key is missing or there are extra keys in the kwargs.
|
|
135
|
-
"""
|
|
136
|
-
@property
|
|
137
|
-
def compatible_model_list(self) -> list[str]:
|
|
138
|
-
'''Returns the list of compatible models for the prompt builder.
|
|
139
|
-
|
|
140
|
-
This property returns the set of models that the prompt builder is compatible with. If the builder is
|
|
141
|
-
model-specific, it returns the list of models in `_compatible_model_list`. Otherwise, it returns a list
|
|
142
|
-
containing `"All"` to indicate compatibility with all models.
|
|
143
|
-
|
|
144
|
-
Returns:
|
|
145
|
-
list[str]: A list of compatible model names, or `["All"]` if the prompt builder is not model-specific.
|
|
146
|
-
'''
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from _typeshed import Incomplete
|
|
2
2
|
from gllm_inference.prompt_formatter.prompt_formatter import BasePromptFormatter as BasePromptFormatter
|
|
3
|
-
from gllm_inference.schema import
|
|
3
|
+
from gllm_inference.schema import MessageRole as MessageRole
|
|
4
4
|
|
|
5
5
|
class AgnosticPromptFormatter(BasePromptFormatter):
|
|
6
6
|
'''A prompt formatter that formats prompt without any specific model formatting.
|
|
@@ -19,9 +19,9 @@ class AgnosticPromptFormatter(BasePromptFormatter):
|
|
|
19
19
|
Usage example:
|
|
20
20
|
```python
|
|
21
21
|
prompt = [
|
|
22
|
-
(
|
|
23
|
-
(
|
|
24
|
-
(
|
|
22
|
+
(MessageRole.USER, ["Hello", "how are you?"]),
|
|
23
|
+
(MessageRole.ASSISTANT, ["I\'m fine", "thank you!"]),
|
|
24
|
+
(MessageRole.USER, ["What is the capital of France?"]),
|
|
25
25
|
]
|
|
26
26
|
prompt_formatter = AgnosticPromptFormatter(
|
|
27
27
|
message_separator="\\n###\\n",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from gllm_inference.prompt_formatter.prompt_formatter import BasePromptFormatter as BasePromptFormatter
|
|
2
|
-
from gllm_inference.schema import
|
|
2
|
+
from gllm_inference.schema import MessageRole as MessageRole
|
|
3
3
|
|
|
4
4
|
TOKENIZER_LOAD_ERROR_MESSAGE: str
|
|
5
5
|
|
|
@@ -22,9 +22,9 @@ class HuggingFacePromptFormatter(BasePromptFormatter):
|
|
|
22
22
|
Usage example:
|
|
23
23
|
```python
|
|
24
24
|
prompt = [
|
|
25
|
-
(
|
|
26
|
-
(
|
|
27
|
-
(
|
|
25
|
+
(MessageRole.USER, ["Hello", "how are you?"]),
|
|
26
|
+
(MessageRole.ASSISTANT, ["I\'m fine", "thank you!"]),
|
|
27
|
+
(MessageRole.USER, ["What is the capital of France?"]),
|
|
28
28
|
]
|
|
29
29
|
prompt_formatter = HuggingFacePromptFormatter(
|
|
30
30
|
model_name_or_path="mistralai/Mistral-7B-Instruct-v0.1",
|
|
@@ -19,9 +19,9 @@ class LlamaPromptFormatter(HuggingFacePromptFormatter):
|
|
|
19
19
|
Usage example:
|
|
20
20
|
```python
|
|
21
21
|
prompt = [
|
|
22
|
-
(
|
|
23
|
-
(
|
|
24
|
-
(
|
|
22
|
+
(MessageRole.USER, ["Hello", "how are you?"]),
|
|
23
|
+
(MessageRole.ASSISTANT, ["I\'m fine", "thank you!"]),
|
|
24
|
+
(MessageRole.USER, ["What is the capital of France?"]),
|
|
25
25
|
]
|
|
26
26
|
prompt_formatter = LlamaPromptFormatter(
|
|
27
27
|
model_name_or_path="meta-llama/Meta-Llama-3.1-8B-Instruct",
|
|
@@ -19,9 +19,9 @@ class MistralPromptFormatter(HuggingFacePromptFormatter):
|
|
|
19
19
|
Usage example:
|
|
20
20
|
```python
|
|
21
21
|
prompt = [
|
|
22
|
-
(
|
|
23
|
-
(
|
|
24
|
-
(
|
|
22
|
+
(MessageRole.USER, ["Hello", "how are you?"]),
|
|
23
|
+
(MessageRole.ASSISTANT, ["I\'m fine", "thank you!"]),
|
|
24
|
+
(MessageRole.USER, ["What is the capital of France?"]),
|
|
25
25
|
]
|
|
26
26
|
prompt_formatter = MistralPromptFormatter(
|
|
27
27
|
model_name_or_path="mistralai/Mistral-7B-Instruct-v0.1",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from gllm_inference.prompt_formatter.prompt_formatter import BasePromptFormatter as BasePromptFormatter
|
|
2
|
-
from gllm_inference.schema import
|
|
2
|
+
from gllm_inference.schema import MessageRole as MessageRole
|
|
3
3
|
|
|
4
4
|
class OpenAIPromptFormatter(BasePromptFormatter):
|
|
5
5
|
'''A prompt formatter that formats prompt with OpenAI\'s specific formatting.
|
|
@@ -16,9 +16,9 @@ class OpenAIPromptFormatter(BasePromptFormatter):
|
|
|
16
16
|
Usage example:
|
|
17
17
|
```python
|
|
18
18
|
prompt = [
|
|
19
|
-
(
|
|
20
|
-
(
|
|
21
|
-
(
|
|
19
|
+
(MessageRole.USER, ["Hello", "how are you?"]),
|
|
20
|
+
(MessageRole.ASSISTANT, ["I\'m fine", "thank you!"]),
|
|
21
|
+
(MessageRole.USER, ["What is the capital of France?"]),
|
|
22
22
|
]
|
|
23
23
|
prompt_formatter = OpenAIPromptFormatter(
|
|
24
24
|
content_separator="---"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import abc
|
|
2
2
|
from _typeshed import Incomplete
|
|
3
3
|
from abc import ABC
|
|
4
|
-
from gllm_inference.schema import
|
|
4
|
+
from gllm_inference.schema import Message as Message, MessageContent as MessageContent, MessageRole as MessageRole
|
|
5
5
|
|
|
6
6
|
class BasePromptFormatter(ABC, metaclass=abc.ABCMeta):
|
|
7
7
|
"""A base class for prompt formatters used in Gen AI applications.
|
|
@@ -19,12 +19,12 @@ class BasePromptFormatter(ABC, metaclass=abc.ABCMeta):
|
|
|
19
19
|
content_separator (str, optional): The separator to be used between the string in a single message.
|
|
20
20
|
Defaults to "\\n".
|
|
21
21
|
'''
|
|
22
|
-
def format(self,
|
|
22
|
+
def format(self, messages: list[Message]) -> str:
|
|
23
23
|
"""Formats the prompt as a string.
|
|
24
24
|
|
|
25
25
|
Args:
|
|
26
|
-
|
|
26
|
+
messages (list[Message]): The messages to be formatted as a string.
|
|
27
27
|
|
|
28
28
|
Returns:
|
|
29
|
-
str: The formatted
|
|
29
|
+
str: The formatted messages as a string.
|
|
30
30
|
"""
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
from _typeshed import Incomplete
|
|
2
2
|
from gllm_core.event import EventEmitter as EventEmitter
|
|
3
3
|
from gllm_inference.lm_invoker.lm_invoker import BaseLMInvoker as BaseLMInvoker
|
|
4
|
-
from gllm_inference.multimodal_lm_invoker.multimodal_lm_invoker import BaseMultimodalLMInvoker as BaseMultimodalLMInvoker
|
|
5
|
-
from gllm_inference.multimodal_prompt_builder import MultimodalPromptBuilder as MultimodalPromptBuilder
|
|
6
4
|
from gllm_inference.output_parser.output_parser import BaseOutputParser as BaseOutputParser
|
|
7
|
-
from gllm_inference.prompt_builder.prompt_builder import
|
|
8
|
-
from gllm_inference.schema import
|
|
5
|
+
from gllm_inference.prompt_builder.prompt_builder import PromptBuilder as PromptBuilder
|
|
6
|
+
from gllm_inference.schema import LMOutput as LMOutput, Message as Message, MessageContent as MessageContent, ResponseSchema as ResponseSchema, ToolCall as ToolCall, ToolResult as ToolResult
|
|
9
7
|
from langchain_core.tools import Tool as Tool
|
|
10
8
|
from typing import Any
|
|
11
9
|
|
|
@@ -17,10 +15,8 @@ class LMRequestProcessor:
|
|
|
17
15
|
the inference process in Gen AI applications.
|
|
18
16
|
|
|
19
17
|
Attributes:
|
|
20
|
-
prompt_builder (PromptBuilder
|
|
21
|
-
|
|
22
|
-
lm_invoker (BaseLMInvoker | BaseMultimodalLMInvoker): The language model invoker that handles the model
|
|
23
|
-
inference.
|
|
18
|
+
prompt_builder (PromptBuilder): The prompt builder used to format the prompt.
|
|
19
|
+
lm_invoker (BaseLMInvoker): The language model invoker that handles the model inference.
|
|
24
20
|
output_parser (BaseOutputParser | None): The optional parser to process the model's output, if any.
|
|
25
21
|
tool_dict (dict[str, Tool]): A dictionary of tools provided to the language model to enable tool calling,
|
|
26
22
|
if any. The dictionary maps the tool name to the tools themselves.
|
|
@@ -29,18 +25,14 @@ class LMRequestProcessor:
|
|
|
29
25
|
lm_invoker: Incomplete
|
|
30
26
|
output_parser: Incomplete
|
|
31
27
|
tool_dict: Incomplete
|
|
32
|
-
def __init__(self, prompt_builder: PromptBuilder
|
|
28
|
+
def __init__(self, prompt_builder: PromptBuilder, lm_invoker: BaseLMInvoker, output_parser: BaseOutputParser | None = None) -> None:
|
|
33
29
|
"""Initializes a new instance of the LMRequestProcessor class.
|
|
34
30
|
|
|
35
31
|
Args:
|
|
36
|
-
prompt_builder (PromptBuilder
|
|
37
|
-
|
|
38
|
-
lm_invoker (BaseLMInvoker | BaseMultimodalLMInvoker): The language model invoker that handles the model
|
|
39
|
-
inference.
|
|
32
|
+
prompt_builder (PromptBuilder): The prompt builder used to format the prompt.
|
|
33
|
+
lm_invoker (BaseLMInvoker): The language model invoker that handles the model inference.
|
|
40
34
|
output_parser (BaseOutputParser, optional): An optional parser to process the model's output.
|
|
41
35
|
Defaults to None.
|
|
42
|
-
|
|
43
|
-
WARNING: Support for MultimodalPromptBuilder is deprecated and will be removed in version 0.5.0.
|
|
44
36
|
"""
|
|
45
37
|
def set_tools(self, tools: list[Tool]) -> None:
|
|
46
38
|
"""Sets the tools for the LM invoker.
|
|
@@ -68,7 +60,7 @@ class LMRequestProcessor:
|
|
|
68
60
|
|
|
69
61
|
This method clears the response schema for the LM invoker.
|
|
70
62
|
"""
|
|
71
|
-
async def process(self, prompt_kwargs: dict[str, Any]
|
|
63
|
+
async def process(self, prompt_kwargs: dict[str, Any] | None = None, history: list[Message] | None = None, extra_contents: list[MessageContent] | None = None, hyperparameters: dict[str, Any] | None = None, event_emitter: EventEmitter | None = None, auto_execute_tools: bool = True, max_lm_calls: int = 5) -> Any:
|
|
72
64
|
"""Processes a language model inference request.
|
|
73
65
|
|
|
74
66
|
This method processes the language model inference request as follows:
|
|
@@ -80,21 +72,16 @@ class LMRequestProcessor:
|
|
|
80
72
|
LMOutput object, the output parser will process the `response` attribute of the LMOutput object.
|
|
81
73
|
|
|
82
74
|
Args:
|
|
83
|
-
prompt_kwargs (dict[str, Any]): A dictionary of arguments used to format the prompt.
|
|
84
|
-
|
|
75
|
+
prompt_kwargs (dict[str, Any], optional): A dictionary of arguments used to format the prompt.
|
|
76
|
+
Defaults to None, in which case no arguments will be passed to the prompt builder.
|
|
77
|
+
history (list[Message] | None, optional): A list of conversation history to be included in the prompt.
|
|
85
78
|
Defaults to None.
|
|
86
|
-
extra_contents (list[
|
|
79
|
+
extra_contents (list[MessageContent] | None, optional): A list of extra contents to be included in the
|
|
87
80
|
user message. Defaults to None.
|
|
88
81
|
hyperparameters (dict[str, Any] | None, optional): A dictionary of hyperparameters for the model invocation.
|
|
89
82
|
Defaults to None.
|
|
90
83
|
event_emitter (EventEmitter | None, optional): An event emitter for streaming model outputs.
|
|
91
84
|
Defaults to None.
|
|
92
|
-
attachments (list[Attachment] | None, optional): Deprecated parameter to handle attachments.
|
|
93
|
-
Will be removed in v0.5.0. Defaults to None.
|
|
94
|
-
system_multimodal_contents (list[Any] | None, optional): Deprecated parameter to handle attachments.
|
|
95
|
-
Will be removed in v0.5.0. Defaults to None.
|
|
96
|
-
user_multimodal_contents (list[Any] | None, optional): Deprecated parameter to handle attachments.
|
|
97
|
-
Will be removed in v0.5.0. Defaults to None.
|
|
98
85
|
auto_execute_tools (bool, optional): Whether to automatically execute tools if the LM invokes output
|
|
99
86
|
tool calls. Defaults to True.
|
|
100
87
|
max_lm_calls (int, optional): The maximum number of times the language model can be invoked
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
from gllm_inference.lm_invoker.lm_invoker import BaseLMInvoker as BaseLMInvoker
|
|
2
|
-
from gllm_inference.multimodal_lm_invoker.multimodal_lm_invoker import BaseMultimodalLMInvoker as BaseMultimodalLMInvoker
|
|
3
|
-
from gllm_inference.multimodal_prompt_builder import MultimodalPromptBuilder as MultimodalPromptBuilder
|
|
4
2
|
from gllm_inference.output_parser.output_parser import BaseOutputParser as BaseOutputParser
|
|
5
|
-
from gllm_inference.prompt_builder.prompt_builder import
|
|
3
|
+
from gllm_inference.prompt_builder.prompt_builder import PromptBuilder as PromptBuilder
|
|
6
4
|
from gllm_inference.request_processor.lm_request_processor import LMRequestProcessor as LMRequestProcessor
|
|
7
5
|
from typing import Any
|
|
8
6
|
|
|
@@ -35,22 +33,18 @@ class UsesLM:
|
|
|
35
33
|
first argument.
|
|
36
34
|
'''
|
|
37
35
|
@classmethod
|
|
38
|
-
def from_lm_components(cls, prompt_builder: PromptBuilder
|
|
36
|
+
def from_lm_components(cls, prompt_builder: PromptBuilder, lm_invoker: BaseLMInvoker, output_parser: BaseOutputParser | None = None, **kwargs: Any):
|
|
39
37
|
"""Creates an instance by initializing LMRequestProcessor with given components.
|
|
40
38
|
|
|
41
39
|
This method is a shortcut to initialize the class by providing the LMRequestProcessor components directly.
|
|
42
40
|
|
|
43
41
|
Args:
|
|
44
|
-
prompt_builder (PromptBuilder
|
|
45
|
-
|
|
46
|
-
lm_invoker (BaseLMInvoker | BaseMultimodalLMInvoker): The language model invoker that handles the model
|
|
47
|
-
inference.
|
|
42
|
+
prompt_builder (PromptBuilder): The prompt builder used to format the prompt.
|
|
43
|
+
lm_invoker (BaseLMInvoker): The language model invoker that handles the model inference.
|
|
48
44
|
output_parser (BaseOutputParser, optional): An optional parser to process the model's output.
|
|
49
45
|
Defaults to None.
|
|
50
46
|
**kwargs (Any): Additional keyword arguments to be passed to the class constructor.
|
|
51
47
|
|
|
52
48
|
Returns:
|
|
53
49
|
An instance of the class that mixes in this mixin.
|
|
54
|
-
|
|
55
|
-
WARNING: Support for MultimodalPromptBuilder is deprecated and will be removed in version 0.5.0.
|
|
56
50
|
"""
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
from gllm_inference.schema.
|
|
1
|
+
from gllm_inference.schema.attachment import Attachment as Attachment
|
|
2
|
+
from gllm_inference.schema.code_exec_result import CodeExecResult as CodeExecResult
|
|
3
|
+
from gllm_inference.schema.enums import AttachmentType as AttachmentType, EmitDataType as EmitDataType, MessageRole as MessageRole
|
|
4
|
+
from gllm_inference.schema.lm_output import LMOutput as LMOutput
|
|
5
|
+
from gllm_inference.schema.message import Message as Message
|
|
2
6
|
from gllm_inference.schema.model_id import ModelId as ModelId, ModelProvider as ModelProvider
|
|
3
|
-
from gllm_inference.schema.
|
|
4
|
-
from gllm_inference.schema.
|
|
7
|
+
from gllm_inference.schema.reasoning import Reasoning as Reasoning
|
|
8
|
+
from gllm_inference.schema.token_usage import TokenUsage as TokenUsage
|
|
9
|
+
from gllm_inference.schema.tool_call import ToolCall as ToolCall
|
|
10
|
+
from gllm_inference.schema.tool_result import ToolResult as ToolResult
|
|
11
|
+
from gllm_inference.schema.type_alias import EMContent as EMContent, ErrorResponse as ErrorResponse, MessageContent as MessageContent, ResponseSchema as ResponseSchema, Vector as Vector
|
|
5
12
|
|
|
6
|
-
__all__ = ['Attachment', 'AttachmentType', 'CodeExecResult', '
|
|
13
|
+
__all__ = ['Attachment', 'AttachmentType', 'CodeExecResult', 'EMContent', 'EmitDataType', 'ErrorResponse', 'MessageContent', 'LMOutput', 'ModelId', 'ModelProvider', 'Message', 'MessageRole', 'Reasoning', 'ResponseSchema', 'TokenUsage', 'ToolCall', 'ToolResult', 'Vector']
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
from _typeshed import Incomplete
|
|
2
|
+
from gllm_inference.constants import HEX_REPR_LENGTH as HEX_REPR_LENGTH
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
|
|
5
|
+
logger: Incomplete
|
|
6
|
+
|
|
7
|
+
class Attachment(BaseModel):
|
|
8
|
+
"""Defines a file attachment schema.
|
|
9
|
+
|
|
10
|
+
Attributes:
|
|
11
|
+
data (bytes): The content data of the file attachment.
|
|
12
|
+
filename (str): The filename of the file attachment.
|
|
13
|
+
mime_type (str): The mime type of the file attachment.
|
|
14
|
+
extension (str): The extension of the file attachment.
|
|
15
|
+
url (str | None): The URL of the file attachment. Defaults to None.
|
|
16
|
+
"""
|
|
17
|
+
data: bytes
|
|
18
|
+
filename: str
|
|
19
|
+
mime_type: str
|
|
20
|
+
extension: str
|
|
21
|
+
url: str | None
|
|
22
|
+
@classmethod
|
|
23
|
+
def from_bytes(cls, bytes: bytes, filename: str | None = None) -> Attachment:
|
|
24
|
+
"""Creates an Attachment from bytes.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
bytes (bytes): The bytes of the file.
|
|
28
|
+
filename (str | None, optional): The filename of the file. Defaults to None,
|
|
29
|
+
in which case the filename will be derived from the extension.
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
Attachment: The instantiated Attachment.
|
|
33
|
+
"""
|
|
34
|
+
@classmethod
|
|
35
|
+
def from_data_url(cls, data_url: str, filename: str | None = None) -> Attachment:
|
|
36
|
+
"""Creates an Attachment from a data URL (data:[mime/type];base64,[bytes]).
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
data_url (str): The data URL of the file.
|
|
40
|
+
filename (str | None, optional): The filename of the file. Defaults to None,
|
|
41
|
+
in which case the filename will be derived from the mime type.
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
Attachment: The instantiated Attachment.
|
|
45
|
+
"""
|
|
46
|
+
@classmethod
|
|
47
|
+
def from_url(cls, url: str, filename: str | None = None) -> Attachment:
|
|
48
|
+
"""Creates an Attachment from a URL.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
url (str): The URL of the file.
|
|
52
|
+
filename (str | None, optional): The filename of the file. Defaults to None,
|
|
53
|
+
in which case the filename will be derived from the URL.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
Attachment: The instantiated Attachment.
|
|
57
|
+
"""
|
|
58
|
+
@classmethod
|
|
59
|
+
def from_path(cls, path: str, filename: str | None = None) -> Attachment:
|
|
60
|
+
"""Creates an Attachment from a path.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
path (str): The path to the file.
|
|
64
|
+
filename (str | None, optional): The filename of the file. Defaults to None,
|
|
65
|
+
in which case the filename will be derived from the path.
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
Attachment: The instantiated Attachment.
|
|
69
|
+
"""
|
|
70
|
+
def write_to_file(self, path: str | None = None) -> None:
|
|
71
|
+
"""Writes the Attachment to a file.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
path (str | None, optional): The path to the file. Defaults to None,
|
|
75
|
+
in which case the filename will be used as the path.
|
|
76
|
+
"""
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from gllm_inference.schema.attachment import Attachment as Attachment
|
|
2
|
+
from pydantic import BaseModel
|
|
3
|
+
|
|
4
|
+
class CodeExecResult(BaseModel):
|
|
5
|
+
"""Defines a code execution result when a language model is configured to execute code.
|
|
6
|
+
|
|
7
|
+
Attributes:
|
|
8
|
+
id (str): The ID of the code execution. Defaults to an empty string.
|
|
9
|
+
code (str): The executed code. Defaults to an empty string.
|
|
10
|
+
output (list[str | Attachment]): The output of the executed code. Defaults to an empty list.
|
|
11
|
+
"""
|
|
12
|
+
id: str
|
|
13
|
+
code: str
|
|
14
|
+
output: list[str | Attachment]
|
gllm_inference/schema/enums.pyi
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
from enum import StrEnum
|
|
2
2
|
|
|
3
|
+
class AttachmentType(StrEnum):
|
|
4
|
+
"""Defines valid attachment types."""
|
|
5
|
+
AUDIO = 'audio'
|
|
6
|
+
DOCUMENT = 'document'
|
|
7
|
+
IMAGE = 'image'
|
|
8
|
+
VIDEO = 'video'
|
|
9
|
+
|
|
3
10
|
class EmitDataType(StrEnum):
|
|
4
11
|
"""Defines valid data types for emitting events."""
|
|
5
12
|
ACTIVITY = 'activity'
|
|
@@ -10,15 +17,8 @@ class EmitDataType(StrEnum):
|
|
|
10
17
|
THINKING_START = 'thinking_start'
|
|
11
18
|
THINKING_END = 'thinking_end'
|
|
12
19
|
|
|
13
|
-
class
|
|
14
|
-
"""Defines valid
|
|
20
|
+
class MessageRole(StrEnum):
|
|
21
|
+
"""Defines valid message roles."""
|
|
15
22
|
SYSTEM = 'system'
|
|
16
23
|
USER = 'user'
|
|
17
24
|
ASSISTANT = 'assistant'
|
|
18
|
-
|
|
19
|
-
class AttachmentType(StrEnum):
|
|
20
|
-
"""Defines valid attachment types."""
|
|
21
|
-
AUDIO = 'audio'
|
|
22
|
-
DOCUMENT = 'document'
|
|
23
|
-
IMAGE = 'image'
|
|
24
|
-
VIDEO = 'video'
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from gllm_core.schema import Chunk as Chunk
|
|
2
|
+
from gllm_inference.schema.code_exec_result import CodeExecResult as CodeExecResult
|
|
3
|
+
from gllm_inference.schema.reasoning import Reasoning as Reasoning
|
|
4
|
+
from gllm_inference.schema.token_usage import TokenUsage as TokenUsage
|
|
5
|
+
from gllm_inference.schema.tool_call import ToolCall as ToolCall
|
|
6
|
+
from pydantic import BaseModel
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
class LMOutput(BaseModel):
|
|
10
|
+
"""Defines the output of a language model.
|
|
11
|
+
|
|
12
|
+
Attributes:
|
|
13
|
+
response (str): The text response. Defaults to an empty string.
|
|
14
|
+
tool_calls (list[ToolCall]): The tool calls, if the language model decides to invoke tools.
|
|
15
|
+
Defaults to an empty list.
|
|
16
|
+
structured_output (dict[str, Any] | BaseModel | None): The structured output, if a response schema is defined
|
|
17
|
+
for the language model. Defaults to None.
|
|
18
|
+
token_usage (TokenUsage | None): The token usage analytics, if requested. Defaults to None.
|
|
19
|
+
duration (float | None): The duration of the invocation in seconds, if requested. Defaults to None.
|
|
20
|
+
finish_details (dict[str, Any]): The details about how the generation finished, if requested.
|
|
21
|
+
Defaults to an empty dictionary.
|
|
22
|
+
reasoning (list[Reasoning]): The reasoning, if the language model is configured to output reasoning.
|
|
23
|
+
Defaults to an empty list.
|
|
24
|
+
citations (list[Chunk]): The citations, if the language model outputs citations. Defaults to an empty list.
|
|
25
|
+
code_exec_results (list[CodeExecResult]): The code execution results, if the language model decides to
|
|
26
|
+
execute code. Defaults to an empty list.
|
|
27
|
+
"""
|
|
28
|
+
response: str
|
|
29
|
+
tool_calls: list[ToolCall]
|
|
30
|
+
structured_output: dict[str, Any] | BaseModel | None
|
|
31
|
+
token_usage: TokenUsage | None
|
|
32
|
+
duration: float | None
|
|
33
|
+
finish_details: dict[str, Any]
|
|
34
|
+
reasoning: list[Reasoning]
|
|
35
|
+
citations: list[Chunk]
|
|
36
|
+
code_exec_results: list[CodeExecResult]
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
from gllm_inference.schema.enums import MessageRole as MessageRole
|
|
2
|
+
from gllm_inference.schema.type_alias import MessageContent as MessageContent
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
class Message(BaseModel):
|
|
7
|
+
"""Defines a message schema to be used as inputs for a language model.
|
|
8
|
+
|
|
9
|
+
Attributes:
|
|
10
|
+
role (MessageRole): The role of the message.
|
|
11
|
+
contents (list[MessageContent]): The contents of the message.
|
|
12
|
+
metadata (dict[str, Any]): The metadata of the message.
|
|
13
|
+
"""
|
|
14
|
+
role: MessageRole
|
|
15
|
+
contents: list[MessageContent]
|
|
16
|
+
metadata: dict[str, Any]
|
|
17
|
+
@classmethod
|
|
18
|
+
def system(cls, contents: MessageContent | list[MessageContent], metadata: dict[str, Any] | None = None) -> Message:
|
|
19
|
+
"""Create a system message.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
contents (MessageContent | list[MessageContent]): The message contents.
|
|
23
|
+
If a single content is provided, it will be wrapped in a list.
|
|
24
|
+
metadata (dict[str, Any], optional): Additional metadata for the message. Defaults to None.
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
Message: A new message with SYSTEM role.
|
|
28
|
+
"""
|
|
29
|
+
@classmethod
|
|
30
|
+
def user(cls, contents: MessageContent | list[MessageContent], metadata: dict[str, Any] | None = None) -> Message:
|
|
31
|
+
"""Create a user message.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
contents (MessageContent | list[MessageContent]): The message contents.
|
|
35
|
+
If a single content is provided, it will be wrapped in a list.
|
|
36
|
+
metadata (dict[str, Any], optional): Additional metadata for the message. Defaults to None.
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
Message: A new message with USER role.
|
|
40
|
+
"""
|
|
41
|
+
@classmethod
|
|
42
|
+
def assistant(cls, contents: MessageContent | list[MessageContent], metadata: dict[str, Any] | None = None) -> Message:
|
|
43
|
+
"""Create an assistant message.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
contents (MessageContent | list[MessageContent]): The message contents.
|
|
47
|
+
If a single content is provided, it will be wrapped in a list.
|
|
48
|
+
metadata (dict[str, Any], optional): Additional metadata for the message. Defaults to None.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
Message: A new message with ASSISTANT role.
|
|
52
|
+
"""
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
|
|
3
|
+
class Reasoning(BaseModel):
|
|
4
|
+
"""Defines a reasoning output when a language model is configured to use reasoning.
|
|
5
|
+
|
|
6
|
+
Attributes:
|
|
7
|
+
id (str): The ID of the reasoning output. Defaults to an empty string.
|
|
8
|
+
reasoning (str): The reasoning text. Defaults to an empty string.
|
|
9
|
+
type (str): The type of the reasoning output. Defaults to an empty string.
|
|
10
|
+
data (str): The additional data of the reasoning output. Defaults to an empty string.
|
|
11
|
+
"""
|
|
12
|
+
id: str
|
|
13
|
+
reasoning: str
|
|
14
|
+
type: str
|
|
15
|
+
data: str
|