fabricatio 0.2.0.dev9__cp312-cp312-win_amd64.whl → 0.2.0.dev10__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.
fabricatio/__init__.py CHANGED
@@ -1,5 +1,7 @@
1
1
  """Fabricatio is a Python library for building llm app using event-based agent structure."""
2
2
 
3
+ from fabricatio._rust import TemplateManager
4
+ from fabricatio.config import configs
3
5
  from fabricatio.core import env
4
6
  from fabricatio.fs import magika
5
7
  from fabricatio.journal import logger
@@ -10,7 +12,8 @@ from fabricatio.models.task import Task
10
12
  from fabricatio.models.tool import ToolBox
11
13
  from fabricatio.models.utils import Message, Messages
12
14
  from fabricatio.parser import Capture, CodeBlockCapture, JsonCapture, PythonCapture
13
- from fabricatio.templates import templates_manager
15
+
16
+ template_manager = TemplateManager(configs.code2prompt.template_dir)
14
17
 
15
18
  __all__ = [
16
19
  "Action",
@@ -28,5 +31,5 @@ __all__ = [
28
31
  "env",
29
32
  "logger",
30
33
  "magika",
31
- "templates_manager",
34
+ "template_manager"
32
35
  ]
Binary file
fabricatio/_rust.pyi CHANGED
@@ -1 +1,53 @@
1
- def download_templates() -> None: ...
1
+ from pathlib import Path
2
+ from typing import Dict, List, Any
3
+
4
+
5
+ class TemplateManager:
6
+ def __init__(self, template_dirs: List[Path]) -> None:
7
+ """
8
+ Initialize the template manager.
9
+ Args:
10
+ template_dirs (List[Path]): A list of paths to directories containing templates.
11
+ """
12
+
13
+ @property
14
+ def template_count(self) -> int:
15
+ """Get the number of templates discovered."""
16
+
17
+ @property
18
+ def templates(self) -> List[str]:
19
+ """Get a list of template names."""
20
+
21
+ def get_template(self, name: str) -> str:
22
+ """
23
+ Get a template by name.
24
+ Args:
25
+ name (str): The name of the template to retrieve.
26
+
27
+ Returns:
28
+ str: The template content.
29
+ """
30
+
31
+ def get_template_source(self, name: str) -> str:
32
+ """
33
+ Get the source path of a template by name.
34
+ Args:
35
+ name (str): The name of the template to retrieve.
36
+
37
+ Returns:
38
+ str: The source path of the template.
39
+ """
40
+
41
+ def discover_templates(self) -> None:
42
+ """Discover templates in the specified directories."""
43
+
44
+ def render_template(self, name: str, data: Dict[str, Any]) -> str:
45
+ """
46
+ Render a template with the given name and data.
47
+ Args:
48
+ name (str): The name of the template to render.
49
+ data (Dict[str, Any]): The data to pass to the template.
50
+
51
+ Returns:
52
+ str: The rendered template.
53
+ """
fabricatio/config.py CHANGED
@@ -1,6 +1,5 @@
1
1
  """Configuration module for the Fabricatio application."""
2
2
 
3
- from pathlib import Path
4
3
  from typing import List, Literal, Optional
5
4
 
6
5
  from appdirs import user_config_dir
@@ -122,7 +121,7 @@ class Code2PromptConfig(BaseModel):
122
121
 
123
122
  model_config = ConfigDict(use_attribute_docstrings=True)
124
123
  template_dir: List[DirectoryPath] = Field(
125
- default_factory=lambda: [Path(r".\templates"), Path(rf"{ROAMING_DIR}\templates")]
124
+ default_factory=lambda: [DirectoryPath(r".\templates"), DirectoryPath(rf"{ROAMING_DIR}\templates")]
126
125
  )
127
126
  """The directory containing the templates for code2prompt."""
128
127
 
@@ -176,12 +175,12 @@ class Settings(BaseSettings):
176
175
 
177
176
  @classmethod
178
177
  def settings_customise_sources(
179
- cls,
180
- settings_cls: type[BaseSettings],
181
- init_settings: PydanticBaseSettingsSource,
182
- env_settings: PydanticBaseSettingsSource,
183
- dotenv_settings: PydanticBaseSettingsSource,
184
- file_secret_settings: PydanticBaseSettingsSource,
178
+ cls,
179
+ settings_cls: type[BaseSettings],
180
+ init_settings: PydanticBaseSettingsSource,
181
+ env_settings: PydanticBaseSettingsSource,
182
+ dotenv_settings: PydanticBaseSettingsSource,
183
+ file_secret_settings: PydanticBaseSettingsSource,
185
184
  ) -> tuple[PydanticBaseSettingsSource, ...]:
186
185
  """Customize settings sources.
187
186
 
fabricatio/core.py CHANGED
@@ -38,11 +38,11 @@ class Env(BaseModel):
38
38
 
39
39
  @overload
40
40
  def on[**P, R](
41
- self,
42
- event: str | Event,
43
- func: Optional[Callable[P, R]] = None,
44
- /,
45
- ttl: int = -1,
41
+ self,
42
+ event: str | Event,
43
+ func: Optional[Callable[P, R]] = None,
44
+ /,
45
+ ttl: int = -1,
46
46
  ) -> Callable[[Callable[P, R]], Callable[P, R]]:
47
47
  """
48
48
  Registers an event listener with a specific function that listens indefinitely or for a specified number of times.
@@ -58,11 +58,11 @@ class Env(BaseModel):
58
58
  ...
59
59
 
60
60
  def on[**P, R](
61
- self,
62
- event: str | Event,
63
- func: Optional[Callable[P, R]] = None,
64
- /,
65
- ttl=-1,
61
+ self,
62
+ event: str | Event,
63
+ func: Optional[Callable[P, R]] = None,
64
+ /,
65
+ ttl=-1,
66
66
  ) -> Callable[[Callable[P, R]], Callable[P, R]] | Self:
67
67
  """Registers an event listener with a specific function that listens indefinitely or for a specified number of times.
68
68
 
@@ -84,8 +84,8 @@ class Env(BaseModel):
84
84
 
85
85
  @overload
86
86
  def once[**P, R](
87
- self,
88
- event: str | Event,
87
+ self,
88
+ event: str | Event,
89
89
  ) -> Callable[[Callable[P, R]], Callable[P, R]]:
90
90
  """
91
91
  Registers an event listener that listens only once.
@@ -100,9 +100,9 @@ class Env(BaseModel):
100
100
 
101
101
  @overload
102
102
  def once[**P, R](
103
- self,
104
- event: str | Event,
105
- func: Callable[[Callable[P, R]], Callable[P, R]],
103
+ self,
104
+ event: str | Event,
105
+ func: Callable[[Callable[P, R]], Callable[P, R]],
106
106
  ) -> Self:
107
107
  """
108
108
  Registers an event listener with a specific function that listens only once.
@@ -117,9 +117,9 @@ class Env(BaseModel):
117
117
  ...
118
118
 
119
119
  def once[**P, R](
120
- self,
121
- event: str | Event,
122
- func: Optional[Callable[P, R]] = None,
120
+ self,
121
+ event: str | Event,
122
+ func: Optional[Callable[P, R]] = None,
123
123
  ) -> Callable[[Callable[P, R]], Callable[P, R]] | Self:
124
124
  """Registers an event listener with a specific function that listens only once.
125
125
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fabricatio
3
- Version: 0.2.0.dev9
3
+ Version: 0.2.0.dev10
4
4
  Classifier: License :: OSI Approved :: MIT License
5
5
  Classifier: Programming Language :: Python :: 3.12
6
6
  Classifier: Programming Language :: Python :: Implementation :: CPython
@@ -1,11 +1,11 @@
1
- fabricatio-0.2.0.dev9.dist-info/METADATA,sha256=paLytbkKVJeWwomMQqT24YeNdNewGZl0G2EJCUigS_w,5970
2
- fabricatio-0.2.0.dev9.dist-info/WHEEL,sha256=tpW5AN9B-9qsM9WW2FXG2r193YXiqexDadpKp0A2daI,96
3
- fabricatio-0.2.0.dev9.dist-info/licenses/LICENSE,sha256=do7J7EiCGbq0QPbMAL_FqLYufXpHnCnXBOuqVPwSV8Y,1088
1
+ fabricatio-0.2.0.dev10.dist-info/METADATA,sha256=dNWLPv66ZRGHyczv0HrHrih837C8eg8MrWnZa6aPKSk,5971
2
+ fabricatio-0.2.0.dev10.dist-info/WHEEL,sha256=tpW5AN9B-9qsM9WW2FXG2r193YXiqexDadpKp0A2daI,96
3
+ fabricatio-0.2.0.dev10.dist-info/licenses/LICENSE,sha256=do7J7EiCGbq0QPbMAL_FqLYufXpHnCnXBOuqVPwSV8Y,1088
4
4
  fabricatio/actions/communication.py,sha256=tmsr3H_w-V-b2WxLEyWByGuwSCLgHIHTdHYAgHrdUxc,425
5
5
  fabricatio/actions/transmission.py,sha256=PedZ6XsflKdT5ikzaqWr_6h8jci0kekAHfwygzKBUns,1188
6
6
  fabricatio/actions/__init__.py,sha256=eFmFVPQvtNgFynIXBVr3eP-vWQDWCPng60YY5LXvZgg,115
7
- fabricatio/config.py,sha256=FspRwp_gpms_b1rnTgGm5TBkBmG1avEapcxO4Jq6gdc,8041
8
- fabricatio/core.py,sha256=aaQDGz7spEeJtI2SVSXox4jnMrkLfzEfQDh7mIgoQmQ,5866
7
+ fabricatio/config.py,sha256=wArRP1n3QIRwGjZOgAezdYwMYqhsrxz3D_biXAZjB28,8057
8
+ fabricatio/core.py,sha256=yQK2ZrbPYDJOaNDp0Bky3muTkB-ZaQ1ld_Qfflm2dY0,5938
9
9
  fabricatio/decorators.py,sha256=Qsyb-_cDwtXY5yhyLrYZEAlrHh5ZuEooQ8vEOUAxj8k,1855
10
10
  fabricatio/fs/readers.py,sha256=mw0VUH3P7Wk0SMlcQm2yOfjEz5C3mQ_kjduAjecaxgY,123
11
11
  fabricatio/fs/__init__.py,sha256=lWcKYg0v3mv2LnnSegOQaTtlVDODU0vtw_s6iKU5IqQ,122
@@ -19,11 +19,10 @@ fabricatio/models/tool.py,sha256=3htDwksf4k6JfYRY3RYirjvcpZUqwj5BNB7DO0nGBN0,339
19
19
  fabricatio/models/utils.py,sha256=i_kpcQpct04mQFk1nbcVGV-pl1YThWu4Qk3wbewzKkc,2535
20
20
  fabricatio/parser.py,sha256=eIdpGBUKHAAWaWEu3NP_7zwgsxHoXIMVaHUAlSjQ6ko,2424
21
21
  fabricatio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
- fabricatio/templates.py,sha256=rmt1cf66wDTjK_LSeATv60eWX2jYO97uAX2yB_Zwtxw,1615
23
22
  fabricatio/toolboxes/task.py,sha256=xgyPetm2R_HlQwpzE8YPnBN7QOYLd0-T8E6QPZG1PPQ,204
24
23
  fabricatio/toolboxes/__init__.py,sha256=bjefmPd7wBaWhbZzdMPXvrjMTeRzlUh_Dev2PUAc124,158
25
- fabricatio/_rust.pyi,sha256=FZ9noKJQrdhxq0S9LJYy7BvZnShnDrupDeOv-PpliI4,39
26
- fabricatio/__init__.py,sha256=eznZiLDVe3pw0NwX36Rari-DK0zxDTpa_wwAmWGnto8,909
27
- fabricatio/_rust.cp312-win_amd64.pyd,sha256=Kfuyc7ZyGG4h5y2pLb39JJp6wqz-NxkI6eZw6gn14ew,174592
28
- fabricatio-0.2.0.dev9.data/scripts/tdown.exe,sha256=GllIge9Vde1YlvBu_vsyXI8df8VD12LzHdl5wi5O1OQ,3380736
29
- fabricatio-0.2.0.dev9.dist-info/RECORD,,
24
+ fabricatio/_rust.pyi,sha256=IHNv9SHdjve24PBWhdRGCqWYdo2tSAkxYR9CddHhzX8,1540
25
+ fabricatio/__init__.py,sha256=fop9UtHY_FGoqjtiHHREXFqO5vUrbc9vnm0wgLgZC8I,1012
26
+ fabricatio/_rust.cp312-win_amd64.pyd,sha256=-TbjfckvcCu7xmWpbgRQGpr8Y6vModoVFOjWWX6s5x8,1123840
27
+ fabricatio-0.2.0.dev10.data/scripts/tdown.exe,sha256=5pJQDhralWahKr5r84HeLW02DyG2K2kXidUQFzw9h38,3387904
28
+ fabricatio-0.2.0.dev10.dist-info/RECORD,,
fabricatio/templates.py DELETED
@@ -1,41 +0,0 @@
1
- """A module that manages templates for code generation."""
2
-
3
- from typing import Any, Dict, List, Self
4
-
5
- from pydantic import BaseModel, ConfigDict, DirectoryPath, Field, FilePath, PrivateAttr
6
-
7
- from fabricatio.config import configs
8
- from fabricatio.journal import logger
9
-
10
-
11
- class TemplateManager(BaseModel):
12
- """A class that manages templates for code generation."""
13
-
14
- model_config = ConfigDict(use_attribute_docstrings=True)
15
- templates_dir: List[DirectoryPath] = Field(default_factory=lambda: list(configs.code2prompt.template_dir))
16
- """The directories containing the templates. first element has the highest override priority."""
17
- _discovered_templates: Dict[str, FilePath] = PrivateAttr(default_factory=dict)
18
-
19
- def model_post_init(self, __context: Any) -> None:
20
- """Post-initialization method for the model."""
21
- self.discover_templates()
22
-
23
- def discover_templates(self) -> Self:
24
- """Discover the templates in the template directories."""
25
- discovered = [
26
- f
27
- for d in self.templates_dir[::-1]
28
- for f in d.rglob(f"*{configs.code2prompt.template_suffix}", case_sensitive=False)
29
- if f.is_file()
30
- ]
31
-
32
- self._discovered_templates = {f.stem: f for f in discovered}
33
- logger.info(f"Discovered {len(self._discovered_templates)} templates.")
34
- return self
35
-
36
- def get_template(self, name: str) -> FilePath | None:
37
- """Get the template with the specified name."""
38
- return self._discovered_templates.get(name, None)
39
-
40
-
41
- templates_manager = TemplateManager()