fabricatio 0.2.8.dev4__tar.gz → 0.2.9.dev1__tar.gz
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-0.2.8.dev4 → fabricatio-0.2.9.dev1}/Cargo.lock +7 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/Cargo.toml +1 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/PKG-INFO +1 -1
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/make_diary/diary.py +2 -2
- fabricatio-0.2.9.dev1/examples/rules/draft_ruleset.py +59 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/task_handle/handle_task.py +2 -2
- fabricatio-0.2.9.dev1/examples/write_article/.gitignore +3 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/write_article/write_article.py +1 -1
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/write_outline/write_outline.py +3 -2
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/write_outline/write_outline_corrected.py +2 -2
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/pyproject.toml +2 -2
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/__init__.py +4 -11
- fabricatio-0.2.9.dev1/python/fabricatio/actions/__init__.py +1 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/actions/article.py +3 -2
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/actions/rag.py +2 -1
- fabricatio-0.2.9.dev1/python/fabricatio/actions/rules.py +39 -0
- fabricatio-0.2.9.dev1/python/fabricatio/capabilities/__init__.py +1 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/capabilities/censor.py +3 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/capabilities/check.py +6 -5
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/capabilities/correct.py +1 -1
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/capabilities/rag.py +5 -4
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/capabilities/rating.py +4 -3
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/capabilities/review.py +1 -1
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/capabilities/task.py +2 -1
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/config.py +2 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/models/action.py +10 -2
- fabricatio-0.2.9.dev1/python/fabricatio/models/extra/__init__.py +1 -0
- fabricatio-0.2.9.dev1/python/fabricatio/models/extra/patches.py +20 -0
- fabricatio-0.2.9.dev1/python/fabricatio/models/extra/rule.py +40 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/models/generic.py +272 -56
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/models/task.py +1 -1
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/models/tool.py +149 -14
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/models/usages.py +39 -26
- fabricatio-0.2.8.dev4/python/fabricatio/_rust.pyi → fabricatio-0.2.9.dev1/python/fabricatio/rust.pyi +3 -0
- fabricatio-0.2.8.dev4/python/fabricatio/_rust_instances.py → fabricatio-0.2.9.dev1/python/fabricatio/rust_instances.py +1 -1
- fabricatio-0.2.9.dev1/python/fabricatio/workflows/__init__.py +1 -0
- fabricatio-0.2.9.dev1/src/hbs_helpers.rs +18 -0
- fabricatio-0.2.9.dev1/src/language.rs +42 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/src/lib.rs +3 -1
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/src/templates.rs +4 -1
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/liststr.hbs +3 -2
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/refined_query.hbs +1 -1
- fabricatio-0.2.9.dev1/templates/built-in/rule_requirement.hbs +12 -0
- fabricatio-0.2.9.dev1/templates/built-in/ruleset_requirement_breakdown.hbs +19 -0
- fabricatio-0.2.9.dev1/templates.tar.gz +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/uv.lock +52 -52
- fabricatio-0.2.8.dev4/python/fabricatio/models/extra/patches.py +0 -7
- fabricatio-0.2.8.dev4/python/fabricatio/models/extra/rule.py +0 -21
- fabricatio-0.2.8.dev4/src/hbs_helpers.rs +0 -9
- fabricatio-0.2.8.dev4/templates/built-in/ruleset_requirement_breakdown.hbs +0 -7
- fabricatio-0.2.8.dev4/templates.tar.gz +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/.github/workflows/build-package.yaml +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/.github/workflows/ruff.yaml +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/.github/workflows/tests.yaml +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/.gitignore +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/.python-version +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/LICENSE +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/Makefile +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/README.md +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/correct/correct.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/correct/correct_loop.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/extract_and_inject/.gitignore +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/extract_and_inject/article_rag.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/extract_and_inject/ask.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/extract_and_inject/extract_and_inject.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/extract_article/extract.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/llm_usages/llm_usage.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/make_a_rating/rating.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/make_diary/commits.json +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/minor/hello_fabricatio.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/minor/write_a_poem.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/propose_task/propose.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/reviewer/review.py +0 -0
- {fabricatio-0.2.8.dev4/examples/write_article → fabricatio-0.2.9.dev1/examples/rules}/.gitignore +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/search_bibtex/.gitignore +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/search_bibtex/search.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/simple_chat/chat.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/simple_rag/simple_rag.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/write_article/article_rag.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/write_outline/.gitignore +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/actions/article_rag.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/actions/output.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/capabilities/advanced_judge.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/capabilities/propose.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/core.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/decorators.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/fs/__init__.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/fs/curd.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/fs/readers.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/journal.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/models/adv_kwargs_types.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/models/events.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/models/extra/advanced_judge.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/models/extra/article_base.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/models/extra/article_essence.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/models/extra/article_main.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/models/extra/article_outline.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/models/extra/article_proposal.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/models/extra/problem.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/models/kwargs_types.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/models/role.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/models/utils.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/parser.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/py.typed +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/toolboxes/__init__.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/toolboxes/arithmetic.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/toolboxes/fs.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/utils.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/workflows/articles.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/python/fabricatio/workflows/rag.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/src/bib_tools.rs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/src/hash.rs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/as_prompt.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/check_string.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/claude-xml.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/clean-up-code.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/co_validation.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/create_json_obj.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/dependencies.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/document-the-code.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/draft_rating_criteria.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/draft_rating_manual.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/draft_rating_weights_klee.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/draft_tool_usage_code.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/extract_criteria_from_reasons.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/extract_reasons_from_examples.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/fix-bugs.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/fix_troubled_obj.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/fix_troubled_string.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/generic_string.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/improve-performance.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/make_choice.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/make_judgment.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/pathstr.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/rate_fine_grind.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/refactor.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/retrieved_display.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/review_string.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/task_briefing.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/web-ctf-solver.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/write-git-commit.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/write-github-pull-request.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/templates/built-in/write-github-readme.hbs +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/tests/test_config.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/tests/test_models/test_action.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/tests/test_models/test_advanced.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/tests/test_models/test_generic.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/tests/test_models/test_role.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/tests/test_models/test_task.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/tests/test_models/test_tool.py +0 -0
- {fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/tests/test_models/test_usages.py +0 -0
@@ -453,6 +453,7 @@ dependencies = [
|
|
453
453
|
"rayon",
|
454
454
|
"serde_json",
|
455
455
|
"walkdir",
|
456
|
+
"whichlang",
|
456
457
|
]
|
457
458
|
|
458
459
|
[[package]]
|
@@ -2099,6 +2100,12 @@ dependencies = [
|
|
2099
2100
|
"wasm-bindgen",
|
2100
2101
|
]
|
2101
2102
|
|
2103
|
+
[[package]]
|
2104
|
+
name = "whichlang"
|
2105
|
+
version = "0.1.1"
|
2106
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
2107
|
+
checksum = "0b9aa3ad29c3d08283ac6b769e3ec15ad1ddb88af7d2e9bc402c574973b937e7"
|
2108
|
+
|
2102
2109
|
[[package]]
|
2103
2110
|
name = "winapi-util"
|
2104
2111
|
version = "0.1.9"
|
@@ -4,7 +4,7 @@ import asyncio
|
|
4
4
|
from datetime import datetime
|
5
5
|
from typing import Optional, Set, Unpack
|
6
6
|
|
7
|
-
from fabricatio import Action, Event, Role, Task, WorkFlow,
|
7
|
+
from fabricatio import Action, Event, Role, Task, WorkFlow, logger, toolboxes
|
8
8
|
from fabricatio.fs.readers import safe_json_read
|
9
9
|
from fabricatio.models.tool import ToolBox
|
10
10
|
from pydantic import Field
|
@@ -48,7 +48,7 @@ class WriteDiary(Action):
|
|
48
48
|
class DumpText(Action):
|
49
49
|
"""Dump the text to a file."""
|
50
50
|
|
51
|
-
toolboxes: Set[ToolBox] = Field(default_factory=lambda: {fs_toolbox})
|
51
|
+
toolboxes: Set[ToolBox] = Field(default_factory=lambda: {toolboxes.fs_toolbox})
|
52
52
|
output_key: str = "task_output"
|
53
53
|
|
54
54
|
async def _execute(self, task_input: Task, dump_text: str, **_: Unpack) -> Optional[str]:
|
@@ -0,0 +1,59 @@
|
|
1
|
+
"""Example of using the library."""
|
2
|
+
|
3
|
+
import asyncio
|
4
|
+
from typing import TYPE_CHECKING
|
5
|
+
|
6
|
+
from fabricatio import Event, Role, WorkFlow, logger
|
7
|
+
from fabricatio.actions.output import PersistentAll
|
8
|
+
from fabricatio.actions.rules import DraftRuleSet
|
9
|
+
from fabricatio.models.task import Task
|
10
|
+
from fabricatio.utils import ok
|
11
|
+
|
12
|
+
if TYPE_CHECKING:
|
13
|
+
from fabricatio.models.extra.rule import RuleSet
|
14
|
+
|
15
|
+
|
16
|
+
async def main() -> None:
|
17
|
+
"""Main function."""
|
18
|
+
Role(
|
19
|
+
name="Undergraduate Researcher",
|
20
|
+
llm_model="openai/qwen-plus",
|
21
|
+
llm_rpm=1000,
|
22
|
+
llm_tpm=3000000,
|
23
|
+
llm_max_tokens=8190,
|
24
|
+
registry={
|
25
|
+
Event.quick_instantiate(ns := "article"): WorkFlow(
|
26
|
+
name="write ruleset",
|
27
|
+
description="Generate an outline for an article. dump the outline to the given path. in typst format.",
|
28
|
+
steps=(
|
29
|
+
DraftRuleSet(
|
30
|
+
ruleset_requirement="1.when try to use an article as reference cited in our article, you should obey the format like (author1, author2 et al., YYYY)\n"
|
31
|
+
"2.we use typst to generate numeric citation. For example, for an article whose `bibtex_key` is `YanWindEnergy2018`, you can create a numeric citation by typing `#cite(<YanWindEnergy2018>)`(note that `bibtex_key` with `<` and `>` wrapped is needed), those notations could automatically be processed and output by compiler as a numeric citation like `[1]` in the upper right corner of text.\n"
|
32
|
+
"3.in addition, since `#cite()` can ONLY cite ONE article at once, we need use multiple `#cite()` notations to cite multiple articles, for example, there are three articles whose `bibtex_key` are `YanWindEnergy2018`, `YanWindEnergy2019`, `YanWindEnergy2020, you can cite them three as numeric citation by typing `#cite(<YanWindEnergy2018>)#cite(<YanWindEnergy2019>)#cite(<YanWindEnergy2020>)` those notations could automatically be processed and output by compiler as a numeric citation like `[1,2,3]` in the upper right corner of text.\n"
|
33
|
+
"4.to cover more references, we usually cite more than one articles that have similar opinions in a single sentence if possible.\n"
|
34
|
+
"5.when using `#cite()` notation, you must be aware of the cite key should be wrapped by `<` and `>`, compiler wont let it pass compilation otherwise.",
|
35
|
+
rule_count=5,
|
36
|
+
output_key="en_ruleset"
|
37
|
+
),
|
38
|
+
DraftRuleSet(
|
39
|
+
ruleset_requirement="1. 当在文章中引用其他文章作为参考文献时,应遵循(作者1,作者2等,年份)的格式进行标注。\n"
|
40
|
+
"2. 我们使用Typst生成数字引用格式。例如,对于BibTeX键为`YanWindEnergy2018`的文献,可通过输入`#cite(<YanWindEnergy2018>)`创建数字引用(注意:BibTeX键必须用尖括号`<`和`>`包裹)。这些标记会被编译器自动处理并输出为右上角的数字引用格式,例如文本旁的[1]。\n"
|
41
|
+
"3. 此外,由于`#cite()`每次只能引用单一文献,需通过叠加多个`#cite()`标记实现多文献引用。例如,若需引用三个BibTeX键分别为`YanWindEnergy2018`、`YanWindEnergy2019`和`YanWindEnergy2020`的文献,应输入`#cite(<YanWindEnergy2018>)#cite(<YanWindEnergy2019>)#cite(<YanWindEnergy2020>)`,编译后将呈现为[1,2,3]的右上角数字引用格式。\n"
|
42
|
+
"4. 为增加参考文献的覆盖率,我们通常建议在可能的情况下,将多个观点相似的文献合并引用于同一句子中。"
|
43
|
+
"5. 使用`#cite()`时需注意:BibTeX键必须用尖括号`<`和`>`包裹,否则编译器将拒绝通过编译。",
|
44
|
+
rule_count=5,
|
45
|
+
output_key="zh_ruleset"
|
46
|
+
),
|
47
|
+
PersistentAll(persist_dir="persistent"),
|
48
|
+
),
|
49
|
+
)
|
50
|
+
},
|
51
|
+
)
|
52
|
+
|
53
|
+
proposed_task: Task[RuleSet] = Task(name="write an ruleset")
|
54
|
+
ruleset = ok(await proposed_task.delegate(ns), "Failed to generate ruleset")
|
55
|
+
logger.success(f"The rule is: \n{ruleset.display()}")
|
56
|
+
|
57
|
+
|
58
|
+
if __name__ == "__main__":
|
59
|
+
asyncio.run(main())
|
@@ -3,7 +3,7 @@
|
|
3
3
|
import asyncio
|
4
4
|
from typing import Any, Set, Unpack
|
5
5
|
|
6
|
-
from fabricatio import Action, Event, PythonCapture, Role, Task, ToolBox, WorkFlow,
|
6
|
+
from fabricatio import Action, Event, PythonCapture, Role, Task, ToolBox, WorkFlow, logger, toolboxes
|
7
7
|
from pydantic import Field
|
8
8
|
|
9
9
|
|
@@ -23,7 +23,7 @@ class WriteCode(Action):
|
|
23
23
|
class DumpText(Action):
|
24
24
|
"""Dump the text to a file."""
|
25
25
|
|
26
|
-
toolboxes: Set[ToolBox] = Field(default_factory=lambda: {fs_toolbox})
|
26
|
+
toolboxes: Set[ToolBox] = Field(default_factory=lambda: {toolboxes.fs_toolbox})
|
27
27
|
output_key: str = "task_output"
|
28
28
|
|
29
29
|
async def _execute(self, task_input: Task, dump_text: str, **_: Unpack) -> Any:
|
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
import asyncio
|
4
4
|
|
5
|
-
from fabricatio import Event, Role,
|
5
|
+
from fabricatio import Event, Role, logger
|
6
|
+
from fabricatio.workflows.articles import WriteOutlineCorrectedWorkFlow
|
6
7
|
|
7
8
|
|
8
9
|
async def main() -> None:
|
@@ -10,7 +11,7 @@ async def main() -> None:
|
|
10
11
|
role = Role(
|
11
12
|
name="Undergraduate Researcher",
|
12
13
|
description="Write an outline for an article in typst format.",
|
13
|
-
registry={Event.quick_instantiate(ns := "article"):
|
14
|
+
registry={Event.quick_instantiate(ns := "article"): WriteOutlineCorrectedWorkFlow},
|
14
15
|
)
|
15
16
|
|
16
17
|
proposed_task = await role.propose_task(
|
{fabricatio-0.2.8.dev4 → fabricatio-0.2.9.dev1}/examples/write_outline/write_outline_corrected.py
RENAMED
@@ -3,7 +3,7 @@
|
|
3
3
|
import asyncio
|
4
4
|
|
5
5
|
from fabricatio import Event, Role, WorkFlow, logger
|
6
|
-
from fabricatio.actions.article import CorrectOutline, CorrectProposal, GenerateArticleProposal,
|
6
|
+
from fabricatio.actions.article import CorrectOutline, CorrectProposal, GenerateArticleProposal, GenerateInitialOutline
|
7
7
|
from fabricatio.actions.output import DumpFinalizedOutput
|
8
8
|
|
9
9
|
|
@@ -25,7 +25,7 @@ async def main() -> None:
|
|
25
25
|
llm_model="deepseek/deepseek-reasoner",
|
26
26
|
llm_temperature=1.3,
|
27
27
|
),
|
28
|
-
|
28
|
+
GenerateInitialOutline(llm_model="deepseek/deepseek-chat", llm_temperature=1.4, llm_top_p=0.5),
|
29
29
|
CorrectOutline(output_key="to_dump", llm_temperature=1.4, llm_top_p=0.45),
|
30
30
|
DumpFinalizedOutput(output_key="task_output"),
|
31
31
|
),
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[project]
|
2
2
|
name = "fabricatio"
|
3
|
-
version = "0.2.
|
3
|
+
version = "0.2.9-dev1"
|
4
4
|
description = "A LLM multi-agent framework."
|
5
5
|
readme = "README.md"
|
6
6
|
license = { file = "LICENSE" }
|
@@ -57,7 +57,7 @@ build-backend = "maturin"
|
|
57
57
|
|
58
58
|
[tool.maturin]
|
59
59
|
python-source = "python"
|
60
|
-
module-name = "fabricatio.
|
60
|
+
module-name = "fabricatio.rust"
|
61
61
|
data = "extra"
|
62
62
|
[dependency-groups]
|
63
63
|
dev = [
|
@@ -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."""
|
@@ -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):
|
@@ -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](
|
@@ -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
|
|
@@ -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
|
|
@@ -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):
|
@@ -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
|
|
@@ -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."""
|
@@ -0,0 +1,20 @@
|
|
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
|
+
|
3
|
+
from typing import Optional, Type
|
4
|
+
|
5
|
+
from fabricatio.models.extra.rule import RuleSet
|
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."""
|
12
|
+
|
13
|
+
|
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
|
@@ -0,0 +1,40 @@
|
|
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
|
+
"""
|
10
|
+
|
11
|
+
from typing import List
|
12
|
+
|
13
|
+
from fabricatio.models.generic import Language, PersistentAble, SketchedAble, WithBriefing
|
14
|
+
|
15
|
+
|
16
|
+
class Rule(WithBriefing,Language, SketchedAble,PersistentAble):
|
17
|
+
"""Represents a rule or guideline for a specific topic."""
|
18
|
+
|
19
|
+
|
20
|
+
violation_examples: List[str]
|
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
|
+
|
26
|
+
compliance_examples: List[str]
|
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."""
|
31
|
+
|
32
|
+
|
33
|
+
class RuleSet( SketchedAble, PersistentAble, WithBriefing,Language):
|
34
|
+
"""Represents a collection of rules and guidelines for a particular topic."""
|
35
|
+
|
36
|
+
rules: List[Rule]
|
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."""
|