banks 2.1.1__py3-none-any.whl → 2.1.3__py3-none-any.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.
banks/__about__.py CHANGED
@@ -1,4 +1,4 @@
1
1
  # SPDX-FileCopyrightText: 2023-present Massimiliano Pippi <mpippi@gmail.com>
2
2
  #
3
3
  # SPDX-License-Identifier: MIT
4
- __version__ = "2.1.1"
4
+ __version__ = "2.1.3"
banks/extensions/chat.py CHANGED
@@ -1,7 +1,6 @@
1
1
  # SPDX-FileCopyrightText: 2023-present Massimiliano Pippi <mpippi@gmail.com>
2
2
  #
3
3
  # SPDX-License-Identifier: MIT
4
- import re
5
4
 
6
5
  from jinja2 import TemplateSyntaxError, nodes
7
6
  from jinja2.ext import Extension
@@ -9,7 +8,6 @@ from jinja2.ext import Extension
9
8
  from banks.types import chat_message_from_text
10
9
 
11
10
  SUPPORTED_TYPES = ("system", "user", "assistant")
12
- CONTENT_BLOCK_REGEX = re.compile(r"<content_block>((?s:.)*)<\/content_block>")
13
11
 
14
12
 
15
13
  class ChatExtension(Extension):
@@ -52,8 +50,8 @@ class ChatExtension(Extension):
52
50
  raise TemplateSyntaxError(error_msg, lineno)
53
51
 
54
52
  if attr_value.value not in SUPPORTED_TYPES:
55
- types = ",".join(SUPPORTED_TYPES)
56
- msg = f"Unknown role type '{attr_value}', use one of ({types})"
53
+ types = ", ".join(SUPPORTED_TYPES)
54
+ msg = f"Unknown role type '{attr_value.value}', use one of ({types})"
57
55
  raise TemplateSyntaxError(msg, lineno)
58
56
 
59
57
  # Pass the role name to the CallBlock node
@@ -27,7 +27,7 @@ DEFAULT_INDEX_NAME = "index.json"
27
27
  class PromptFile(PromptModel):
28
28
  """Model representing a prompt file stored on disk."""
29
29
 
30
- path: Path = Field(exclude=True)
30
+ path: Path | None = Field(default=None, exclude=True)
31
31
 
32
32
  @classmethod
33
33
  def from_prompt_path(cls: type[Self], prompt: Prompt, path: Path) -> Self:
@@ -101,7 +101,7 @@ class DirectoryPromptRegistry:
101
101
  """
102
102
  version = version or DEFAULT_VERSION
103
103
  for pf in self._index.files:
104
- if pf.name == name and pf.version == version and pf.path.exists():
104
+ if pf.name == name and pf.version == version and pf.path and pf.path.exists():
105
105
  return Prompt(**pf.model_dump())
106
106
  raise PromptNotFoundError
107
107
 
@@ -135,6 +135,10 @@ class DirectoryPromptRegistry:
135
135
  def _load(self):
136
136
  """Load the prompt index from disk."""
137
137
  self._index = PromptFileIndex.model_validate_json(self._index_path.read_text())
138
+ # Reconstruct the file paths since they're excluded from serialization
139
+ for pf in self._index.files:
140
+ if pf.path is None:
141
+ pf.path = self._path / f"{pf.name}.{pf.version}.jinja"
138
142
 
139
143
  def _save(self):
140
144
  """Save the prompt index to disk."""
banks/types.py CHANGED
@@ -16,7 +16,7 @@ from typing_extensions import Self
16
16
  from .utils import parse_params_from_docstring, python_type_to_jsonschema
17
17
 
18
18
  # pylint: disable=invalid-name
19
- CONTENT_BLOCK_REGEX = re.compile(r"(<content_block>\{.*?\}<\/content_block>)|([^<](?:(?!<content_block>).)*)")
19
+ CONTENT_BLOCK_REGEX = re.compile(r"(<content_block>\{.*?\}<\/content_block>)|([^<](?:(?!<content_block>)[\s\S])*)")
20
20
 
21
21
 
22
22
  class ContentBlockType(str, Enum):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: banks
3
- Version: 2.1.1
3
+ Version: 2.1.3
4
4
  Summary: A prompt programming language
5
5
  Project-URL: Documentation, https://github.com/masci/banks#readme
6
6
  Project-URL: Issues, https://github.com/masci/banks/issues
@@ -123,8 +123,14 @@ print(p.chat_messages({"persona": "helpful assistant"}))
123
123
 
124
124
  # Output:
125
125
  # [
126
- # ChatMessage(role='system', content='You are a helpful assistant.\n'),
127
- # ChatMessage(role='user', content='Hello, how are you?\n')
126
+ # ChatMessage(role='system', content=[
127
+ # ContentBlock(type=<ContentBlockType.text: 'text'>, cache_control=None, text='You are a helpful assistant.',
128
+ # image_url=None, input_audio=None)
129
+ # ], tool_call_id=None, name=None),
130
+ # ChatMessage(role='user', content=[
131
+ # ContentBlock(type=<ContentBlockType.text: 'text'>, cache_control=None, text='Hello, how are you?',
132
+ # image_url=None, input_audio=None)
133
+ # ], tool_call_id=None, name=None)
128
134
  # ]
129
135
  ```
130
136
 
@@ -1,14 +1,14 @@
1
- banks/__about__.py,sha256=S57kL24mDlNkjLlC1XN2yFEPPClI55FfNyJjlqC8_Fw,132
1
+ banks/__about__.py,sha256=GetPXxJYXnTH5Y2Q50FaMRs7TJ2tkq34MorPa-qCNpc,132
2
2
  banks/__init__.py,sha256=4IBopxXstFZliCvSjOuTurSQb32Vy26EXOPhmNZ4Hus,334
3
3
  banks/cache.py,sha256=uUGAu82-mfrscc2q24x19ZMZBkoQzf3hh7_V300J-Ik,1069
4
4
  banks/config.py,sha256=c6B1cXUZ-NN0XmJvfezXeHPXHP7knk8TfbmcZL7gCzk,1082
5
5
  banks/env.py,sha256=PBSz-iH_E3_KYofAfsQZLrYMZXVLNJLxgSFD7GB1Xd0,1233
6
6
  banks/errors.py,sha256=I5cgsa7wtolRVKBSq_aH5xs27yVcErBlMyUswCnM-es,580
7
7
  banks/prompt.py,sha256=RhPq3wpE-AiCfCftZpPFj2HXGdazwYD502Pr1e-j7FY,8162
8
- banks/types.py,sha256=R53mLqmTm9HoDJDfRP4mjfpORthkKJbn-6kxudsi_bw,5515
8
+ banks/types.py,sha256=03x7E7FPVfuN39xY--c0fKumnyVUVzNrq9pgG5R-pAU,5520
9
9
  banks/utils.py,sha256=ZetGG3qhXMYOitDZQCWbE33wHEqR0ih2ZEg_dIW8OeI,1827
10
10
  banks/extensions/__init__.py,sha256=Lx4UrOzywYQY7a8qvIqvc3ql54nwK0lNP7x3jYdbREY,110
11
- banks/extensions/chat.py,sha256=3eGsvtBxcaXwjCNiaKVgVc7HN8p1p9CIAGgqlt9F_-U,2560
11
+ banks/extensions/chat.py,sha256=VV6UV1wQZcJ0KbIFHSFmDeptWtww4o2IXF5pXB6TpTM,2478
12
12
  banks/extensions/completion.py,sha256=kF55PiNxjqpslUTAd46H4jOy0eFiLLm5hEcwxS4_oxs,7356
13
13
  banks/extensions/docs.py,sha256=vWOZvu2JoS4LwUG-BR3jPqThirYvu3Fdba331UxooYM,1098
14
14
  banks/filters/__init__.py,sha256=LV4mtTYkmLPo0OST8PMhJJmyC8azZJgU-ZKtpAVU1_0,325
@@ -18,10 +18,10 @@ banks/filters/image.py,sha256=cxp_Tlqy-DQ1y3I6IyO6TwM7KkdP8aL_xEKcSqeWX1w,1140
18
18
  banks/filters/lemmatize.py,sha256=Yvp8M4HCx6C0nrcu3UEMtjJUwsyVYI6GQDYOG4S6EEw,887
19
19
  banks/filters/tool.py,sha256=i8ukSDYw54ksShVJ2abfRQAiKzKrqUtmgBB1H04cig0,475
20
20
  banks/registries/__init__.py,sha256=iRK-8420cKBckOTd5KcIFQyV66EsF0Mc7UHCkzf8qZU,255
21
- banks/registries/directory.py,sha256=WXVL8gIrH2OqDYcC89TuTW-iXSwT9WqJq_OWe_kYC2Q,5803
21
+ banks/registries/directory.py,sha256=gRFO7fl9yXHt2NJ1pDA2wPSQtlORhSw1GKWxSTyFzE8,6055
22
22
  banks/registries/file.py,sha256=8ayvFrcM8Tk0DWgGXmKD2DRBfGXr5CmgtdQaQ5cXhow,4054
23
23
  banks/registries/redis.py,sha256=eBL92URJa-NegOxRLS4b2xrDRDxz6iiaz_7Ddi32Rtc,2756
24
- banks-2.1.1.dist-info/METADATA,sha256=cMavPBlQKZ02YwJ77whxc8UvBw0u7pDSP723SkF1y30,11749
25
- banks-2.1.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
26
- banks-2.1.1.dist-info/licenses/LICENSE.txt,sha256=NZJne_JTwMFwq_g-kq-sm4PuaeVOgu1l3NUGOgBHX-g,1102
27
- banks-2.1.1.dist-info/RECORD,,
24
+ banks-2.1.3.dist-info/METADATA,sha256=TL6VlzchrWjdEduPj_aHzVKJts7peXbug1CUaogpPbo,12098
25
+ banks-2.1.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
26
+ banks-2.1.3.dist-info/licenses/LICENSE.txt,sha256=NZJne_JTwMFwq_g-kq-sm4PuaeVOgu1l3NUGOgBHX-g,1102
27
+ banks-2.1.3.dist-info/RECORD,,
File without changes