You need to sign in or sign up before continuing.

fabricatio 0.2.0.dev9__cp312-cp312-manylinux_2_34_x86_64.whl → 0.2.0.dev11__cp312-cp312-manylinux_2_34_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.
fabricatio/__init__.py CHANGED
@@ -1,5 +1,6 @@
1
1
  """Fabricatio is a Python library for building llm app using event-based agent structure."""
2
2
 
3
+ from fabricatio._rust_instances import template_manager
3
4
  from fabricatio.core import env
4
5
  from fabricatio.fs import magika
5
6
  from fabricatio.journal import logger
@@ -10,7 +11,6 @@ from fabricatio.models.task import Task
10
11
  from fabricatio.models.tool import ToolBox
11
12
  from fabricatio.models.utils import Message, Messages
12
13
  from fabricatio.parser import Capture, CodeBlockCapture, JsonCapture, PythonCapture
13
- from fabricatio.templates import templates_manager
14
14
 
15
15
  __all__ = [
16
16
  "Action",
@@ -28,5 +28,5 @@ __all__ = [
28
28
  "env",
29
29
  "logger",
30
30
  "magika",
31
- "templates_manager",
31
+ "template_manager"
32
32
  ]
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
+ """
@@ -0,0 +1,4 @@
1
+ from fabricatio._rust import TemplateManager
2
+ from fabricatio.config import configs
3
+
4
+ template_manager = TemplateManager(configs.code2prompt.template_dir)
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
 
fabricatio/models/task.py CHANGED
@@ -7,6 +7,7 @@ from asyncio import Queue
7
7
  from enum import Enum
8
8
  from typing import Any, List, Optional, Self
9
9
 
10
+ from fabricatio._rust_instances import template_manager
10
11
  from fabricatio.core import env
11
12
  from fabricatio.journal import logger
12
13
  from fabricatio.models.events import Event, EventLike
@@ -273,11 +274,12 @@ class ProposeTask(LLMUsage, WithBriefing):
273
274
  logger.error(f"Failed to parse task from JSON: {e}")
274
275
  return None
275
276
 
277
+ template_data = {
278
+ "prompt": prompt,
279
+ "json_example": Task.json_example()
280
+ }
276
281
  return await self.aask_validate(
277
- f"{prompt} \n\nBased on requirement above, "
278
- f"you need to construct a task to satisfy that requirement in JSON format "
279
- f"written like this: \n\n```json\n{Task.json_example()}\n```\n\n"
280
- f"No extra explanation needed. ",
282
+ template_manager.render_template("propose_task", template_data),
281
283
  _validate_json,
282
284
  system_message=f"# your personal briefing: \n{self.briefing}",
283
285
  )
@@ -1,7 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fabricatio
3
- Version: 0.2.0.dev9
3
+ Version: 0.2.0.dev11
4
4
  Classifier: License :: OSI Approved :: MIT License
5
+ Classifier: Programming Language :: Rust
5
6
  Classifier: Programming Language :: Python :: 3.12
6
7
  Classifier: Programming Language :: Python :: Implementation :: CPython
7
8
  Classifier: Framework :: AsyncIO
@@ -23,7 +24,7 @@ Requires-Dist: regex>=2024.11.6
23
24
  Requires-Dist: rich>=13.9.4
24
25
  License-File: LICENSE
25
26
  Summary: A LLM multi-agent framework.
26
- Keywords: ai,agents,multi-agent,llm
27
+ Keywords: ai,agents,multi-agent,llm,pyo3
27
28
  Author-email: Whth <zettainspector@foxmail.com>
28
29
  Requires-Python: >=3.12
29
30
  Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
@@ -1,29 +1,29 @@
1
- fabricatio-0.2.0.dev9.dist-info/METADATA,sha256=I7x3HxGkHVT7mHN5FsLmHIkuFQ5R1XMdAH-k0V_rtOA,5777
2
- fabricatio-0.2.0.dev9.dist-info/WHEEL,sha256=RIvmwLDYujv60MYBx2jxyP4vdn1DD7X0kBgz1TQvZuc,108
3
- fabricatio-0.2.0.dev9.dist-info/licenses/LICENSE,sha256=yDZaTLnOi03bi3Dk6f5IjhLUc5old2yOsihHWU0z-i0,1067
1
+ fabricatio-0.2.0.dev11.dist-info/METADATA,sha256=5XdMpp40bDU_ulMm0r4EfK6wTERGc1Uiz56lzpIMCPM,5824
2
+ fabricatio-0.2.0.dev11.dist-info/WHEEL,sha256=RIvmwLDYujv60MYBx2jxyP4vdn1DD7X0kBgz1TQvZuc,108
3
+ fabricatio-0.2.0.dev11.dist-info/licenses/LICENSE,sha256=yDZaTLnOi03bi3Dk6f5IjhLUc5old2yOsihHWU0z-i0,1067
4
4
  fabricatio/fs/__init__.py,sha256=bYE9r8uR0dtknzbg_YaGv_6Wwa27ntkQt0Tl7Kb3HFI,117
5
5
  fabricatio/fs/readers.py,sha256=E219Pef7gknltkHjL9iZXwjI841_EPFpNvDG9KBUG3g,118
6
6
  fabricatio/toolboxes/__init__.py,sha256=8gd8yPhhQBO0A37w1zqVLfbOG-pyCPrveEtO0MX042A,151
7
7
  fabricatio/toolboxes/task.py,sha256=G_nNYT8Sy5ll6YmXES458MUmgJnDSBNwlozyJewdnzY,200
8
- fabricatio/__init__.py,sha256=EVT4wvmRYDmYMTME_ZWb6U39Kbt5grAtMxfaH3faNXc,877
9
- fabricatio/core.py,sha256=r7qjG-ACFGgOsiPjWStlNWb0oRnIVvO5MEfMoagiVT8,5699
10
- fabricatio/config.py,sha256=434wpWNzzmBnLxsj07l7xp7YTUc1--SzdOhQIXE0tuw,7835
8
+ fabricatio/__init__.py,sha256=5z3QgwOGRzH7EIxKNWsZ_A6Ytfcu23nl-r6prZ-Z4cw,880
9
+ fabricatio/core.py,sha256=apwXgI94DCWpGujGlsmXsTZQvJOQMB9llmuUo7ohd-4,5771
10
+ fabricatio/config.py,sha256=Or_PzOzXy_4Rqje1r788sID4bxILXhNC3r7eelcZJy0,7852
11
11
  fabricatio/decorators.py,sha256=Y2F5JuN3K5Pas_JPBLQrB_Np0s1U8k2lPvrdtCHtcRE,1799
12
12
  fabricatio/journal.py,sha256=u6YTKrD9EoebbR8guvAe5zSqWV1nS-BGyKxZR_Sw2ik,684
13
- fabricatio/templates.py,sha256=wXEdFlWSP5SAFivDEr8nkvPkcjGTipdpKkwzJcRHANc,1574
14
13
  fabricatio/models/generic.py,sha256=1S5guUWnHSpoyNi1D1t4q14e6YNIovI4Goc3kizHd8M,15698
15
14
  fabricatio/models/action.py,sha256=PNcm4t34fSaI03ECIOZ8ezvB6PlZkNhJtZFEhtU0Gec,4916
16
- fabricatio/models/task.py,sha256=W66bRf6au6ysS_ypZ3i4W1mL-WhotfvbhbjX-3CrBj4,9146
15
+ fabricatio/models/task.py,sha256=Li66mMYM4xF3vGH0FHNZv02YQ2KhcU67CSTTcqTrGVU,9124
17
16
  fabricatio/models/role.py,sha256=1vhpHRKJ6f7PDBLl6jYRZbxTJyrVhNN3FEEh_HAwU3o,990
18
17
  fabricatio/models/tool.py,sha256=jzH34UHIgqEwYdXOQ3Jz_TN0cyj_jLTVBVs0qGl9tQU,3299
19
18
  fabricatio/models/events.py,sha256=S0E7l5iQoJYdUn0pSSziHdXqPzIvvLy8ifVPQxXeAho,2570
20
19
  fabricatio/models/utils.py,sha256=u-eR_v-o0BSFSmCprP3mOyAO-WOyg_P68jjzLjyit_w,2457
21
20
  fabricatio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
+ fabricatio/_rust_instances.py,sha256=c3aB95D7qKrA1AxDHD94lYinklAmK5EL6_DDJUEzPB0,153
22
22
  fabricatio/actions/__init__.py,sha256=eLa_5ACZ-FqdrLtOfCHk5nQBxzhIs1kgMIXWmkm2P8Y,110
23
23
  fabricatio/actions/communication.py,sha256=4hNzyv5_j4HU291dDuBmBEb66VihQPI9SLRVZrxWu1Y,412
24
24
  fabricatio/actions/transmission.py,sha256=gLLKoi4keL64uaEkHDxwVrBGciheupQrO2fW3GkjfEw,1156
25
- fabricatio/_rust.pyi,sha256=yvIFCtXH7p5F-1OA4k1diSTlhpDAShdOoFzRxh9LLtY,38
25
+ fabricatio/_rust.pyi,sha256=EwMPoCZFOCYZ5h_9PZLvO3YrgBEG0Hwae0ux0hcBabM,1487
26
26
  fabricatio/parser.py,sha256=2wFvkyAIlFyB_dj8txr6shc-0ik5cz0mUy_Yj_GrqcI,2355
27
- fabricatio/_rust.cpython-312-x86_64-linux-gnu.so,sha256=zlsqjtyM4uvxykIZOW5JG1RUVCbhC7nlpxzaUgUdB2E,402344
28
- fabricatio-0.2.0.dev9.data/scripts/tdown,sha256=o5p_FBwrVaRyVry-j3_mYbFLQg5wWcUC4_i-_P7eda8,4527456
29
- fabricatio-0.2.0.dev9.dist-info/RECORD,,
27
+ fabricatio/_rust.cpython-312-x86_64-linux-gnu.so,sha256=zSQ7Y-Hp7TDAzKenBEEWirLdaVturuUyGbNn1oXtRYs,1191136
28
+ fabricatio-0.2.0.dev11.data/scripts/tdown,sha256=jyItwd3z9dBoOT6EEA3niK0e7AXhhBnL87-T0IBRkYk,4540840
29
+ fabricatio-0.2.0.dev11.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()