fabricatio 0.2.8.dev4__cp312-cp312-manylinux_2_34_x86_64.whl → 0.2.9.dev0__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 +4 -11
- fabricatio/actions/__init__.py +1 -0
- fabricatio/actions/article.py +3 -2
- fabricatio/actions/rag.py +2 -1
- fabricatio/actions/rules.py +39 -0
- fabricatio/capabilities/__init__.py +1 -0
- fabricatio/capabilities/censor.py +3 -0
- fabricatio/capabilities/check.py +6 -5
- fabricatio/capabilities/correct.py +1 -1
- fabricatio/capabilities/rag.py +5 -4
- fabricatio/capabilities/rating.py +4 -3
- fabricatio/capabilities/review.py +1 -1
- fabricatio/capabilities/task.py +2 -1
- fabricatio/config.py +2 -0
- fabricatio/models/action.py +10 -2
- fabricatio/models/extra/__init__.py +1 -0
- fabricatio/models/extra/patches.py +16 -3
- fabricatio/models/extra/rule.py +26 -7
- fabricatio/models/generic.py +272 -56
- fabricatio/models/task.py +1 -1
- fabricatio/models/tool.py +149 -14
- fabricatio/models/usages.py +39 -26
- fabricatio/rust.cpython-312-x86_64-linux-gnu.so +0 -0
- fabricatio/{_rust_instances.py → rust_instances.py} +1 -1
- fabricatio/workflows/__init__.py +1 -0
- fabricatio-0.2.9.dev0.data/scripts/tdown +0 -0
- {fabricatio-0.2.8.dev4.dist-info → fabricatio-0.2.9.dev0.dist-info}/METADATA +1 -1
- {fabricatio-0.2.8.dev4.dist-info → fabricatio-0.2.9.dev0.dist-info}/RECORD +31 -26
- fabricatio/_rust.cpython-312-x86_64-linux-gnu.so +0 -0
- fabricatio-0.2.8.dev4.data/scripts/tdown +0 -0
- /fabricatio/{_rust.pyi → rust.pyi} +0 -0
- {fabricatio-0.2.8.dev4.dist-info → fabricatio-0.2.9.dev0.dist-info}/WHEEL +0 -0
- {fabricatio-0.2.8.dev4.dist-info → fabricatio-0.2.9.dev0.dist-info}/licenses/LICENSE +0 -0
fabricatio/__init__.py
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
"""Fabricatio is a Python library for building llm app using event-based agent structure."""
|
2
2
|
|
3
|
-
from
|
4
|
-
|
5
|
-
from fabricatio import actions, toolboxes, workflows
|
6
|
-
from fabricatio._rust import BibManager
|
7
|
-
from fabricatio._rust_instances import TEMPLATE_MANAGER
|
3
|
+
from fabricatio import actions, capabilities, toolboxes, workflows
|
8
4
|
from fabricatio.core import env
|
9
5
|
from fabricatio.journal import logger
|
10
6
|
from fabricatio.models import extra
|
@@ -14,6 +10,8 @@ from fabricatio.models.role import Role
|
|
14
10
|
from fabricatio.models.task import Task
|
15
11
|
from fabricatio.models.tool import ToolBox
|
16
12
|
from fabricatio.parser import Capture, GenericCapture, JsonCapture, PythonCapture
|
13
|
+
from fabricatio.rust import BibManager
|
14
|
+
from fabricatio.rust_instances import TEMPLATE_MANAGER
|
17
15
|
|
18
16
|
__all__ = [
|
19
17
|
"TEMPLATE_MANAGER",
|
@@ -29,15 +27,10 @@ __all__ = [
|
|
29
27
|
"ToolBox",
|
30
28
|
"WorkFlow",
|
31
29
|
"actions",
|
30
|
+
"capabilities",
|
32
31
|
"env",
|
33
32
|
"extra",
|
34
33
|
"logger",
|
35
34
|
"toolboxes",
|
36
35
|
"workflows",
|
37
36
|
]
|
38
|
-
|
39
|
-
|
40
|
-
if find_spec("pymilvus"):
|
41
|
-
from fabricatio.capabilities.rag import RAG
|
42
|
-
|
43
|
-
__all__ += ["RAG"]
|
@@ -0,0 +1 @@
|
|
1
|
+
"""A module containing some builtin actins."""
|
fabricatio/actions/article.py
CHANGED
@@ -4,7 +4,8 @@ from asyncio import gather
|
|
4
4
|
from pathlib import Path
|
5
5
|
from typing import Any, Callable, List, Optional
|
6
6
|
|
7
|
-
from
|
7
|
+
from more_itertools import filter_map
|
8
|
+
|
8
9
|
from fabricatio.capabilities.censor import Censor
|
9
10
|
from fabricatio.capabilities.correct import Correct
|
10
11
|
from fabricatio.capabilities.propose import Propose
|
@@ -18,8 +19,8 @@ from fabricatio.models.extra.article_outline import ArticleOutline
|
|
18
19
|
from fabricatio.models.extra.article_proposal import ArticleProposal
|
19
20
|
from fabricatio.models.extra.rule import RuleSet
|
20
21
|
from fabricatio.models.task import Task
|
22
|
+
from fabricatio.rust import BibManager
|
21
23
|
from fabricatio.utils import ok
|
22
|
-
from more_itertools import filter_map
|
23
24
|
|
24
25
|
|
25
26
|
class ExtractArticleEssence(Action, Propose):
|
fabricatio/actions/rag.py
CHANGED
@@ -2,12 +2,13 @@
|
|
2
2
|
|
3
3
|
from typing import List, Optional
|
4
4
|
|
5
|
+
from questionary import text
|
6
|
+
|
5
7
|
from fabricatio.capabilities.rag import RAG
|
6
8
|
from fabricatio.journal import logger
|
7
9
|
from fabricatio.models.action import Action
|
8
10
|
from fabricatio.models.generic import Vectorizable
|
9
11
|
from fabricatio.models.task import Task
|
10
|
-
from questionary import text
|
11
12
|
|
12
13
|
|
13
14
|
class InjectToDB(Action, RAG):
|
@@ -0,0 +1,39 @@
|
|
1
|
+
"""A module containing the DraftRuleSet action."""
|
2
|
+
|
3
|
+
from typing import Optional
|
4
|
+
|
5
|
+
from fabricatio.capabilities.check import Check
|
6
|
+
from fabricatio.models.action import Action
|
7
|
+
from fabricatio.models.extra.rule import RuleSet
|
8
|
+
from fabricatio.utils import ok
|
9
|
+
|
10
|
+
|
11
|
+
class DraftRuleSet(Action, Check):
|
12
|
+
"""Action to draft a ruleset based on a given requirement description."""
|
13
|
+
|
14
|
+
output_key: str = "drafted_ruleset"
|
15
|
+
"""The key used to store the drafted ruleset in the context dictionary."""
|
16
|
+
|
17
|
+
ruleset_requirement: Optional[str] = None
|
18
|
+
"""The natural language description of the desired ruleset characteristics."""
|
19
|
+
rule_count: int = 0
|
20
|
+
"""The number of rules to generate in the ruleset (0 for no restriction)."""
|
21
|
+
async def _execute(
|
22
|
+
self,
|
23
|
+
ruleset_requirement: Optional[str]=None,
|
24
|
+
**_,
|
25
|
+
) -> Optional[RuleSet]:
|
26
|
+
"""Draft a ruleset based on the requirement description.
|
27
|
+
|
28
|
+
Args:
|
29
|
+
ruleset_requirement (str): Natural language description of desired ruleset characteristics
|
30
|
+
rule_count (int): Number of rules to generate (0 for no restriction)
|
31
|
+
**kwargs: Validation parameters for rule generation
|
32
|
+
|
33
|
+
Returns:
|
34
|
+
Optional[RuleSet]: Drafted ruleset object or None if generation fails
|
35
|
+
"""
|
36
|
+
return await self.draft_ruleset(
|
37
|
+
ruleset_requirement=ok(ruleset_requirement or self.ruleset_requirement,"No ruleset requirement provided"),
|
38
|
+
rule_count=self.rule_count,
|
39
|
+
)
|
@@ -0,0 +1 @@
|
|
1
|
+
"""A module containing some high level capabilities."""
|
@@ -19,6 +19,9 @@ class Censor(Correct, Check):
|
|
19
19
|
|
20
20
|
Inherits from both Correct and Check classes.
|
21
21
|
Provides methods to censor objects and strings by first checking them against a ruleset and then correcting them if necessary.
|
22
|
+
|
23
|
+
Attributes:
|
24
|
+
ruleset (RuleSet): The ruleset to be used for censoring.
|
22
25
|
"""
|
23
26
|
|
24
27
|
async def censor_obj[M: SketchedAble](
|
fabricatio/capabilities/check.py
CHANGED
@@ -6,7 +6,7 @@ from fabricatio import TEMPLATE_MANAGER
|
|
6
6
|
from fabricatio.capabilities.advanced_judge import AdvancedJudge
|
7
7
|
from fabricatio.capabilities.propose import Propose
|
8
8
|
from fabricatio.config import configs
|
9
|
-
from fabricatio.models.extra.patches import
|
9
|
+
from fabricatio.models.extra.patches import RuleSetBriefingPatch
|
10
10
|
from fabricatio.models.extra.problem import Improvement
|
11
11
|
from fabricatio.models.extra.rule import Rule, RuleSet
|
12
12
|
from fabricatio.models.generic import Display, WithBriefing
|
@@ -50,21 +50,22 @@ class Check(AdvancedJudge, Propose):
|
|
50
50
|
if rule_reqs is None:
|
51
51
|
return None
|
52
52
|
|
53
|
-
rules = await self.propose(Rule, rule_reqs, **kwargs)
|
53
|
+
rules = await self.propose(Rule, [TEMPLATE_MANAGER.render_template(configs.templates.rule_requirement_template, {"rule_requirement": r}) for r in rule_reqs], **kwargs)
|
54
54
|
if any(r for r in rules if r is None):
|
55
55
|
return None
|
56
56
|
|
57
57
|
ruleset_patch = await self.propose(
|
58
|
-
|
58
|
+
RuleSetBriefingPatch,
|
59
59
|
f"# Rules Requirements\n{rule_reqs}\n# Generated Rules\n{Display.seq_display(rules)}\n\n"
|
60
|
-
f"You need to write a concise and detailed patch for this ruleset that can be applied to the ruleset nicely"
|
60
|
+
f"You need to write a concise and detailed patch for this ruleset that can be applied to the ruleset nicely.\n"
|
61
|
+
f"Note that all fields in this patch will be directly copied to the ruleset obj, including `name` and `description`, so write when knowing the subject.\n",
|
61
62
|
**override_kwargs(kwargs, default=None),
|
62
63
|
)
|
63
64
|
|
64
65
|
if ruleset_patch is None:
|
65
66
|
return None
|
66
67
|
|
67
|
-
return
|
68
|
+
return RuleSet(rules=rules, **ruleset_patch.as_kwargs())
|
68
69
|
|
69
70
|
async def check_string_against_rule(
|
70
71
|
self,
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
from typing import Optional, Type, Unpack, cast
|
4
4
|
|
5
|
-
from fabricatio._rust_instances import TEMPLATE_MANAGER
|
6
5
|
from fabricatio.capabilities.propose import Propose
|
7
6
|
from fabricatio.capabilities.rating import Rating
|
8
7
|
from fabricatio.config import configs
|
@@ -14,6 +13,7 @@ from fabricatio.models.kwargs_types import (
|
|
14
13
|
BestKwargs,
|
15
14
|
ValidateKwargs,
|
16
15
|
)
|
16
|
+
from fabricatio.rust_instances import TEMPLATE_MANAGER
|
17
17
|
from fabricatio.utils import ok, override_kwargs
|
18
18
|
|
19
19
|
|
fabricatio/capabilities/rag.py
CHANGED
@@ -3,14 +3,16 @@
|
|
3
3
|
try:
|
4
4
|
from pymilvus import MilvusClient
|
5
5
|
except ImportError as e:
|
6
|
-
raise RuntimeError("pymilvus is not installed. Have you installed `fabricatio[rag]` instead of `fabricatio
|
6
|
+
raise RuntimeError("pymilvus is not installed. Have you installed `fabricatio[rag]` instead of `fabricatio`?") from e
|
7
7
|
from functools import lru_cache
|
8
8
|
from operator import itemgetter
|
9
9
|
from os import PathLike
|
10
10
|
from pathlib import Path
|
11
11
|
from typing import Any, Callable, Dict, List, Optional, Self, Union, Unpack, cast, overload
|
12
12
|
|
13
|
-
from
|
13
|
+
from more_itertools.recipes import flatten, unique
|
14
|
+
from pydantic import Field, PrivateAttr
|
15
|
+
|
14
16
|
from fabricatio.config import configs
|
15
17
|
from fabricatio.journal import logger
|
16
18
|
from fabricatio.models.kwargs_types import (
|
@@ -23,9 +25,8 @@ from fabricatio.models.kwargs_types import (
|
|
23
25
|
)
|
24
26
|
from fabricatio.models.usages import EmbeddingUsage
|
25
27
|
from fabricatio.models.utils import MilvusData
|
28
|
+
from fabricatio.rust_instances import TEMPLATE_MANAGER
|
26
29
|
from fabricatio.utils import ok
|
27
|
-
from more_itertools.recipes import flatten, unique
|
28
|
-
from pydantic import Field, PrivateAttr
|
29
30
|
|
30
31
|
|
31
32
|
@lru_cache(maxsize=None)
|
@@ -4,16 +4,17 @@ from itertools import permutations
|
|
4
4
|
from random import sample
|
5
5
|
from typing import Dict, List, Optional, Set, Tuple, Union, Unpack, overload
|
6
6
|
|
7
|
-
from
|
7
|
+
from more_itertools import flatten, windowed
|
8
|
+
from pydantic import NonNegativeInt, PositiveInt
|
9
|
+
|
8
10
|
from fabricatio.config import configs
|
9
11
|
from fabricatio.journal import logger
|
10
12
|
from fabricatio.models.generic import Display
|
11
13
|
from fabricatio.models.kwargs_types import CompositeScoreKwargs, ValidateKwargs
|
12
14
|
from fabricatio.models.usages import LLMUsage
|
13
15
|
from fabricatio.parser import JsonCapture
|
16
|
+
from fabricatio.rust_instances import TEMPLATE_MANAGER
|
14
17
|
from fabricatio.utils import ok, override_kwargs
|
15
|
-
from more_itertools import flatten, windowed
|
16
|
-
from pydantic import NonNegativeInt, PositiveInt
|
17
18
|
|
18
19
|
|
19
20
|
class Rating(LLMUsage):
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
from typing import Dict, Optional, Set, Unpack
|
4
4
|
|
5
|
-
from fabricatio._rust_instances import TEMPLATE_MANAGER
|
6
5
|
from fabricatio.capabilities.propose import Propose
|
7
6
|
from fabricatio.capabilities.rating import Rating
|
8
7
|
from fabricatio.config import configs
|
@@ -10,6 +9,7 @@ from fabricatio.models.extra.problem import Improvement
|
|
10
9
|
from fabricatio.models.generic import Display, WithBriefing
|
11
10
|
from fabricatio.models.kwargs_types import ReviewKwargs, ValidateKwargs
|
12
11
|
from fabricatio.models.task import Task
|
12
|
+
from fabricatio.rust_instances import TEMPLATE_MANAGER
|
13
13
|
from fabricatio.utils import ok
|
14
14
|
|
15
15
|
|
fabricatio/capabilities/task.py
CHANGED
@@ -4,7 +4,7 @@ from types import CodeType
|
|
4
4
|
from typing import Any, Dict, List, Optional, Tuple, Unpack
|
5
5
|
|
6
6
|
import orjson
|
7
|
-
|
7
|
+
|
8
8
|
from fabricatio.capabilities.propose import Propose
|
9
9
|
from fabricatio.config import configs
|
10
10
|
from fabricatio.journal import logger
|
@@ -13,6 +13,7 @@ from fabricatio.models.task import Task
|
|
13
13
|
from fabricatio.models.tool import Tool, ToolExecutor
|
14
14
|
from fabricatio.models.usages import ToolBoxUsage
|
15
15
|
from fabricatio.parser import JsonCapture, PythonCapture
|
16
|
+
from fabricatio.rust_instances import TEMPLATE_MANAGER
|
16
17
|
|
17
18
|
|
18
19
|
class ProposeTask(Propose):
|
fabricatio/config.py
CHANGED
@@ -247,6 +247,8 @@ class TemplateConfig(BaseModel):
|
|
247
247
|
fix_troubled_string_template: str = Field(default="fix_troubled_string")
|
248
248
|
"""The name of the fix troubled string template which will be used to fix a troubled string."""
|
249
249
|
|
250
|
+
rule_requirement_template: str = Field(default="rule_requirement")
|
251
|
+
"""The name of the rule requirement template which will be used to generate a rule requirement."""
|
250
252
|
class MagikaConfig(BaseModel):
|
251
253
|
"""Magika configuration class."""
|
252
254
|
|
fabricatio/models/action.py
CHANGED
@@ -15,6 +15,10 @@ from fabricatio.models.task import Task
|
|
15
15
|
from fabricatio.models.usages import LLMUsage, ToolBoxUsage
|
16
16
|
from pydantic import Field, PrivateAttr
|
17
17
|
|
18
|
+
OUTPUT_KEY = "task_output"
|
19
|
+
|
20
|
+
INPUT_KEY = "task_input"
|
21
|
+
|
18
22
|
|
19
23
|
class Action(WithBriefing, LLMUsage):
|
20
24
|
"""Class that represents an action to be executed in a workflow.
|
@@ -88,6 +92,10 @@ class Action(WithBriefing, LLMUsage):
|
|
88
92
|
return f"## Your personality: \n{self.personality}\n# The action you are going to perform: \n{super().briefing}"
|
89
93
|
return f"# The action you are going to perform: \n{super().briefing}"
|
90
94
|
|
95
|
+
def to_task_output(self)->Self:
|
96
|
+
"""Set the output key to OUTPUT_KEY and return the action instance."""
|
97
|
+
self.output_key=OUTPUT_KEY
|
98
|
+
return self
|
91
99
|
|
92
100
|
class WorkFlow(WithBriefing, ToolBoxUsage):
|
93
101
|
"""Class that represents a sequence of actions to be executed for a task.
|
@@ -110,10 +118,10 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
|
|
110
118
|
)
|
111
119
|
"""The sequence of actions to be executed, can be action classes or instances."""
|
112
120
|
|
113
|
-
task_input_key: str = Field(default=
|
121
|
+
task_input_key: str = Field(default=INPUT_KEY)
|
114
122
|
"""Key used to store the input task in the context dictionary."""
|
115
123
|
|
116
|
-
task_output_key: str = Field(default=
|
124
|
+
task_output_key: str = Field(default=OUTPUT_KEY)
|
117
125
|
"""Key used to extract the final result from the context dictionary."""
|
118
126
|
|
119
127
|
extra_init_context: Dict[str, Any] = Field(default_factory=dict, frozen=True)
|
@@ -0,0 +1 @@
|
|
1
|
+
"""A module contains extra models for fabricatio."""
|
@@ -1,7 +1,20 @@
|
|
1
|
-
"""A patch class for updating the description and name of a `WithBriefing` object."""
|
1
|
+
"""A patch class for updating the description and name of a `WithBriefing` object, all fields within this instance will be directly copied onto the target model's field."""
|
2
2
|
|
3
|
+
from typing import Optional, Type
|
4
|
+
|
5
|
+
from fabricatio.models.extra.rule import RuleSet
|
3
6
|
from fabricatio.models.generic import Patch, WithBriefing
|
7
|
+
from pydantic import BaseModel
|
8
|
+
|
9
|
+
|
10
|
+
class BriefingPatch[T: WithBriefing](Patch[T], WithBriefing):
|
11
|
+
"""Patch class for updating the description and name of a `WithBriefing` object, all fields within this instance will be directly copied onto the target model's field."""
|
4
12
|
|
5
13
|
|
6
|
-
class BriefingPatch[
|
7
|
-
"""Patch class for updating the description and name of a `
|
14
|
+
class RuleSetBriefingPatch(BriefingPatch[RuleSet]):
|
15
|
+
"""Patch class for updating the description and name of a `RuleSet` object, all fields within this instance will be directly copied onto the target model's field."""
|
16
|
+
language: str
|
17
|
+
@staticmethod
|
18
|
+
def ref_cls() -> Optional[Type[BaseModel]]:
|
19
|
+
"""Get the reference class of the model."""
|
20
|
+
return RuleSet
|
fabricatio/models/extra/rule.py
CHANGED
@@ -1,21 +1,40 @@
|
|
1
|
-
"""A module containing classes related to rule sets and rules.
|
1
|
+
"""A module containing classes related to rule sets and rules.
|
2
|
+
|
3
|
+
This module provides the `Rule` and `RuleSet` classes, which are used to define and manage
|
4
|
+
individual rules and collections of rules, respectively. These classes are designed to
|
5
|
+
facilitate the creation, organization, and application of rules in various contexts,
|
6
|
+
ensuring clarity, consistency, and enforceability. The module supports detailed
|
7
|
+
descriptions, examples, and metadata for each rule and rule set, making it suitable for
|
8
|
+
complex rule management systems.
|
9
|
+
"""
|
2
10
|
|
3
11
|
from typing import List
|
4
12
|
|
5
|
-
from fabricatio.models.generic import
|
13
|
+
from fabricatio.models.generic import Language, PersistentAble, SketchedAble, WithBriefing
|
6
14
|
|
7
15
|
|
8
|
-
class Rule(WithBriefing,
|
16
|
+
class Rule(WithBriefing,Language, SketchedAble,PersistentAble):
|
9
17
|
"""Represents a rule or guideline for a specific topic."""
|
10
18
|
|
19
|
+
|
11
20
|
violation_examples: List[str]
|
12
|
-
"""
|
21
|
+
"""A list of concrete examples demonstrating violations of this rule. Each example should
|
22
|
+
be a clear scenario or case that illustrates how the rule can be broken, including the
|
23
|
+
context, actions, and consequences of the violation. These examples should help in
|
24
|
+
understanding the boundaries of the rule."""
|
25
|
+
|
13
26
|
compliance_examples: List[str]
|
14
|
-
"""
|
27
|
+
"""A list of concrete examples demonstrating proper compliance with this rule. Each example
|
28
|
+
should be a clear scenario or case that illustrates how to correctly follow the rule,
|
29
|
+
including the context, actions, and positive outcomes of compliance. These examples should
|
30
|
+
serve as practical guidance for implementing the rule correctly."""
|
15
31
|
|
16
32
|
|
17
|
-
class RuleSet(
|
33
|
+
class RuleSet( SketchedAble, PersistentAble, WithBriefing,Language):
|
18
34
|
"""Represents a collection of rules and guidelines for a particular topic."""
|
19
35
|
|
20
36
|
rules: List[Rule]
|
21
|
-
"""The rules and guidelines contained in
|
37
|
+
"""The collection of rules and guidelines contained in this rule set. Each rule should be
|
38
|
+
a well-defined, specific guideline that contributes to the overall purpose of the rule set.
|
39
|
+
The rules should be logically organized and consistent with each other, forming a coherent
|
40
|
+
framework for the topic or domain covered by the rule set."""
|