gllm-inference-binary 0.5.44__cp312-cp312-win_amd64.whl → 0.5.45__cp312-cp312-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.

Potentially problematic release.


This version of gllm-inference-binary might be problematic. Click here for more details.

@@ -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'
Binary file
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.cp312-win_amd64.pyd,sha256=Q7oLRTlk-18vMMIUjSlX8GLQULsaKg_IlryULhQekAQ,3666944
2
- gllm_inference.pyi,sha256=Ue4h4rmHxeDhBKu4Ofd6wTgDBxxsFhd_CxTCvtQgZpA,4898
1
+ gllm_inference.cp312-win_amd64.pyd,sha256=WB51YD639IbMobpkPfZxwf_tBpazCofUXe2LUcVMYWI,3734528
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=PncjVw-mkzcJ3ln1ohvVZGdJ-TD-VZy1Ygn4Va8Z7i0,350
5
5
  gllm_inference/builder/__init__.pyi,sha256=-bw1uDx7CAM7pkvjvb1ZXku9zXlQ7aEAyC83KIn3bz8,506
@@ -77,7 +77,11 @@ gllm_inference/output_parser/__init__.pyi,sha256=dhAeRTBxc6CfS8bhnHjbtrnyqJ1iyff
77
77
  gllm_inference/output_parser/json_output_parser.pyi,sha256=YtgQh8Uzy8W_Tgh8DfuR7VFFS7qvLEasiTwRfaGZZEU,2993
78
78
  gllm_inference/output_parser/output_parser.pyi,sha256=-Xu5onKCBDqShcO-VrQh5icqAmXdihGc3rkZxL93swg,975
79
79
  gllm_inference/prompt_builder/__init__.pyi,sha256=mPsbiafzSNHsgN-CuzjhgZpfXfi1pPC3_gdsq2p0EM4,120
80
- gllm_inference/prompt_builder/prompt_builder.pyi,sha256=ju52smKHT_Bh2EVMZBWe1Z0ZQjD5aPBDLI_xLaILcgo,3334
80
+ gllm_inference/prompt_builder/prompt_builder.pyi,sha256=67X0MXPRGb_Azifk5fM9lAsQX48rASsQk2gCPikqU5k,4626
81
+ gllm_inference/prompt_builder/format_strategy/__init__.pyi,sha256=BliNAdrN2yNoQt8muLe1IknuE78UDQys_3L_8_2Tn9E,312
82
+ gllm_inference/prompt_builder/format_strategy/format_strategy.pyi,sha256=Uay07qR0nMGbrOZ2twEyrIWYRKevBQL9ju_4fVfByyQ,2328
83
+ gllm_inference/prompt_builder/format_strategy/jinja_format_strategy.pyi,sha256=W8SdOPWPz_U355G8rQwiIQ0Ys78vomUBFEEZiz3AS5k,2270
84
+ gllm_inference/prompt_builder/format_strategy/string_format_strategy.pyi,sha256=Xbx8xAtj3AbgFuPY8A3OuC6MlwenjYm6OXnQwxAP45k,713
81
85
  gllm_inference/prompt_formatter/__init__.pyi,sha256=q5sPPrnoCf-4tMGowh7hXxs63uyWfaZyEI-wjLBTGsA,747
82
86
  gllm_inference/prompt_formatter/agnostic_prompt_formatter.pyi,sha256=qp4L3x7XK7oZaSYP8B4idewKpPioB4XELeKVV-dNi-Q,2067
83
87
  gllm_inference/prompt_formatter/huggingface_prompt_formatter.pyi,sha256=kH60A_3DnHd3BrqbgS_FqQTCTHIjC9BTsk6_FNgcZw8,2784
@@ -99,12 +103,12 @@ gllm_inference/realtime_chat/output_streamer/output_streamer.pyi,sha256=5P9NQ0aJ
99
103
  gllm_inference/request_processor/__init__.pyi,sha256=giEme2WFQhgyKiBZHhSet0_nKSCHwGy-_2p6NRzg0Zc,231
100
104
  gllm_inference/request_processor/lm_request_processor.pyi,sha256=0fy1HyILCVDw6y46E-7tLnQTRYx4ppeRMe0QP6t9Jyw,5990
101
105
  gllm_inference/request_processor/uses_lm_mixin.pyi,sha256=LYHq-zLoXEMel1LfVdYv7W3BZ8WtBLo_WWFjRf10Yto,6512
102
- gllm_inference/schema/__init__.pyi,sha256=cGEeGc5xDyfepbCi5r_c61VmS6VnWyvoRjjK7K13lLg,2177
106
+ gllm_inference/schema/__init__.pyi,sha256=Rv821pgyUUbcVhnGJ0CnXVWJMi2pgaglv6Pq4RHK7yE,2223
103
107
  gllm_inference/schema/activity.pyi,sha256=atrU4OwLesA9FEt1H7K3gsUWYNdOqpI5i2VdWkmo6cs,2367
104
108
  gllm_inference/schema/attachment.pyi,sha256=9zgAjGXBjLfzPGaKi68FMW6b5mXdEA352nDe-ynOSvY,3385
105
109
  gllm_inference/schema/code_exec_result.pyi,sha256=WQ-ARoGM9r6nyRX-A0Ro1XKiqrc9R3jRYXZpu_xo5S4,573
106
110
  gllm_inference/schema/config.pyi,sha256=NVmjQK6HipIE0dKSfx12hgIC0O-S1HEcAc-TWlXAF5A,689
107
- gllm_inference/schema/enums.pyi,sha256=zuKgBxcm0GXvyEZag3FAETFTG-uikgjGJ5QRoXluSZg,1675
111
+ gllm_inference/schema/enums.pyi,sha256=dN6FzT4zNbSfqVxmrl3hO7IIiP-Qy4lAP_tf4tp8dNI,1827
108
112
  gllm_inference/schema/events.pyi,sha256=iG3sFAhvek-fSJgmUE6nJ5M0XzSpRKKpJJiXyuB4Wq0,5058
109
113
  gllm_inference/schema/lm_input.pyi,sha256=HxQiZgY7zcXh_Dw8nK8LSeBTZEHMPZVwmPmnfgSsAbs,197
110
114
  gllm_inference/schema/lm_output.pyi,sha256=DIV8BiIOPaSnMKxzKzH_Mp7j7-MScWCvmllegJDLqFg,2479
@@ -121,7 +125,7 @@ gllm_inference/utils/io_utils.pyi,sha256=Eg7dvHWdXslTKdjh1j3dG50i7r35XG2zTmJ9XXv
121
125
  gllm_inference/utils/langchain.pyi,sha256=4AwFiVAO0ZpdgmqeC4Pb5NJwBt8vVr0MSUqLeCdTscc,1194
122
126
  gllm_inference/utils/validation.pyi,sha256=-RdMmb8afH7F7q4Ao7x6FbwaDfxUHn3hA3WiOgzB-3s,397
123
127
  gllm_inference.build/.gitignore,sha256=aEiIwOuxfzdCmLZe4oB1JsBmCUxwG8x-u-HBCV9JT8E,1
124
- gllm_inference_binary-0.5.44.dist-info/METADATA,sha256=k03CIyjygon71qyD5--ATKsmuR5bi1IZyMotR-Gyqes,5852
125
- gllm_inference_binary-0.5.44.dist-info/WHEEL,sha256=x5rgv--I0NI0IT1Lh9tN1VG2cI637p3deednwYLKnxc,96
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=RLBqUxp1nnQSWcpsyb5R3g0PWAmQ3Q5k4fQl8jLjJIs,5852
129
+ gllm_inference_binary-0.5.45.dist-info/WHEEL,sha256=x5rgv--I0NI0IT1Lh9tN1VG2cI637p3deednwYLKnxc,96
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,,