gllm-inference-binary 0.5.44__cp311-cp311-manylinux_2_31_x86_64.whl → 0.5.45__cp311-cp311-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.
@@ -0,0 +1,4 @@
1
+ from gllm_inference.prompt_builder.format_strategy.jinja_format_strategy import JinjaFormatStrategy as JinjaFormatStrategy
2
+ from gllm_inference.prompt_builder.format_strategy.string_format_strategy import StringFormatStrategy as StringFormatStrategy
3
+
4
+ __all__ = ['StringFormatStrategy', 'JinjaFormatStrategy']
@@ -0,0 +1,55 @@
1
+ import abc
2
+ from _typeshed import Incomplete
3
+ from abc import ABC, abstractmethod
4
+ from gllm_inference.schema.message import MessageContent as MessageContent
5
+
6
+ class BasePromptFormattingStrategy(ABC, metaclass=abc.ABCMeta):
7
+ """Base class for prompt formatting strategies.
8
+
9
+ This class defines the interface for different prompt templating engines. Subclasses
10
+ implement specific formatting strategies to render templates with variable
11
+ substitution.
12
+
13
+ The strategy pattern allows the PromptBuilder to work with different templating engines
14
+ without changing its core logic.
15
+
16
+ Attributes:
17
+ key_defaults (dict[str, str]): The default values for the keys.
18
+ """
19
+ key_defaults: Incomplete
20
+ def __init__(self, key_defaults: dict[str, str] | None = None) -> None:
21
+ """Initialize the BasePromptFormattingStrategy.
22
+
23
+ Args:
24
+ key_defaults (dict[str, str] | None, optional): The default values for the keys. Defaults to None,
25
+ in which case no default values are used.
26
+ """
27
+ def format(self, template: str, variables_map: dict[str, str] | None = None, extra_contents: list[MessageContent] | None = None) -> list[str]:
28
+ """Format template with variables using the template method pattern.
29
+
30
+ This is a template method that defines the algorithm for formatting:
31
+ 1. Merge key_defaults and variables_map
32
+ 2. Render the template (delegated to subclass via _render_template)
33
+ 3. Append extra_contents to the result
34
+
35
+ Args:
36
+ template (str): Template string to format.
37
+ variables_map (dict[str, str] | None, optional): Variables for substitution. Defaults to None.
38
+ extra_contents (list[MessageContent] | None, optional): Extra contents to format. Defaults to None.
39
+
40
+ Returns:
41
+ str: Formatted template string.
42
+ """
43
+ @abstractmethod
44
+ def extract_keys(self, template: str | None) -> set[str]:
45
+ """Extract variable keys from template.
46
+
47
+ Args:
48
+ template (str | None): Template string to extract keys from.
49
+
50
+ Returns:
51
+ set[str]: Set of variable keys found in template.
52
+
53
+ Raises:
54
+ NotImplementedError: If the method is not implemented.
55
+ """
@@ -0,0 +1,45 @@
1
+ from _typeshed import Incomplete
2
+ from gllm_inference.prompt_builder.format_strategy.format_strategy import BasePromptFormattingStrategy as BasePromptFormattingStrategy
3
+ from gllm_inference.schema import JinjaEnvType as JinjaEnvType
4
+ from jinja2.sandbox import SandboxedEnvironment
5
+ from typing import Any
6
+
7
+ JINJA_DEFAULT_BLACKLISTED_FILTERS: list[str]
8
+ JINJA_DEFAULT_SAFE_GLOBALS: dict[str, Any]
9
+ JINJA_DANGEROUS_PATTERNS: list[str]
10
+ PROMPT_BUILDER_VARIABLE_START_STRING: str
11
+ PROMPT_BUILDER_VARIABLE_END_STRING: str
12
+
13
+ class JinjaFormatStrategy(BasePromptFormattingStrategy):
14
+ """Jinja2 template engine for formatting prompts.
15
+
16
+ Attributes:
17
+ jinja_env (SandboxedEnvironment): The Jinja environment for rendering templates.
18
+ key_defaults (dict[str, str]): The default values for the keys.
19
+ """
20
+ jinja_env: Incomplete
21
+ def __init__(self, environment: JinjaEnvType | SandboxedEnvironment = ..., key_defaults: dict[str, str] | None = None) -> None:
22
+ """Initialize the JinjaFormatStrategy.
23
+
24
+ Args:
25
+ environment (JinjaEnvType | SandboxedEnvironment, optional): The environment for Jinja rendering.
26
+ It can be one of the following:
27
+ 1. `JinjaEnvType.RESTRICTED`: Uses a minimal, restricted Jinja environment.
28
+ Safest for most cases.
29
+ 2. `JinjaEnvType.JINJA_DEFAULT`: Uses the full Jinja environment. Allows more powerful templating,
30
+ but with fewer safety restrictions.
31
+ 3. `SandboxedEnvironment` instance: A custom Jinja `SandboxedEnvironment` object provided by the
32
+ user. Offers fine-grained control over template execution.
33
+ Defaults to `JinjaEnvType.RESTRICTED`
34
+ key_defaults (dict[str, str], optional): The default values for the keys. Defaults to None, in which
35
+ case no default values are used.
36
+ """
37
+ def extract_keys(self, template: str | None) -> set[str]:
38
+ """Extract keys from Jinja template using AST analysis.
39
+
40
+ Args:
41
+ template (str | None): The template to extract keys from.
42
+
43
+ Returns:
44
+ set[str]: The set of keys found in the template.
45
+ """
@@ -0,0 +1,20 @@
1
+ from _typeshed import Incomplete
2
+ from gllm_inference.prompt_builder.format_strategy.format_strategy import BasePromptFormattingStrategy as BasePromptFormattingStrategy
3
+
4
+ KEY_EXTRACTOR_REGEX: Incomplete
5
+
6
+ class StringFormatStrategy(BasePromptFormattingStrategy):
7
+ """String format strategy using str.format() method.
8
+
9
+ Attributes:
10
+ key_defaults (dict[str, str]): The default values for the keys.
11
+ """
12
+ def extract_keys(self, template: str | None) -> set[str]:
13
+ """Extract keys from a template.
14
+
15
+ Args:
16
+ template (str | None): The template to extract keys from.
17
+
18
+ Returns:
19
+ set[str]: The set of keys found in the template.
20
+ """
@@ -1,9 +1,9 @@
1
1
  from _typeshed import Incomplete
2
- from gllm_inference.schema import Message as Message, MessageContent as MessageContent, MessageRole as MessageRole
2
+ from gllm_inference.prompt_builder.format_strategy import JinjaFormatStrategy as JinjaFormatStrategy, StringFormatStrategy as StringFormatStrategy
3
+ from gllm_inference.schema import JinjaEnvType as JinjaEnvType, Message as Message, MessageContent as MessageContent, MessageRole as MessageRole
4
+ from jinja2.sandbox import SandboxedEnvironment as SandboxedEnvironment
3
5
  from typing import Any
4
6
 
5
- KEY_EXTRACTOR_REGEX: Incomplete
6
-
7
7
  class PromptBuilder:
8
8
  """A prompt builder class used in Gen AI applications.
9
9
 
@@ -12,12 +12,14 @@ class PromptBuilder:
12
12
  user_template (str): The user prompt template. May contain placeholders enclosed in curly braces `{}`.
13
13
  prompt_key_set (set[str]): A set of expected keys that must be present in the prompt templates.
14
14
  key_defaults (dict[str, str]): Default values for the keys in the prompt templates.
15
+ strategy (BasePromptFormattingStrategy): The format strategy to be used for formatting the prompt.
15
16
  """
17
+ key_defaults: Incomplete
16
18
  system_template: Incomplete
17
19
  user_template: Incomplete
20
+ strategy: Incomplete
18
21
  prompt_key_set: Incomplete
19
- key_defaults: Incomplete
20
- def __init__(self, system_template: str = '', user_template: str = '', key_defaults: dict[str, str] | None = None, ignore_extra_keys: bool | None = None) -> None:
22
+ def __init__(self, system_template: str = '', user_template: str = '', key_defaults: dict[str, str] | None = None, ignore_extra_keys: bool | None = None, use_jinja: bool = False, jinja_env: JinjaEnvType | SandboxedEnvironment = ...) -> None:
21
23
  """Initializes a new instance of the PromptBuilder class.
22
24
 
23
25
  Args:
@@ -30,6 +32,17 @@ class PromptBuilder:
30
32
  Defaults to None, in which case no default values will be assigned to the keys.
31
33
  ignore_extra_keys (bool | None, optional): Deprecated parameter. Will be removed in v0.6. Extra keys
32
34
  will always raise a warning only instead of raising an error.
35
+ use_jinja (bool, optional): Whether to use Jinja for rendering the prompt templates.
36
+ Defaults to False.
37
+ jinja_env (JinjaEnvType | SandboxedEnvironment, optional): The environment for Jinja rendering.
38
+ It can be one of the following:
39
+ 1. `JinjaEnvType.RESTRICTED`: Uses a minimal, restricted Jinja environment.
40
+ Safest for most cases.
41
+ 2. `JinjaEnvType.JINJA_DEFAULT`: Uses the full Jinja environment. Allows more powerful templating,
42
+ but with fewer safety restrictions.
43
+ 3. `SandboxedEnvironment` instance: A custom Jinja `SandboxedEnvironment` object provided by the
44
+ user. Offers fine-grained control over template execution.
45
+ Defaults to `JinjaEnvType.RESTRICTED`
33
46
 
34
47
  Raises:
35
48
  ValueError: If both `system_template` and `user_template` are empty.
@@ -49,7 +62,7 @@ class PromptBuilder:
49
62
  Values must be either a string or an object that can be serialized to a string.
50
63
 
51
64
  Returns:
52
- list[Message]: A formatted list of messages.
65
+ list[Message]: A list of formatted messages.
53
66
 
54
67
  Raises:
55
68
  ValueError: If a required key for the prompt template is missing from `kwargs`.
@@ -2,7 +2,7 @@ from gllm_inference.schema.activity import Activity as Activity, MCPCallActivity
2
2
  from gllm_inference.schema.attachment import Attachment as Attachment
3
3
  from gllm_inference.schema.code_exec_result import CodeExecResult as CodeExecResult
4
4
  from gllm_inference.schema.config import TruncationConfig as TruncationConfig
5
- from gllm_inference.schema.enums import AttachmentType as AttachmentType, BatchStatus as BatchStatus, EmitDataType as EmitDataType, LMEventType as LMEventType, MessageRole as MessageRole, TruncateSide as TruncateSide
5
+ from gllm_inference.schema.enums import AttachmentType as AttachmentType, BatchStatus as BatchStatus, EmitDataType as EmitDataType, JinjaEnvType as JinjaEnvType, LMEventType as LMEventType, MessageRole as MessageRole, TruncateSide as TruncateSide
6
6
  from gllm_inference.schema.events import ActivityEvent as ActivityEvent, CodeEvent as CodeEvent, ThinkingEvent as ThinkingEvent
7
7
  from gllm_inference.schema.lm_input import LMInput as LMInput
8
8
  from gllm_inference.schema.lm_output import LMOutput as LMOutput
@@ -15,4 +15,4 @@ from gllm_inference.schema.tool_call import ToolCall as ToolCall
15
15
  from gllm_inference.schema.tool_result import ToolResult as ToolResult
16
16
  from gllm_inference.schema.type_alias import EMContent as EMContent, MessageContent as MessageContent, ResponseSchema as ResponseSchema, Vector as Vector
17
17
 
18
- __all__ = ['Activity', 'ActivityEvent', 'Attachment', 'AttachmentType', 'BatchStatus', 'CodeEvent', 'CodeExecResult', 'EMContent', 'EmitDataType', 'LMEventType', 'InputTokenDetails', 'LMInput', 'LMOutput', 'MCPCall', 'MCPCallActivity', 'MCPListToolsActivity', 'MCPServer', 'Message', 'MessageContent', 'MessageRole', 'ModelId', 'ModelProvider', 'OutputTokenDetails', 'Reasoning', 'ThinkingEvent', 'ResponseSchema', 'TokenUsage', 'ToolCall', 'ToolResult', 'TruncateSide', 'TruncationConfig', 'Vector', 'WebSearchActivity']
18
+ __all__ = ['Activity', 'ActivityEvent', 'Attachment', 'AttachmentType', 'BatchStatus', 'CodeEvent', 'CodeExecResult', 'EMContent', 'EmitDataType', 'LMEventType', 'InputTokenDetails', 'JinjaEnvType', 'LMInput', 'LMOutput', 'MCPCall', 'MCPCallActivity', 'MCPListToolsActivity', 'MCPServer', 'Message', 'MessageContent', 'MessageRole', 'ModelId', 'ModelProvider', 'OutputTokenDetails', 'Reasoning', 'ThinkingEvent', 'ResponseSchema', 'TokenUsage', 'ToolCall', 'ToolResult', 'TruncateSide', 'TruncationConfig', 'Vector', 'WebSearchActivity']
@@ -54,6 +54,11 @@ class TruncateSide(StrEnum):
54
54
  RIGHT = 'RIGHT'
55
55
  LEFT = 'LEFT'
56
56
 
57
+ class JinjaEnvType(StrEnum):
58
+ """Enumeration for Jinja environment types."""
59
+ JINJA_DEFAULT = 'jinja_default'
60
+ RESTRICTED = 'restricted'
61
+
57
62
  class WebSearchKey(StrEnum):
58
63
  """Defines valid web search keys."""
59
64
  PATTERN = 'pattern'
gllm_inference.pyi CHANGED
@@ -131,6 +131,11 @@ import xai_sdk.search
131
131
  import xai_sdk.proto
132
132
  import xai_sdk.proto.v5
133
133
  import xai_sdk.proto.v5.chat_pb2
134
+ import jinja2
135
+ import jinja2.sandbox
136
+ import gllm_inference.schema.JinjaEnvType
137
+ import gllm_inference.prompt_builder.format_strategy.JinjaFormatStrategy
138
+ import gllm_inference.prompt_builder.format_strategy.StringFormatStrategy
134
139
  import transformers
135
140
  import gllm_inference.prompt_formatter.HuggingFacePromptFormatter
136
141
  import logging
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: gllm-inference-binary
3
- Version: 0.5.44
3
+ Version: 0.5.45
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,5 +1,5 @@
1
- gllm_inference.cpython-311-x86_64-linux-gnu.so,sha256=qi0XRUXo6qxP3gv-_fNkpvo6744gct_EoXqh1Ur309U,5073600
2
- gllm_inference.pyi,sha256=Ue4h4rmHxeDhBKu4Ofd6wTgDBxxsFhd_CxTCvtQgZpA,4898
1
+ gllm_inference.cpython-311-x86_64-linux-gnu.so,sha256=L1UTHulpPmXRNNjXL0SSXcBh8uzf8lYd1tKZYaDVZoE,5159920
2
+ gllm_inference.pyi,sha256=mlp8HQ3h_dutd5vdOEFyF6Z1algaWVEoX2VuYNONg1U,5123
3
3
  gllm_inference/__init__.pyi,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  gllm_inference/constants.pyi,sha256=viU-ACRbVSGvsCJ0FQmuR1yhyl-BzoHDVIWo5cwHmF0,337
5
5
  gllm_inference/builder/__init__.pyi,sha256=usz2lvfwO4Yk-ZGKXbCWG1cEr3nlQXxMNDNC-2yc1NM,500
@@ -77,7 +77,11 @@ gllm_inference/output_parser/__init__.pyi,sha256=WQOOgsYnPk8vd-SOhFMMaVTzy4gkYrO
77
77
  gllm_inference/output_parser/json_output_parser.pyi,sha256=uulh91uQLMSb4ZXZhHYi9W9w7zGnmrOweEkL6wdDJN8,2933
78
78
  gllm_inference/output_parser/output_parser.pyi,sha256=Yzk7F26pH8Uc7FQZo4G6l67YkfppefUvaV9cNK-HyDs,948
79
79
  gllm_inference/prompt_builder/__init__.pyi,sha256=kshfBMvwIwiIvjxiGG5BrJZNvpPa8rhtkbHo5FPifBg,117
80
- gllm_inference/prompt_builder/prompt_builder.pyi,sha256=zDKN0JWn23DPM73sCe-qpXT4d32Izis94K5aNpzLaoM,3278
80
+ gllm_inference/prompt_builder/prompt_builder.pyi,sha256=VQaw8nE8SPK1nvVVB4YjeqZSazigNPuWvOEcgGji0W8,4557
81
+ gllm_inference/prompt_builder/format_strategy/__init__.pyi,sha256=QhORHac3ySOPmL9k9kmCKL70vtaUtwkZEtGoRNWNuA8,308
82
+ gllm_inference/prompt_builder/format_strategy/format_strategy.pyi,sha256=JSUl_7Ka08oDZPpslymkUa8pDzqNGIK2TlcVANspqrY,2273
83
+ gllm_inference/prompt_builder/format_strategy/jinja_format_strategy.pyi,sha256=IAezLUiKSJMaoDyleo8pFnFqq8rBM_Q-lNXuAGvwXhI,2225
84
+ gllm_inference/prompt_builder/format_strategy/string_format_strategy.pyi,sha256=E0r8x6NTVbPLUfbJBz75PW1n3Ong6bi1WNgxBD0FTM4,693
81
85
  gllm_inference/prompt_formatter/__init__.pyi,sha256=rTsjfRsT-y00qH67fPewMNPMN1fAO2y7DM9scR1ccm0,740
82
86
  gllm_inference/prompt_formatter/agnostic_prompt_formatter.pyi,sha256=c9mN4t8LXn79h8wq8DAeWYwMgmZGzXjP7EcjLpwfNZg,2018
83
87
  gllm_inference/prompt_formatter/huggingface_prompt_formatter.pyi,sha256=AJ-D11HBhTKBA1B5s0km_K1R6o5HD1yvdbGoL7SpGhI,2729
@@ -99,12 +103,12 @@ gllm_inference/realtime_chat/output_streamer/output_streamer.pyi,sha256=GPAw1wPS
99
103
  gllm_inference/request_processor/__init__.pyi,sha256=hVnfdNZnkTBJHnmLtN3Na4ANP0yK6AstWdIizVr2Apo,227
100
104
  gllm_inference/request_processor/lm_request_processor.pyi,sha256=VnYc8E3Iayyhw-rPnGPfTKuO3ohgFsS8HPrZJeyES5I,5889
101
105
  gllm_inference/request_processor/uses_lm_mixin.pyi,sha256=Yu0XPNuHxq1tWBviHTPw1oThojneFwGHepvGjBXxKQA,6382
102
- gllm_inference/schema/__init__.pyi,sha256=CSyh7FmQWkIasNderPd5xDptlu-CliGSzXbDV7j4KyA,2159
106
+ gllm_inference/schema/__init__.pyi,sha256=k6FIO3N5fKnGvUMNjQBUx-HiA5zZ3tHW5ezcMNiD9Z4,2205
103
107
  gllm_inference/schema/activity.pyi,sha256=JnO2hqj91P5Tc6qb4pbkEMrHer2u5owiCvhl-igcQKQ,2303
104
108
  gllm_inference/schema/attachment.pyi,sha256=jApuzjOHJDCz4lr4MlHzBgIndh559nbWu2Xp1fk3hso,3297
105
109
  gllm_inference/schema/code_exec_result.pyi,sha256=ZTHh6JtRrPIdQ059P1UAiD2L-tAO1_S5YcMsAXfJ5A0,559
106
110
  gllm_inference/schema/config.pyi,sha256=rAL_UeXyQeXVk1P2kqd8vFWOMwmKenfpQLtvMP74t9s,674
107
- gllm_inference/schema/enums.pyi,sha256=RkHW2GQisgHBvYQ928D6olpL6GYehv65g8uoiGVsWUM,1612
111
+ gllm_inference/schema/enums.pyi,sha256=mr7qfSbbwssEuqTNWcvw7CYiNWkKLuH1htbrIXekiVA,1759
108
112
  gllm_inference/schema/events.pyi,sha256=3dJtYRuofgFDW1-kqV7PQw0WVyraEYC9je8196K-Cf8,4934
109
113
  gllm_inference/schema/lm_input.pyi,sha256=A5pjz1id6tP9XRNhzQrbmzd66C_q3gzo0UP8rCemz6Q,193
110
114
  gllm_inference/schema/lm_output.pyi,sha256=1SZi6vIWvmrZlVQ59WeQUKO5VhKrLHsSRDYslEH9d7o,2435
@@ -121,7 +125,7 @@ gllm_inference/utils/io_utils.pyi,sha256=7kUTacHAVRYoemFUOjCH7-Qmw-YsQGd6rGYxjf_
121
125
  gllm_inference/utils/langchain.pyi,sha256=VluQiHkGigDdqLUbhB6vnXiISCP5hHqV0qokYY6dC1A,1164
122
126
  gllm_inference/utils/validation.pyi,sha256=toxBtRp-VItC_X7sNi-GDd7sjibBdWMrR0q01OI2D7k,385
123
127
  gllm_inference.build/.gitignore,sha256=aEiIwOuxfzdCmLZe4oB1JsBmCUxwG8x-u-HBCV9JT8E,1
124
- gllm_inference_binary-0.5.44.dist-info/METADATA,sha256=ioEKrM2Qov6BNbvcQnR_WCkCwW8jeN4KuZNfXCjZbw4,5716
125
- gllm_inference_binary-0.5.44.dist-info/WHEEL,sha256=WMelAR6z66VnlU3tu68fV-jM5qbG8iPyeTqaBcpU3pI,108
126
- gllm_inference_binary-0.5.44.dist-info/top_level.txt,sha256=FpOjtN80F-qVNgbScXSEyqa0w09FYn6301iq6qt69IQ,15
127
- gllm_inference_binary-0.5.44.dist-info/RECORD,,
128
+ gllm_inference_binary-0.5.45.dist-info/METADATA,sha256=6RduOcMdvkHJ5vP5HV2XDX2e5YKMWOFLajSFrJE121U,5716
129
+ gllm_inference_binary-0.5.45.dist-info/WHEEL,sha256=WMelAR6z66VnlU3tu68fV-jM5qbG8iPyeTqaBcpU3pI,108
130
+ gllm_inference_binary-0.5.45.dist-info/top_level.txt,sha256=FpOjtN80F-qVNgbScXSEyqa0w09FYn6301iq6qt69IQ,15
131
+ gllm_inference_binary-0.5.45.dist-info/RECORD,,