fabricatio 0.2.11.dev2__cp312-cp312-win_amd64.whl → 0.2.11.dev3__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.
@@ -149,10 +149,10 @@ class GenerateInitialOutline(Action, Extract):
149
149
  async def _execute(
150
150
  self,
151
151
  article_proposal: ArticleProposal,
152
+ supervisor: Optional[bool] = None,
152
153
  **_,
153
154
  ) -> Optional[ArticleOutline]:
154
- raw_outline = await self.aask(
155
- f"{(article_proposal.as_prompt())}\n"
155
+ req = (
156
156
  f"Design each chapter of a proper and academic and ready for release manner.\n"
157
157
  f"You Must make sure every chapter have sections, and every section have subsections.\n"
158
158
  f"Make the chapter and sections and subsections bing divided into a specific enough article component.\n"
@@ -160,14 +160,16 @@ class GenerateInitialOutline(Action, Extract):
160
160
  f"Note that you SHALL use `{article_proposal.language}` as written language",
161
161
  )
162
162
 
163
- if self.supervisor:
163
+ raw_outline = await self.aask(f"{(article_proposal.as_prompt())}\n{req}")
164
+
165
+ if supervisor or (supervisor is None and self.supervisor):
164
166
  from questionary import confirm, text
165
167
 
166
168
  r_print(raw_outline)
167
169
  while not await confirm("Accept this version and continue?", default=True).ask_async():
168
170
  imp = await text("Enter the improvement:").ask_async()
169
171
  raw_outline = await self.aask(
170
- f"{article_proposal.as_prompt()}\n{wrapp_in_block(raw_outline, 'Previous ArticleOutline')}\n{imp}"
172
+ f"{article_proposal.as_prompt()}\n{wrapp_in_block(raw_outline, 'Previous ArticleOutline')}\n{req}\n{wrapp_in_block(imp, title='Improvement')}"
171
173
  )
172
174
  r_print(raw_outline)
173
175
 
@@ -177,6 +179,20 @@ class GenerateInitialOutline(Action, Extract):
177
179
  ).update_ref(article_proposal)
178
180
 
179
181
 
182
+ class ExtractOutlineFromRaw(Action, Extract):
183
+ """Extract the outline from the raw outline."""
184
+
185
+ output_key: str = "article_outline_from_raw"
186
+
187
+ async def _execute(self, article_outline_raw_path: str | Path, **cxt) -> ArticleOutline:
188
+ logger.info(f"Extracting outline from raw: {Path(article_outline_raw_path).as_posix()}")
189
+
190
+ return ok(
191
+ await self.extract(ArticleOutline, safe_text_read(article_outline_raw_path)),
192
+ "Could not extract the outline from raw.",
193
+ )
194
+
195
+
180
196
  class FixIntrospectedErrors(Action, Censor):
181
197
  """Fix introspected errors in the article outline."""
182
198
 
@@ -56,13 +56,13 @@ class WriteArticleContentRAG(Action, RAG, Extract):
56
56
  async def _execute(
57
57
  self,
58
58
  article_outline: ArticleOutline,
59
- writing_ruleset: RuleSet,
60
59
  collection_name: str = "article_chunks",
60
+ supervisor: Optional[bool] = None,
61
61
  **cxt,
62
62
  ) -> Article:
63
63
  article = Article.from_outline(article_outline).update_ref(article_outline)
64
64
 
65
- if self.supervisor:
65
+ if supervisor or (supervisor is None and self.supervisor):
66
66
  await gather(
67
67
  *[
68
68
  self._supervisor_inner(article, article_outline, chap, sec, subsec)
@@ -98,9 +98,10 @@ class WriteArticleContentRAG(Action, RAG, Extract):
98
98
 
99
99
  raw = await self.write_raw(article, article_outline, chap, sec, subsec, cm)
100
100
  r_print(raw)
101
+
101
102
  while not await confirm("Accept this version and continue?").ask_async():
102
103
  if await confirm("Search for more refs?").ask_async():
103
- new_refs = await self.search_database(article, article_outline, chap, sec, subsec)
104
+ new_refs = await self.search_database(article, article_outline, chap, sec, subsec, supervisor=True)
104
105
  cm.add_chunks(await ask_retain([r.chunk for r in new_refs], new_refs))
105
106
 
106
107
  instruction = await text("Enter the instructions to improve").ask_async()
@@ -185,6 +186,7 @@ class WriteArticleContentRAG(Action, RAG, Extract):
185
186
  sec: ArticleSection,
186
187
  subsec: ArticleSubsection,
187
188
  extra_instruction: str = "",
189
+ supervisor: bool = False,
188
190
  ) -> List[ArticleChunk]:
189
191
  """Search database for related references."""
190
192
  ref_q = ok(
@@ -199,7 +201,7 @@ class WriteArticleContentRAG(Action, RAG, Extract):
199
201
  "Failed to refine query.",
200
202
  )
201
203
 
202
- if self.supervisor:
204
+ if supervisor:
203
205
  ref_q = await ask_retain(ref_q)
204
206
 
205
207
  return await self.aretrieve(
@@ -18,6 +18,7 @@ from fabricatio.journal import logger
18
18
  from fabricatio.models.generic import WithBriefing
19
19
  from fabricatio.models.task import Task
20
20
  from fabricatio.models.usages import LLMUsage, ToolBoxUsage
21
+ from fabricatio.utils import override_kwargs
21
22
  from pydantic import Field, PrivateAttr
22
23
 
23
24
  OUTPUT_KEY = "task_output"
@@ -55,7 +56,7 @@ class Action(WithBriefing, LLMUsage):
55
56
  self.description = self.description or self.__class__.__doc__ or ""
56
57
 
57
58
  @abstractmethod
58
- async def _execute(self, *_:Any, **cxt) -> Any:
59
+ async def _execute(self, *_: Any, **cxt) -> Any:
59
60
  """Implement the core logic of the action.
60
61
 
61
62
  Args:
@@ -95,11 +96,12 @@ class Action(WithBriefing, LLMUsage):
95
96
  return f"## Your personality: \n{self.personality}\n# The action you are going to perform: \n{super().briefing}"
96
97
  return f"# The action you are going to perform: \n{super().briefing}"
97
98
 
98
- def to_task_output(self)->Self:
99
+ def to_task_output(self) -> Self:
99
100
  """Set the output key to OUTPUT_KEY and return the action instance."""
100
- self.output_key=OUTPUT_KEY
101
+ self.output_key = OUTPUT_KEY
101
102
  return self
102
103
 
104
+
103
105
  class WorkFlow(WithBriefing, ToolBoxUsage):
104
106
  """Manages sequences of actions to fulfill tasks.
105
107
 
@@ -177,7 +179,7 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
177
179
  current_action = None
178
180
  try:
179
181
  # Process each action in sequence
180
- for i,step in enumerate(self._instances):
182
+ for i, step in enumerate(self._instances):
181
183
  current_action = step.name
182
184
  logger.info(f"Executing step [{i}] >> {current_action}")
183
185
 
@@ -227,8 +229,13 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
227
229
  - Any extra_init_context values
228
230
  """
229
231
  logger.debug(f"Initializing context for workflow: {self.name}")
230
- initial_context = {self.task_input_key: task, **dict(self.extra_init_context)}
231
- await self._context.put(initial_context)
232
+ ctx = override_kwargs(self.extra_init_context, **task.extra_init_context)
233
+ if self.task_input_key in ctx:
234
+ raise ValueError(
235
+ f"Task input key: `{self.task_input_key}`, which is reserved, is already set in the init context"
236
+ )
237
+
238
+ await self._context.put({self.task_input_key: task, **ctx})
232
239
 
233
240
  def steps_fallback_to_self(self) -> Self:
234
241
  """Configure all steps to use this workflow's configuration as fallback.
@@ -245,7 +252,7 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
245
252
  Returns:
246
253
  Self: The workflow instance for method chaining.
247
254
  """
248
- self.provide_tools_to(i for i in self._instances if isinstance(i,ToolBoxUsage))
255
+ self.provide_tools_to(i for i in self._instances if isinstance(i, ToolBoxUsage))
249
256
  return self
250
257
 
251
258
  def update_init_context(self, /, **kwargs) -> Self:
fabricatio/models/task.py CHANGED
@@ -4,7 +4,7 @@ It includes methods to manage the task's lifecycle, such as starting, finishing,
4
4
  """
5
5
 
6
6
  from asyncio import Queue
7
- from typing import Any, List, Optional, Self
7
+ from typing import Any, Dict, List, Optional, Self
8
8
 
9
9
  from fabricatio.config import configs
10
10
  from fabricatio.constants import TaskStatus
@@ -50,6 +50,18 @@ class Task[T](WithBriefing, ProposedAble, WithDependency):
50
50
 
51
51
  _namespace: Event = PrivateAttr(default_factory=Event)
52
52
  """The namespace of the task as an event, which is generated from the namespace list."""
53
+ _extra_init_context: Dict = PrivateAttr(default_factory=dict)
54
+ """Extra initialization context for the task, which is designed to override the one of the Workflow."""
55
+
56
+ @property
57
+ def extra_init_context(self) -> Dict:
58
+ """Extra initialization context for the task, which is designed to override the one of the Workflow."""
59
+ return self._extra_init_context
60
+
61
+ def update_init_context(self, /, **kwargs) -> Self:
62
+ """Update the extra initialization context for the task."""
63
+ self.extra_init_context.update(kwargs)
64
+ return self
53
65
 
54
66
  def model_post_init(self, __context: Any) -> None:
55
67
  """Initialize the task with a namespace event."""
@@ -31,7 +31,7 @@ from pydantic import BaseModel, ConfigDict, Field, NonNegativeInt, PositiveInt
31
31
 
32
32
  if configs.cache.enabled and configs.cache.type:
33
33
  litellm.enable_cache(type=configs.cache.type, **configs.cache.params)
34
- logger.success(f"{configs.cache.type.name} Cache enabled")
34
+ logger.debug(f"{configs.cache.type.name} Cache enabled")
35
35
 
36
36
  ROUTER = Router(
37
37
  routing_strategy="usage-based-routing-v2",
Binary file
fabricatio/utils.py CHANGED
@@ -54,14 +54,14 @@ async def ask_retain[V](candidates: List[str], value_mapping: Optional[List[V]]
54
54
  def override_kwargs(kwargs: Mapping[str, Any], **overrides) -> Dict[str, Any]:
55
55
  """Override the values in kwargs with the provided overrides."""
56
56
  new_kwargs = dict(kwargs.items())
57
- new_kwargs.update({k: v for k, v in overrides.items() if v is not None})
57
+ new_kwargs.update(overrides)
58
58
  return new_kwargs
59
59
 
60
60
 
61
- def fallback_kwargs(kwargs: Mapping[str, Any], **overrides) -> Dict[str, Any]:
62
- """Fallback the values in kwargs with the provided overrides."""
61
+ def fallback_kwargs(kwargs: Mapping[str, Any], **fallbacks) -> Dict[str, Any]:
62
+ """Fallback the values in kwargs with the provided fallbacks."""
63
63
  new_kwargs = dict(kwargs.items())
64
- new_kwargs.update({k: v for k, v in overrides.items() if k not in new_kwargs and v is not None})
64
+ new_kwargs.update({k: v for k, v in fallbacks.items() if k not in new_kwargs})
65
65
  return new_kwargs
66
66
 
67
67
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fabricatio
3
- Version: 0.2.11.dev2
3
+ Version: 0.2.11.dev3
4
4
  Classifier: License :: OSI Approved :: MIT License
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -20,18 +20,20 @@ Requires-Dist: pydantic-settings>=2.7.1
20
20
  Requires-Dist: pymitter>=1.0.0
21
21
  Requires-Dist: rich>=13.9.4
22
22
  Requires-Dist: ujson>=5.10.0
23
- Requires-Dist: fabricatio[calc,ftd,plot,qa,rag] ; extra == 'full'
23
+ Requires-Dist: fabricatio[calc,ftd,plot,qa,rag,cli] ; extra == 'full'
24
24
  Requires-Dist: pymilvus>=2.5.4 ; extra == 'rag'
25
25
  Requires-Dist: sympy>=1.13.3 ; extra == 'calc'
26
26
  Requires-Dist: matplotlib>=3.10.1 ; extra == 'plot'
27
27
  Requires-Dist: questionary>=2.1.0 ; extra == 'qa'
28
28
  Requires-Dist: magika>=0.6.1 ; extra == 'ftd'
29
+ Requires-Dist: typer-slim[standard]>=0.15.2 ; extra == 'cli'
29
30
  Provides-Extra: full
30
31
  Provides-Extra: rag
31
32
  Provides-Extra: calc
32
33
  Provides-Extra: plot
33
34
  Provides-Extra: qa
34
35
  Provides-Extra: ftd
36
+ Provides-Extra: cli
35
37
  License-File: LICENSE
36
38
  Summary: A LLM multi-agent framework.
37
39
  Keywords: ai,agents,multi-agent,llm,pyo3
@@ -1,8 +1,8 @@
1
- fabricatio-0.2.11.dev2.dist-info/METADATA,sha256=8vrHMg-FM5vxNTDy3G5Ck3n9MM4UJ9NeHcgXQVUYrRI,5178
2
- fabricatio-0.2.11.dev2.dist-info/WHEEL,sha256=jABKVkLC9kJr8mi_er5jOqpiQUjARSLXDUIIxDqsS50,96
3
- fabricatio-0.2.11.dev2.dist-info/licenses/LICENSE,sha256=do7J7EiCGbq0QPbMAL_FqLYufXpHnCnXBOuqVPwSV8Y,1088
4
- fabricatio/actions/article.py,sha256=J2wneRmGDVzzyvsFw1Ux69Q6kI8Ty3Dty0l5eToSGX0,10237
5
- fabricatio/actions/article_rag.py,sha256=UdhkZ2MAi094xKkdIKpdprOS-OOPb9xwceKX4tRRhSw,14221
1
+ fabricatio-0.2.11.dev3.dist-info/METADATA,sha256=alou2beIqeg3_FeS2dp-VQx15_Ep-0bf-tbGrUSxGmw,5263
2
+ fabricatio-0.2.11.dev3.dist-info/WHEEL,sha256=jABKVkLC9kJr8mi_er5jOqpiQUjARSLXDUIIxDqsS50,96
3
+ fabricatio-0.2.11.dev3.dist-info/licenses/LICENSE,sha256=do7J7EiCGbq0QPbMAL_FqLYufXpHnCnXBOuqVPwSV8Y,1088
4
+ fabricatio/actions/article.py,sha256=SFl1zc0hz9vW2sW4VJm9-w8E7kLEty-2LzXi9wgWMmE,10905
5
+ fabricatio/actions/article_rag.py,sha256=P1Bgvk6w8HogEMOw15-_cn2lzKpIcmfe_Ku2mlkdkYk,14318
6
6
  fabricatio/actions/fs.py,sha256=gJR14U4ln35nt8Z7OWLVAZpqGaLnED-r1Yi-lX22tkI,959
7
7
  fabricatio/actions/output.py,sha256=ttXLC2wZmtVN9Ik8zsA7g45rwBO656LyRjOGRdVSyJA,6977
8
8
  fabricatio/actions/rag.py,sha256=KN-OWgcQjGmNgSZ-s5B8m4LpYKSGFJR8eq72mo2CP9k,3592
@@ -27,7 +27,7 @@ fabricatio/fs/curd.py,sha256=p8y0LGKgVDk-CWOlm37E6wg7RK6RCD6denKo-VsW28c,4763
27
27
  fabricatio/fs/readers.py,sha256=UXvcJO3UCsxHu9PPkg34Yh55Zi-miv61jD_wZQJgKRs,1751
28
28
  fabricatio/fs/__init__.py,sha256=FydmlEY_3QY74r1BpGDc5lFLhE6g6gkwOAtE30Fo-aI,786
29
29
  fabricatio/journal.py,sha256=stnEP88aUBA_GmU9gfTF2EZI8FS2OyMLGaMSTgK4QgA,476
30
- fabricatio/models/action.py,sha256=Kfa-zojgHQ1vPoC2lQp-thTTp0oySKn7k6I4ea6iYTs,9837
30
+ fabricatio/models/action.py,sha256=SnL8FAZsUCi9xM9BZT-CSjSRuI-4YBC5By8-ZHEBrW8,10109
31
31
  fabricatio/models/adv_kwargs_types.py,sha256=kUO-SiZtFuz5cZCmMLnJJ9tjQ4-Zd_foo6R8HQMlM5A,1950
32
32
  fabricatio/models/events.py,sha256=wiirk_ASg3iXDOZU_gIimci1VZVzWE1nDmxy-hQVJ9M,4150
33
33
  fabricatio/models/extra/advanced_judge.py,sha256=INUl_41C8jkausDekkjnEmTwNfLCJ23TwFjq2cM23Cw,1092
@@ -45,9 +45,9 @@ fabricatio/models/extra/__init__.py,sha256=XlYnS_2B9nhLhtQkjE7rvvfPmAAtXVdNi9bSD
45
45
  fabricatio/models/generic.py,sha256=7wcG01DN9g4q1DJGZsTUxSTMixQgwXX0xlX4HbbLc6U,31185
46
46
  fabricatio/models/kwargs_types.py,sha256=GEw75ZiiDEFx_ImhCBENnPF7K0BcdTQ1ocH5jSPwMRs,4774
47
47
  fabricatio/models/role.py,sha256=-CRcj5_M3_ciLPzwiNn92grBmwoSLQ-n4koVZiCNTBM,2953
48
- fabricatio/models/task.py,sha256=SxWI-b5jlQcGmNsjQ2aKDyywXwGiUvCR1rgUhk-pli8,10503
48
+ fabricatio/models/task.py,sha256=bLYSKjlRAlb4jMYyF12RTnm_8pVXysSmX8CYLrEmbQ8,11096
49
49
  fabricatio/models/tool.py,sha256=jQ51g4lwTPfsMF1nbreDJtBczbxIHoXcPuLSOqHliq8,12506
50
- fabricatio/models/usages.py,sha256=B9kII7wP9uUj6-M69kbnTsWQpZcJ-gKZ2HplIxL0j1c,33358
50
+ fabricatio/models/usages.py,sha256=0bzITf0vug9ZaN6qnjNfFB7T8BAvpXE0bvx0otFYLLA,33356
51
51
  fabricatio/parser.py,sha256=-RbW2yzfJiu2ARq-lZw4tfgsjY2rIZWtJpoUmaE6gJQ,6637
52
52
  fabricatio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
53
53
  fabricatio/rust.pyi,sha256=GJRLeeQ1UIaf5kOgJWX2GkwIacoTBk3yBKuD5cKW8i4,10489
@@ -55,11 +55,11 @@ fabricatio/rust_instances.py,sha256=Byeo8KHW_dJiXujJq7YPGDLBX5bHNDYbBc4sY3uubVY,
55
55
  fabricatio/toolboxes/arithmetic.py,sha256=WLqhY-Pikv11Y_0SGajwZx3WhsLNpHKf9drzAqOf_nY,1369
56
56
  fabricatio/toolboxes/fs.py,sha256=l4L1CVxJmjw9Ld2XUpIlWfV0_Fu_2Og6d3E13I-S4aE,736
57
57
  fabricatio/toolboxes/__init__.py,sha256=KBJi5OG_pExscdlM7Bnt_UF43j4I3Lv6G71kPVu4KQU,395
58
- fabricatio/utils.py,sha256=vlXbAA4b_odh2wlAcJlNQ-1ckkxNNKDGJaxShdljojA,3146
58
+ fabricatio/utils.py,sha256=sLD6L_BHXusJjCu3gsUpxOFbmEOnT577xU1kaZQ04SE,3084
59
59
  fabricatio/workflows/articles.py,sha256=ObYTFUqLUk_CzdmmnX6S7APfxcGmPFqnFr9pdjU7Z4Y,969
60
60
  fabricatio/workflows/rag.py,sha256=-YYp2tlE9Vtfgpg6ROpu6QVO8j8yVSPa6yDzlN3qVxs,520
61
61
  fabricatio/workflows/__init__.py,sha256=5ScFSTA-bvhCesj3U9Mnmi6Law6N1fmh5UKyh58L3u8,51
62
62
  fabricatio/__init__.py,sha256=Rmvq2VgdS2u68vnOi2i5RbeWbAwrJDbk8D8D883PJWE,1022
63
- fabricatio/rust.cp312-win_amd64.pyd,sha256=UUJZ7DBWgQbROlf5Cfa-yJOWSp_1qNTJwbp4AmxOVUU,4150272
64
- fabricatio-0.2.11.dev2.data/scripts/tdown.exe,sha256=LtLVx_ahJ-FP1bpQm-GMXr8_xYPf_Ax-tap9bHW6PvA,3350016
65
- fabricatio-0.2.11.dev2.dist-info/RECORD,,
63
+ fabricatio/rust.cp312-win_amd64.pyd,sha256=Z3wuzfa_m81nq1W6MVF66ne-gQ0-gkNFdknay_wVskY,4150272
64
+ fabricatio-0.2.11.dev3.data/scripts/tdown.exe,sha256=nHWlrICGMzmDpo1bZA-l1tqyCZhSreyrc5S1J3E7KgU,3350016
65
+ fabricatio-0.2.11.dev3.dist-info/RECORD,,