fabricatio 0.2.7.dev5__tar.gz → 0.2.8.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.7.dev5 → fabricatio-0.2.8.dev1}/PKG-INFO +1 -1
- {fabricatio-0.2.7.dev5/examples/write_outline → fabricatio-0.2.8.dev1/examples/write_article}/.gitignore +2 -1
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/write_article/write_article.py +8 -5
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/pyproject.toml +1 -1
- fabricatio-0.2.8.dev1/python/fabricatio/actions/article.py +333 -0
- fabricatio-0.2.8.dev1/python/fabricatio/actions/output.py +69 -0
- fabricatio-0.2.8.dev1/python/fabricatio/capabilities/advanced_judge.py +23 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/capabilities/correct.py +26 -6
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/capabilities/rating.py +1 -1
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/capabilities/review.py +2 -2
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/models/action.py +3 -1
- fabricatio-0.2.8.dev1/python/fabricatio/models/extra/advanced_judge.py +22 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/models/extra/article_base.py +196 -86
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/models/extra/article_essence.py +6 -9
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/models/extra/article_main.py +29 -49
- fabricatio-0.2.8.dev1/python/fabricatio/models/extra/article_outline.py +41 -0
- fabricatio-0.2.8.dev1/python/fabricatio/models/extra/article_proposal.py +33 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/models/generic.py +12 -16
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/models/usages.py +5 -1
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/create_json_obj.hbs +1 -1
- fabricatio-0.2.8.dev1/templates.tar.gz +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/uv.lock +281 -289
- fabricatio-0.2.7.dev5/python/fabricatio/actions/article.py +0 -219
- fabricatio-0.2.7.dev5/python/fabricatio/actions/output.py +0 -34
- fabricatio-0.2.7.dev5/python/fabricatio/models/extra/article_outline.py +0 -187
- fabricatio-0.2.7.dev5/python/fabricatio/models/extra/article_proposal.py +0 -35
- fabricatio-0.2.7.dev5/templates.tar.gz +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/.github/workflows/build-package.yaml +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/.github/workflows/ruff.yaml +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/.github/workflows/tests.yaml +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/.gitignore +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/.python-version +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/Cargo.lock +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/Cargo.toml +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/LICENSE +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/Makefile +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/README.md +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/correct/correct.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/correct/correct_loop.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/extract_and_inject/.gitignore +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/extract_and_inject/article_rag.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/extract_and_inject/ask.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/extract_and_inject/extract_and_inject.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/extract_article/extract.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/llm_usages/llm_usage.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/make_a_rating/rating.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/make_diary/commits.json +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/make_diary/diary.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/minor/hello_fabricatio.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/minor/write_a_poem.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/propose_task/propose.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/reviewer/review.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/search_bibtex/.gitignore +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/search_bibtex/search.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/simple_chat/chat.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/simple_rag/simple_rag.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/task_handle/handle_task.py +0 -0
- {fabricatio-0.2.7.dev5/examples/write_article → fabricatio-0.2.8.dev1/examples/write_outline}/.gitignore +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/write_outline/write_outline.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/examples/write_outline/write_outline_corrected.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/__init__.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/_rust.pyi +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/_rust_instances.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/actions/article_rag.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/actions/rag.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/capabilities/propose.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/capabilities/rag.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/capabilities/task.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/config.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/core.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/decorators.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/fs/__init__.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/fs/curd.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/fs/readers.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/journal.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/models/events.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/models/kwargs_types.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/models/role.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/models/task.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/models/tool.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/models/utils.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/parser.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/py.typed +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/toolboxes/__init__.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/toolboxes/arithmetic.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/toolboxes/fs.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/workflows/articles.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/python/fabricatio/workflows/rag.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/src/bib_tools.rs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/src/hash.rs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/src/hbs_helpers.rs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/src/lib.rs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/src/templates.rs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/as_prompt.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/claude-xml.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/clean-up-code.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/co_validation.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/correct.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/dependencies.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/document-the-code.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/draft_rating_criteria.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/draft_rating_manual.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/draft_rating_weights_klee.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/draft_tool_usage_code.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/extract_criteria_from_reasons.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/extract_reasons_from_examples.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/fix-bugs.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/generic_string.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/improve-performance.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/liststr.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/make_choice.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/make_judgment.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/pathstr.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/rate_fine_grind.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/refactor.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/refined_query.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/retrieved_display.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/review_string.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/task_briefing.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/web-ctf-solver.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/write-git-commit.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/write-github-pull-request.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/templates/built-in/write-github-readme.hbs +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/tests/test_config.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/tests/test_models/test_action.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/tests/test_models/test_advanced.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/tests/test_models/test_generic.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/tests/test_models/test_role.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/tests/test_models/test_task.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/tests/test_models/test_tool.py +0 -0
- {fabricatio-0.2.7.dev5 → fabricatio-0.2.8.dev1}/tests/test_models/test_usages.py +0 -0
@@ -9,7 +9,7 @@ from fabricatio.actions.article import (
|
|
9
9
|
GenerateArticleProposal,
|
10
10
|
GenerateOutline,
|
11
11
|
)
|
12
|
-
from fabricatio.actions.output import DumpFinalizedOutput
|
12
|
+
from fabricatio.actions.output import DumpFinalizedOutput, PersistentAll
|
13
13
|
from fabricatio.models.task import Task
|
14
14
|
|
15
15
|
|
@@ -20,9 +20,7 @@ async def main() -> None:
|
|
20
20
|
description="Write an outline for an article in typst format.",
|
21
21
|
llm_top_p=0.8,
|
22
22
|
llm_temperature=1.15,
|
23
|
-
|
24
|
-
llm_model="openai/qwen-max",
|
25
|
-
llm_stream=True,
|
23
|
+
llm_model="litellm_proxy/qwen-max",
|
26
24
|
registry={
|
27
25
|
Event.quick_instantiate(ns := "article"): WorkFlow(
|
28
26
|
name="Generate Article Outline",
|
@@ -32,8 +30,13 @@ async def main() -> None:
|
|
32
30
|
GenerateOutline(llm_temperature=1.21, llm_top_p=0.3),
|
33
31
|
GenerateArticle(output_key="to_dump", llm_temperature=1.2, llm_top_p=0.45),
|
34
32
|
DumpFinalizedOutput(output_key="task_output"),
|
33
|
+
PersistentAll,
|
35
34
|
),
|
36
|
-
).update_init_context(
|
35
|
+
).update_init_context(
|
36
|
+
article_briefing=Path("./article_briefing.txt").read_text(),
|
37
|
+
dump_path="out.typ",
|
38
|
+
persist_dir="persistent",
|
39
|
+
)
|
37
40
|
},
|
38
41
|
)
|
39
42
|
|
@@ -0,0 +1,333 @@
|
|
1
|
+
"""Actions for transmitting tasks to targets."""
|
2
|
+
|
3
|
+
from asyncio import gather
|
4
|
+
from pathlib import Path
|
5
|
+
from typing import Any, Callable, List, Optional
|
6
|
+
|
7
|
+
from fabricatio.capabilities.advanced_judge import AdvancedJudge
|
8
|
+
from fabricatio.fs import safe_text_read
|
9
|
+
from fabricatio.journal import logger
|
10
|
+
from fabricatio.models.action import Action
|
11
|
+
from fabricatio.models.extra.article_base import ArticleRefPatch
|
12
|
+
from fabricatio.models.extra.article_essence import ArticleEssence
|
13
|
+
from fabricatio.models.extra.article_main import Article
|
14
|
+
from fabricatio.models.extra.article_outline import ArticleOutline
|
15
|
+
from fabricatio.models.extra.article_proposal import ArticleProposal
|
16
|
+
from fabricatio.models.task import Task
|
17
|
+
from fabricatio.models.utils import ok
|
18
|
+
|
19
|
+
|
20
|
+
class ExtractArticleEssence(Action):
|
21
|
+
"""Extract the essence of article(s) in text format from the paths specified in the task dependencies.
|
22
|
+
|
23
|
+
Notes:
|
24
|
+
This action is designed to extract vital information from articles with Markdown format, which is pure text, and
|
25
|
+
which is converted from pdf files using `magic-pdf` from the `MinerU` project, see https://github.com/opendatalab/MinerU
|
26
|
+
"""
|
27
|
+
|
28
|
+
output_key: str = "article_essence"
|
29
|
+
"""The key of the output data."""
|
30
|
+
|
31
|
+
async def _execute(
|
32
|
+
self,
|
33
|
+
task_input: Task,
|
34
|
+
reader: Callable[[str], str] = lambda p: Path(p).read_text(encoding="utf-8"),
|
35
|
+
**_,
|
36
|
+
) -> Optional[List[ArticleEssence]]:
|
37
|
+
if not task_input.dependencies:
|
38
|
+
logger.info(err := "Task not approved, since no dependencies are provided.")
|
39
|
+
raise RuntimeError(err)
|
40
|
+
|
41
|
+
# trim the references
|
42
|
+
contents = ["References".join(c.split("References")[:-1]) for c in map(reader, task_input.dependencies)]
|
43
|
+
return await self.propose(
|
44
|
+
ArticleEssence,
|
45
|
+
contents,
|
46
|
+
system_message=f"# your personal briefing: \n{self.briefing}",
|
47
|
+
)
|
48
|
+
|
49
|
+
|
50
|
+
class GenerateArticleProposal(Action):
|
51
|
+
"""Generate an outline for the article based on the extracted essence."""
|
52
|
+
|
53
|
+
output_key: str = "article_proposal"
|
54
|
+
"""The key of the output data."""
|
55
|
+
|
56
|
+
async def _execute(
|
57
|
+
self,
|
58
|
+
task_input: Optional[Task] = None,
|
59
|
+
article_briefing: Optional[str] = None,
|
60
|
+
article_briefing_path: Optional[str] = None,
|
61
|
+
langauge: Optional[str] = None,
|
62
|
+
**_,
|
63
|
+
) -> Optional[ArticleProposal]:
|
64
|
+
if article_briefing is None and article_briefing_path is None and task_input is None:
|
65
|
+
logger.error("Task not approved, since all inputs are None.")
|
66
|
+
return None
|
67
|
+
|
68
|
+
proposal = ok(
|
69
|
+
await self.propose(
|
70
|
+
ArticleProposal,
|
71
|
+
briefing := (
|
72
|
+
article_briefing
|
73
|
+
or safe_text_read(
|
74
|
+
ok(
|
75
|
+
article_briefing_path
|
76
|
+
or await self.awhich_pathstr(
|
77
|
+
f"{ok(task_input).briefing}\nExtract the path of file which contains the article briefing."
|
78
|
+
),
|
79
|
+
"Could not find the path of file to read.",
|
80
|
+
)
|
81
|
+
)
|
82
|
+
),
|
83
|
+
**self.prepend_sys_msg(),
|
84
|
+
),
|
85
|
+
"Could not generate the proposal.",
|
86
|
+
).update_ref(briefing)
|
87
|
+
if langauge:
|
88
|
+
proposal.language = langauge
|
89
|
+
|
90
|
+
return proposal
|
91
|
+
|
92
|
+
|
93
|
+
class GenerateInitialOutline(Action):
|
94
|
+
"""Generate the initial article outline based on the article proposal."""
|
95
|
+
|
96
|
+
output_key: str = "initial_article_outline"
|
97
|
+
"""The key of the output data."""
|
98
|
+
|
99
|
+
async def _execute(
|
100
|
+
self,
|
101
|
+
article_proposal: ArticleProposal,
|
102
|
+
**_,
|
103
|
+
) -> Optional[ArticleOutline]:
|
104
|
+
return ok(
|
105
|
+
await self.propose(
|
106
|
+
ArticleOutline,
|
107
|
+
article_proposal.as_prompt(),
|
108
|
+
**self.prepend_sys_msg(),
|
109
|
+
),
|
110
|
+
"Could not generate the initial outline.",
|
111
|
+
)
|
112
|
+
|
113
|
+
|
114
|
+
class FixIntrospectedErrors(Action):
|
115
|
+
"""Fix introspected errors in the article outline."""
|
116
|
+
|
117
|
+
output_key: str = "introspected_errors_fixed_outline"
|
118
|
+
"""The key of the output data."""
|
119
|
+
|
120
|
+
async def _execute(
|
121
|
+
self,
|
122
|
+
article_outline: ArticleOutline,
|
123
|
+
**_,
|
124
|
+
) -> Optional[ArticleOutline]:
|
125
|
+
introspect_manual = ok(
|
126
|
+
await self.draft_rating_manual(
|
127
|
+
topic=(
|
128
|
+
intro_topic
|
129
|
+
:= "Fix the error in the article outline, make sure there is no more error in the article outline."
|
130
|
+
),
|
131
|
+
),
|
132
|
+
"Could not generate the rating manual.",
|
133
|
+
)
|
134
|
+
|
135
|
+
while pack := article_outline.find_introspected():
|
136
|
+
component, err = ok(pack)
|
137
|
+
logger.warning(f"Found introspected error: {err}")
|
138
|
+
corrected = ok(
|
139
|
+
await self.correct_obj(
|
140
|
+
component,
|
141
|
+
reference=f"# Original Article Outline\n{article_outline.display()}\n# Error Need to be fixed\n{err}",
|
142
|
+
topic=intro_topic,
|
143
|
+
rating_manual=introspect_manual,
|
144
|
+
supervisor_check=False,
|
145
|
+
),
|
146
|
+
"Could not correct the component.",
|
147
|
+
)
|
148
|
+
component.update_from(corrected)
|
149
|
+
|
150
|
+
return article_outline
|
151
|
+
|
152
|
+
|
153
|
+
class FixIllegalReferences(Action):
|
154
|
+
"""Fix illegal references in the article outline."""
|
155
|
+
|
156
|
+
output_key: str = "illegal_references_fixed_outline"
|
157
|
+
"""The key of the output data."""
|
158
|
+
|
159
|
+
async def _execute(
|
160
|
+
self,
|
161
|
+
article_outline: ArticleOutline,
|
162
|
+
**_,
|
163
|
+
) -> Optional[ArticleOutline]:
|
164
|
+
ref_manual = ok(
|
165
|
+
await self.draft_rating_manual(
|
166
|
+
topic=(
|
167
|
+
ref_topic
|
168
|
+
:= "Fix the internal referring error, make sure there is no more `ArticleRef` pointing to a non-existing article component."
|
169
|
+
),
|
170
|
+
),
|
171
|
+
"Could not generate the rating manual.",
|
172
|
+
)
|
173
|
+
|
174
|
+
while pack := article_outline.find_illegal_ref():
|
175
|
+
ref, err = ok(pack)
|
176
|
+
logger.warning(f"Found illegal referring error: {err}")
|
177
|
+
ok(
|
178
|
+
await self.correct_obj_inplace(
|
179
|
+
ref,
|
180
|
+
reference=f"# Original Article Outline\n{article_outline.display()}\n# Error Need to be fixed\n{err}\n\n",
|
181
|
+
topic=ref_topic,
|
182
|
+
rating_manual=ref_manual,
|
183
|
+
supervisor_check=False,
|
184
|
+
)
|
185
|
+
)
|
186
|
+
return article_outline.update_ref(article_outline)
|
187
|
+
|
188
|
+
|
189
|
+
class TweakOutlineBackwardRef(Action, AdvancedJudge):
|
190
|
+
"""Tweak the backward references in the article outline.
|
191
|
+
|
192
|
+
Ensures that the prerequisites of the current chapter are correctly referenced in the `depend_on` field.
|
193
|
+
"""
|
194
|
+
|
195
|
+
output_key: str = "article_outline_bw_ref_checked"
|
196
|
+
|
197
|
+
async def _execute(self, article_outline: ArticleOutline, **cxt) -> ArticleOutline:
|
198
|
+
tweak_depend_on_manual = ok(
|
199
|
+
await self.draft_rating_manual(
|
200
|
+
topic := "Ensure prerequisites are correctly referenced in the `depend_on` field."
|
201
|
+
),
|
202
|
+
"Could not generate the rating manual.",
|
203
|
+
)
|
204
|
+
|
205
|
+
for a in article_outline.iter_dfs():
|
206
|
+
if await self.evidently_judge(
|
207
|
+
f"{article_outline.as_prompt()}\n\n{a.display()}\n"
|
208
|
+
f"Does the `{a.__class__.__name__}`'s `depend_on` field need to be extended or tweaked?"
|
209
|
+
):
|
210
|
+
patch=ArticleRefPatch.default()
|
211
|
+
patch.tweaked=a.depend_on
|
212
|
+
|
213
|
+
await self.correct_obj_inplace(
|
214
|
+
patch,
|
215
|
+
topic=topic,
|
216
|
+
reference=f"{article_outline.as_prompt()}\nThe Article component whose `depend_on` field needs to be extended or tweaked",
|
217
|
+
rating_manual=tweak_depend_on_manual,
|
218
|
+
)
|
219
|
+
|
220
|
+
return article_outline
|
221
|
+
|
222
|
+
|
223
|
+
class TweakOutlineForwardRef(Action, AdvancedJudge):
|
224
|
+
"""Tweak the forward references in the article outline.
|
225
|
+
|
226
|
+
Ensures that the conclusions of the current chapter effectively support the analysis of subsequent chapters.
|
227
|
+
"""
|
228
|
+
|
229
|
+
output_key: str = "article_outline_fw_ref_checked"
|
230
|
+
|
231
|
+
async def _execute(self, article_outline: ArticleOutline, **cxt) -> ArticleOutline:
|
232
|
+
tweak_support_to_manual = ok(
|
233
|
+
await self.draft_rating_manual(
|
234
|
+
topic := "Ensure conclusions support the analysis of subsequent chapters, sections or subsections."
|
235
|
+
),
|
236
|
+
"Could not generate the rating manual.",
|
237
|
+
)
|
238
|
+
|
239
|
+
for a in article_outline.iter_dfs():
|
240
|
+
if await self.evidently_judge(
|
241
|
+
f"{article_outline.as_prompt()}\n\n{a.display()}\n"
|
242
|
+
f"Does the `{a.__class__.__name__}`'s `support_to` field need to be extended or tweaked?"
|
243
|
+
):
|
244
|
+
patch=ArticleRefPatch.default()
|
245
|
+
patch.tweaked=a.support_to
|
246
|
+
|
247
|
+
await self.correct_obj_inplace(
|
248
|
+
patch,
|
249
|
+
topic=topic,
|
250
|
+
reference=f"{article_outline.as_prompt()}\nThe Article component whose `support_to` field needs to be extended or tweaked",
|
251
|
+
rating_manual=tweak_support_to_manual,
|
252
|
+
)
|
253
|
+
|
254
|
+
return article_outline
|
255
|
+
|
256
|
+
|
257
|
+
class GenerateArticle(Action):
|
258
|
+
"""Generate the article based on the outline."""
|
259
|
+
|
260
|
+
output_key: str = "article"
|
261
|
+
"""The key of the output data."""
|
262
|
+
|
263
|
+
async def _execute(
|
264
|
+
self,
|
265
|
+
article_outline: ArticleOutline,
|
266
|
+
**_,
|
267
|
+
) -> Optional[Article]:
|
268
|
+
article: Article = Article.from_outline(ok(article_outline, "Article outline not specified.")).update_ref(
|
269
|
+
article_outline
|
270
|
+
)
|
271
|
+
|
272
|
+
write_para_manual = ok(
|
273
|
+
await self.draft_rating_manual(w_topic := "write the following paragraph in the subsection.")
|
274
|
+
)
|
275
|
+
|
276
|
+
await gather(
|
277
|
+
*[
|
278
|
+
self.correct_obj_inplace(
|
279
|
+
subsec,
|
280
|
+
reference=f"# Original Article Outline\n{article_outline.display()}\n# Error Need to be fixed\n{err}",
|
281
|
+
topic=w_topic,
|
282
|
+
rating_manual=write_para_manual,
|
283
|
+
supervisor_check=False,
|
284
|
+
)
|
285
|
+
for _, __, subsec in article.iter_subsections()
|
286
|
+
if (err := subsec.introspect())
|
287
|
+
],
|
288
|
+
return_exceptions=True,
|
289
|
+
)
|
290
|
+
|
291
|
+
return article
|
292
|
+
|
293
|
+
|
294
|
+
class CorrectProposal(Action):
|
295
|
+
"""Correct the proposal of the article."""
|
296
|
+
|
297
|
+
output_key: str = "corrected_proposal"
|
298
|
+
|
299
|
+
async def _execute(self, article_proposal: ArticleProposal, **_) -> Any:
|
300
|
+
return (await self.censor_obj(article_proposal, reference=article_proposal.referenced)).update_ref(
|
301
|
+
article_proposal
|
302
|
+
)
|
303
|
+
|
304
|
+
|
305
|
+
class CorrectOutline(Action):
|
306
|
+
"""Correct the outline of the article."""
|
307
|
+
|
308
|
+
output_key: str = "corrected_outline"
|
309
|
+
"""The key of the output data."""
|
310
|
+
|
311
|
+
async def _execute(
|
312
|
+
self,
|
313
|
+
article_outline: ArticleOutline,
|
314
|
+
**_,
|
315
|
+
) -> ArticleOutline:
|
316
|
+
return (await self.censor_obj(article_outline, reference=article_outline.referenced.as_prompt())).update_ref(
|
317
|
+
article_outline
|
318
|
+
)
|
319
|
+
|
320
|
+
|
321
|
+
class CorrectArticle(Action):
|
322
|
+
"""Correct the article based on the outline."""
|
323
|
+
|
324
|
+
output_key: str = "corrected_article"
|
325
|
+
"""The key of the output data."""
|
326
|
+
|
327
|
+
async def _execute(
|
328
|
+
self,
|
329
|
+
article: Article,
|
330
|
+
article_outline: ArticleOutline,
|
331
|
+
**_,
|
332
|
+
) -> Article:
|
333
|
+
return await self.censor_obj(article, reference=article_outline.referenced.as_prompt())
|
@@ -0,0 +1,69 @@
|
|
1
|
+
"""Dump the finalized output to a file."""
|
2
|
+
|
3
|
+
from pathlib import Path
|
4
|
+
from typing import Optional
|
5
|
+
|
6
|
+
from fabricatio.journal import logger
|
7
|
+
from fabricatio.models.action import Action
|
8
|
+
from fabricatio.models.generic import FinalizedDumpAble, PersistentAble
|
9
|
+
from fabricatio.models.task import Task
|
10
|
+
from fabricatio.models.utils import ok
|
11
|
+
|
12
|
+
|
13
|
+
class DumpFinalizedOutput(Action):
|
14
|
+
"""Dump the finalized output to a file."""
|
15
|
+
|
16
|
+
output_key: str = "dump_path"
|
17
|
+
|
18
|
+
async def _execute(
|
19
|
+
self,
|
20
|
+
to_dump: FinalizedDumpAble,
|
21
|
+
task_input: Optional[Task] = None,
|
22
|
+
dump_path: Optional[str | Path] = None,
|
23
|
+
**_,
|
24
|
+
) -> str:
|
25
|
+
dump_path = Path(
|
26
|
+
dump_path
|
27
|
+
or ok(
|
28
|
+
await self.awhich_pathstr(
|
29
|
+
f"{ok(task_input, 'Neither `task_input` and `dump_path` is provided.').briefing}\n\nExtract a single path of the file, to which I will dump the data."
|
30
|
+
),
|
31
|
+
"Could not find the path of file to dump the data.",
|
32
|
+
)
|
33
|
+
)
|
34
|
+
ok(to_dump, "Could not dump the data since the path is not specified.").finalized_dump_to(dump_path)
|
35
|
+
return dump_path.as_posix()
|
36
|
+
|
37
|
+
|
38
|
+
class PersistentAll(Action):
|
39
|
+
"""Persist all the data to a file."""
|
40
|
+
|
41
|
+
output_key: str = "persistent_count"
|
42
|
+
|
43
|
+
async def _execute(
|
44
|
+
self,
|
45
|
+
task_input: Optional[Task] = None,
|
46
|
+
persist_dir: Optional[str | Path] = None,
|
47
|
+
**cxt,
|
48
|
+
) -> int:
|
49
|
+
persist_dir = Path(
|
50
|
+
persist_dir
|
51
|
+
or ok(
|
52
|
+
await self.awhich_pathstr(
|
53
|
+
f"{ok(task_input, 'Neither `task_input` and `dump_path` is provided.').briefing}\n\nExtract a single path of the file, to which I will persist the data."
|
54
|
+
),
|
55
|
+
"Can not find the path of file to persist the data.",
|
56
|
+
)
|
57
|
+
)
|
58
|
+
|
59
|
+
count = 0
|
60
|
+
if persist_dir.is_file():
|
61
|
+
logger.warning("Dump should be a directory, but it is a file. Skip dumping.")
|
62
|
+
return count
|
63
|
+
persist_dir.mkdir(parents=True, exist_ok=True)
|
64
|
+
for v in cxt.values():
|
65
|
+
if isinstance(v, PersistentAble):
|
66
|
+
v.persist(persist_dir)
|
67
|
+
count += 1
|
68
|
+
|
69
|
+
return count
|
@@ -0,0 +1,23 @@
|
|
1
|
+
"""The Capabilities module for advanced judging."""
|
2
|
+
|
3
|
+
from typing import Optional, Unpack
|
4
|
+
|
5
|
+
from fabricatio.capabilities.propose import Propose
|
6
|
+
from fabricatio.models.extra.advanced_judge import JudgeMent
|
7
|
+
from fabricatio.models.kwargs_types import ValidateKwargs
|
8
|
+
|
9
|
+
|
10
|
+
class AdvancedJudge(Propose):
|
11
|
+
"""A class that judges the evidence and makes a final decision."""
|
12
|
+
async def evidently_judge(
|
13
|
+
self,
|
14
|
+
prompt: str,
|
15
|
+
**kwargs: Unpack[ValidateKwargs[JudgeMent]],
|
16
|
+
) -> Optional[JudgeMent]:
|
17
|
+
"""Judge the evidence and make a final decision."""
|
18
|
+
return await self.propose(
|
19
|
+
JudgeMent,
|
20
|
+
prompt,
|
21
|
+
**kwargs
|
22
|
+
)
|
23
|
+
|
@@ -10,7 +10,7 @@ from typing import Optional, Unpack, cast
|
|
10
10
|
from fabricatio._rust_instances import TEMPLATE_MANAGER
|
11
11
|
from fabricatio.capabilities.review import Review, ReviewResult
|
12
12
|
from fabricatio.config import configs
|
13
|
-
from fabricatio.models.generic import CensoredAble, Display, ProposedAble, WithBriefing
|
13
|
+
from fabricatio.models.generic import CensoredAble, Display, ProposedAble, ProposedUpdateAble, WithBriefing
|
14
14
|
from fabricatio.models.kwargs_types import CensoredCorrectKwargs, CorrectKwargs, ReviewKwargs
|
15
15
|
from fabricatio.models.task import Task
|
16
16
|
from questionary import confirm, text
|
@@ -134,12 +134,32 @@ class Correct(Review):
|
|
134
134
|
while await confirm("Begin to correct obj above with human censorship?").ask_async():
|
135
135
|
while (topic := await text("What is the topic of the obj reviewing?").ask_async()) is not None and topic:
|
136
136
|
...
|
137
|
-
if (
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
137
|
+
if (
|
138
|
+
modified_obj := await self.correct_obj(
|
139
|
+
last_modified_obj,
|
140
|
+
topic=topic,
|
141
|
+
**kwargs,
|
142
|
+
)
|
143
|
+
) is None:
|
142
144
|
break
|
143
145
|
last_modified_obj = modified_obj
|
144
146
|
rprint(last_modified_obj.finalized_dump())
|
145
147
|
return modified_obj or last_modified_obj
|
148
|
+
|
149
|
+
async def correct_obj_inplace[M: ProposedUpdateAble](
|
150
|
+
self, obj: M, **kwargs: Unpack[CorrectKwargs[ReviewResult[str]]]
|
151
|
+
) -> Optional[M]:
|
152
|
+
"""Correct an object in place based on defined criteria and templates.
|
153
|
+
|
154
|
+
Args:
|
155
|
+
obj (M): The object to be corrected.
|
156
|
+
**kwargs (Unpack[CensoredCorrectKwargs]): Additional keyword arguments for the correction process.
|
157
|
+
|
158
|
+
Returns:
|
159
|
+
Optional[M]: The corrected object, or None if correction fails.
|
160
|
+
"""
|
161
|
+
corrected_obj = await self.correct_obj(obj, **kwargs)
|
162
|
+
if corrected_obj is None:
|
163
|
+
return corrected_obj
|
164
|
+
obj.update_from(corrected_obj)
|
165
|
+
return obj
|
@@ -16,7 +16,7 @@ from more_itertools import flatten, windowed
|
|
16
16
|
from pydantic import NonNegativeInt, PositiveInt
|
17
17
|
|
18
18
|
|
19
|
-
class
|
19
|
+
class Rating(WithBriefing, LLMUsage):
|
20
20
|
"""A class that provides functionality to rate tasks based on a rating manual and score range.
|
21
21
|
|
22
22
|
References:
|
@@ -4,7 +4,7 @@ from typing import Dict, List, Optional, Self, Set, Unpack, cast
|
|
4
4
|
|
5
5
|
from fabricatio._rust_instances import TEMPLATE_MANAGER
|
6
6
|
from fabricatio.capabilities.propose import Propose
|
7
|
-
from fabricatio.capabilities.rating import
|
7
|
+
from fabricatio.capabilities.rating import Rating
|
8
8
|
from fabricatio.config import configs
|
9
9
|
from fabricatio.models.generic import Base, Display, ProposedAble, WithBriefing
|
10
10
|
from fabricatio.models.kwargs_types import ReviewKwargs, ValidateKwargs
|
@@ -175,7 +175,7 @@ class ReviewResult[T](ProposedAble, Display):
|
|
175
175
|
return self
|
176
176
|
|
177
177
|
|
178
|
-
class Review(
|
178
|
+
class Review(Rating, Propose):
|
179
179
|
"""Class that provides functionality to review tasks and strings using a language model.
|
180
180
|
|
181
181
|
This class extends GiveRating and Propose capabilities to analyze content,
|
@@ -170,6 +170,8 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
|
|
170
170
|
# Update context with modified values
|
171
171
|
modified_ctx = await act_task
|
172
172
|
logger.success(f"Step execution finished: {current_action}")
|
173
|
+
if step.output_key:
|
174
|
+
logger.success(f"Setting output: {step.output_key}")
|
173
175
|
await self._context.put(modified_ctx)
|
174
176
|
|
175
177
|
logger.success(f"Workflow execution finished: {self.name}")
|
@@ -219,7 +221,7 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
|
|
219
221
|
self.provide_tools_to(self._instances)
|
220
222
|
return self
|
221
223
|
|
222
|
-
def update_init_context(self, **kwargs) -> Self:
|
224
|
+
def update_init_context(self, /, **kwargs) -> Self:
|
223
225
|
"""Update the initial context with additional key-value pairs.
|
224
226
|
|
225
227
|
Args:
|
@@ -0,0 +1,22 @@
|
|
1
|
+
"""A module containing the JudgeMent class."""
|
2
|
+
|
3
|
+
from typing import List
|
4
|
+
|
5
|
+
from fabricatio.models.generic import ProposedAble
|
6
|
+
|
7
|
+
|
8
|
+
class JudgeMent(ProposedAble):
|
9
|
+
"""A class representing a judgment made by a judge."""
|
10
|
+
|
11
|
+
affirm_evidence: List[str]
|
12
|
+
"""List of evidence supporting the affirmation."""
|
13
|
+
|
14
|
+
deny_evidence: List[str]
|
15
|
+
"""List of evidence supporting the denial."""
|
16
|
+
|
17
|
+
final_judgement: bool
|
18
|
+
"""The final judgement."""
|
19
|
+
|
20
|
+
def __bool__(self) -> bool:
|
21
|
+
"""Return the final judgement."""
|
22
|
+
return self.final_judgement
|