fabricatio 0.2.9.dev4__tar.gz → 0.2.10.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.9.dev4 → fabricatio-0.2.10.dev1}/PKG-INFO +1 -4
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/README.md +0 -2
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/extract_and_inject/.gitignore +2 -1
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/extract_and_inject/ask.py +16 -17
- fabricatio-0.2.10.dev1/examples/extract_and_inject/chunk_article.py +41 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/search_bibtex/search.py +1 -1
- fabricatio-0.2.10.dev1/examples/write_article/write_article.py +241 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/pyproject.toml +1 -2
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/actions/article.py +11 -107
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/actions/article_rag.py +33 -2
- fabricatio-0.2.10.dev1/python/fabricatio/actions/rag.py +96 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/capabilities/check.py +2 -1
- fabricatio-0.2.10.dev1/python/fabricatio/capabilities/rag.py +232 -0
- fabricatio-0.2.10.dev1/python/fabricatio/constants.py +20 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/decorators.py +23 -0
- fabricatio-0.2.10.dev1/python/fabricatio/models/adv_kwargs_types.py +60 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/models/events.py +6 -6
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/models/extra/advanced_judge.py +2 -2
- fabricatio-0.2.10.dev1/python/fabricatio/models/extra/aricle_rag.py +120 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/models/extra/article_base.py +2 -186
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/models/extra/article_essence.py +8 -7
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/models/extra/article_main.py +12 -107
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/models/extra/problem.py +12 -17
- fabricatio-0.2.10.dev1/python/fabricatio/models/extra/rag.py +98 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/models/extra/rule.py +1 -2
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/models/generic.py +19 -11
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/models/kwargs_types.py +6 -36
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/models/task.py +3 -3
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/models/usages.py +73 -5
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/rust.pyi +35 -6
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/utils.py +14 -1
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/src/bib_tools.rs +44 -27
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/src/hash.rs +1 -1
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/src/hbs_helpers.rs +1 -1
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/src/language.rs +1 -2
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/src/templates.rs +1 -0
- fabricatio-0.2.10.dev1/src/word_split.rs +86 -0
- fabricatio-0.2.10.dev1/templates/built-in/check_string.hbs +22 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/extract_criteria_from_reasons.hbs +3 -3
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/extract_reasons_from_examples.hbs +5 -3
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/refined_query.hbs +7 -6
- fabricatio-0.2.10.dev1/templates.tar.gz +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/tests/test_models/test_action.py +1 -1
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/tests/test_models/test_problem.py +7 -7
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/tests/test_models/test_task.py +1 -1
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/uv.lock +48 -73
- fabricatio-0.2.9.dev4/examples/write_article/write_article.py +0 -64
- fabricatio-0.2.9.dev4/python/fabricatio/actions/rag.py +0 -74
- fabricatio-0.2.9.dev4/python/fabricatio/capabilities/rag.py +0 -422
- fabricatio-0.2.9.dev4/python/fabricatio/models/adv_kwargs_types.py +0 -25
- fabricatio-0.2.9.dev4/python/fabricatio/models/utils.py +0 -148
- fabricatio-0.2.9.dev4/src/word_split.rs +0 -27
- fabricatio-0.2.9.dev4/templates/built-in/check_string.hbs +0 -19
- fabricatio-0.2.9.dev4/templates.tar.gz +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/.github/workflows/build-package.yaml +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/.github/workflows/ruff.yaml +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/.github/workflows/tests.yaml +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/.gitignore +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/.python-version +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/Cargo.lock +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/Cargo.toml +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/LICENSE +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/Makefile +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/correct/correct.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/correct/correct_loop.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/extract_and_inject/article_rag.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/extract_and_inject/extract_and_inject.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/extract_article/extract.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/llm_usages/llm_usage.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/make_a_rating/rating.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/make_diary/commits.json +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/make_diary/diary.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/minor/hello_fabricatio.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/minor/write_a_poem.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/propose_task/propose.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/reviewer/censor.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/reviewer/review.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/rules/.gitignore +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/rules/draft_ruleset.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/search_bibtex/.gitignore +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/simple_chat/chat.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/simple_rag/simple_rag.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/task_handle/handle_task.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/write_article/.gitignore +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/write_article/article_rag.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/write_outline/.gitignore +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/write_outline/write_outline.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/examples/write_outline/write_outline_corrected.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/__init__.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/actions/__init__.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/actions/output.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/actions/rules.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/capabilities/__init__.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/capabilities/advanced_judge.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/capabilities/censor.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/capabilities/correct.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/capabilities/propose.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/capabilities/rating.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/capabilities/review.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/capabilities/task.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/config.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/core.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/fs/__init__.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/fs/curd.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/fs/readers.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/journal.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/models/action.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/models/extra/__init__.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/models/extra/article_outline.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/models/extra/article_proposal.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/models/extra/patches.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/models/role.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/models/tool.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/parser.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/py.typed +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/rust_instances.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/toolboxes/__init__.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/toolboxes/arithmetic.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/toolboxes/fs.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/workflows/__init__.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/workflows/articles.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/python/fabricatio/workflows/rag.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/src/lib.rs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/as_prompt.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/claude-xml.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/clean-up-code.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/co_validation.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/create_json_obj.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/dependencies.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/document-the-code.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/draft_rating_criteria.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/draft_rating_manual.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/draft_rating_weights_klee.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/draft_tool_usage_code.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/fix-bugs.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/fix_troubled_obj.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/fix_troubled_string.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/generic_string.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/improve-performance.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/liststr.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/make_choice.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/make_judgment.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/pathstr.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/rate_fine_grind.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/refactor.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/retrieved_display.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/review_string.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/rule_requirement.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/ruleset_requirement_breakdown.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/task_briefing.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/web-ctf-solver.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/write-git-commit.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/write-github-pull-request.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/templates/built-in/write-github-readme.hbs +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/tests/test_config.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/tests/test_models/test_advanced.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/tests/test_models/test_generic.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/tests/test_models/test_role.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/tests/test_models/test_tool.py +0 -0
- {fabricatio-0.2.9.dev4 → fabricatio-0.2.10.dev1}/tests/test_models/test_usages.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: fabricatio
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.10.dev1
|
4
4
|
Classifier: License :: OSI Approved :: MIT License
|
5
5
|
Classifier: Programming Language :: Rust
|
6
6
|
Classifier: Programming Language :: Python :: 3.12
|
@@ -23,7 +23,6 @@ Requires-Dist: pymitter>=1.0.0
|
|
23
23
|
Requires-Dist: questionary>=2.1.0
|
24
24
|
Requires-Dist: regex>=2024.11.6
|
25
25
|
Requires-Dist: rich>=13.9.4
|
26
|
-
Requires-Dist: rtoml>=0.12.0
|
27
26
|
Requires-Dist: pymilvus>=2.5.4 ; extra == 'rag'
|
28
27
|
Requires-Dist: fabricatio[calc,plot,rag] ; extra == 'full'
|
29
28
|
Requires-Dist: sympy>=1.13.3 ; extra == 'calc'
|
@@ -45,8 +44,6 @@ Project-URL: Issues, https://github.com/Whth/fabricatio/issues
|
|
45
44
|
# Fabricatio
|
46
45
|
|
47
46
|

|
48
|
-

|
49
|
-

|
50
47
|
|
51
48
|
## Overview
|
52
49
|
|
@@ -2,8 +2,10 @@
|
|
2
2
|
|
3
3
|
import asyncio
|
4
4
|
|
5
|
-
from fabricatio import
|
5
|
+
from fabricatio import Action, Role, Task, WorkFlow, logger
|
6
|
+
from fabricatio.capabilities.rag import RAG
|
6
7
|
from fabricatio.models.events import Event
|
8
|
+
from fabricatio.models.extra.aricle_rag import ArticleChunk
|
7
9
|
from fabricatio.utils import ok
|
8
10
|
from questionary import text
|
9
11
|
|
@@ -23,14 +25,14 @@ class Talk(Action, RAG):
|
|
23
25
|
user_say = await text("User: ").ask_async()
|
24
26
|
if user_say is None:
|
25
27
|
break
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
ref_q = ok(await self.arefined_query(user_say))
|
29
|
+
logger.info(f'refined query: \n{ref_q}')
|
30
|
+
ret = await self.aretrieve(ref_q, document_model=ArticleChunk)
|
31
|
+
|
32
|
+
sys_msg = "\n".join(r.as_prompt() for r in ret)
|
33
|
+
logger.info(f"System message: \n{sys_msg}")
|
34
|
+
gpt_say = await self.aask(user_say, sys_msg)
|
35
|
+
|
34
36
|
print(f"GPT: {gpt_say}") # noqa: T201
|
35
37
|
counter += 1
|
36
38
|
except KeyboardInterrupt:
|
@@ -40,18 +42,15 @@ class Talk(Action, RAG):
|
|
40
42
|
|
41
43
|
async def main() -> None:
|
42
44
|
"""Main function."""
|
43
|
-
|
45
|
+
Role(
|
44
46
|
name="talker",
|
45
47
|
description="talker role but with rag",
|
46
|
-
registry={
|
48
|
+
registry={
|
49
|
+
Event.quick_instantiate("talk"): WorkFlow(name="talk", steps=(Talk(target_collection="article_chunks"),))
|
50
|
+
},
|
47
51
|
)
|
48
52
|
|
49
|
-
task =
|
50
|
-
await role.propose_task(
|
51
|
-
"you have to act as a helpful assistant, answer to all user questions properly and patiently"
|
52
|
-
),
|
53
|
-
"Failed to propose task",
|
54
|
-
)
|
53
|
+
task = Task(name="answer user's questions")
|
55
54
|
_ = await task.delegate("talk")
|
56
55
|
|
57
56
|
|
@@ -0,0 +1,41 @@
|
|
1
|
+
"""Example of proposing a task to a role."""
|
2
|
+
|
3
|
+
import asyncio
|
4
|
+
|
5
|
+
from fabricatio import BibManager, Event, Role, Task, WorkFlow, logger
|
6
|
+
from fabricatio.actions.article_rag import ChunkArticle
|
7
|
+
from fabricatio.actions.rag import InjectToDB
|
8
|
+
from fabricatio.fs import gather_files
|
9
|
+
from fabricatio.utils import ok
|
10
|
+
|
11
|
+
|
12
|
+
async def main() -> None:
|
13
|
+
"""Main function."""
|
14
|
+
Role(
|
15
|
+
name="Researcher",
|
16
|
+
description="chunk the article",
|
17
|
+
llm_rpm=50,
|
18
|
+
llm_tpm=100000,
|
19
|
+
registry={
|
20
|
+
Event.quick_instantiate(e := "Chunk"): WorkFlow(
|
21
|
+
name="Chunk",
|
22
|
+
steps=(
|
23
|
+
ChunkArticle(output_key="to_inject"),
|
24
|
+
InjectToDB(collection_name="article_chunks").to_task_output(),
|
25
|
+
),
|
26
|
+
).update_init_context(
|
27
|
+
article_path=gather_files("bare_md", "md"),
|
28
|
+
bib_manager=BibManager(path="ref.bib"),
|
29
|
+
max_chunk_size=500,
|
30
|
+
max_overlapping_rate=0.3,
|
31
|
+
),
|
32
|
+
},
|
33
|
+
)
|
34
|
+
|
35
|
+
task: Task[str] = Task(name="Chunk Article")
|
36
|
+
res = ok(await task.delegate(e))
|
37
|
+
logger.success(f"Injected to {res}")
|
38
|
+
|
39
|
+
|
40
|
+
if __name__ == "__main__":
|
41
|
+
asyncio.run(main())
|
@@ -3,7 +3,7 @@ from fabricatio import BibManager, logger
|
|
3
3
|
|
4
4
|
b = BibManager("Exported Items.bib")
|
5
5
|
logger.success(
|
6
|
-
b.
|
6
|
+
b.get_cite_key_by_title("A Negative Selection Immune System Inspired Methodology for Fault Diagnosis of Wind Turbines"))
|
7
7
|
logger.success(
|
8
8
|
b.get_cite_key_fuzzy(
|
9
9
|
"System Inspired Methodology for Fault"
|
@@ -0,0 +1,241 @@
|
|
1
|
+
"""Example of using the library."""
|
2
|
+
|
3
|
+
import asyncio
|
4
|
+
from pathlib import Path
|
5
|
+
from typing import List
|
6
|
+
|
7
|
+
from fabricatio import Event, Role, WorkFlow, logger
|
8
|
+
from fabricatio.actions.article import (
|
9
|
+
FixIntrospectedErrors,
|
10
|
+
GenerateArticle,
|
11
|
+
GenerateArticleProposal,
|
12
|
+
GenerateInitialOutline,
|
13
|
+
)
|
14
|
+
from fabricatio.actions.article_rag import TweakArticleRAG
|
15
|
+
from fabricatio.actions.output import DumpFinalizedOutput, GatherAsList, PersistentAll, RetrieveFromLatest
|
16
|
+
from fabricatio.actions.rules import DraftRuleSet, GatherRuleset
|
17
|
+
from fabricatio.models.action import Action
|
18
|
+
from fabricatio.models.extra.article_main import Article
|
19
|
+
from fabricatio.models.extra.article_outline import ArticleOutline
|
20
|
+
from fabricatio.models.extra.article_proposal import ArticleProposal
|
21
|
+
from fabricatio.models.extra.rule import RuleSet
|
22
|
+
from fabricatio.models.task import Task
|
23
|
+
from fabricatio.utils import ok
|
24
|
+
|
25
|
+
|
26
|
+
class Connect(Action):
|
27
|
+
"""Connect the article with the article_outline and article_proposal."""
|
28
|
+
|
29
|
+
output_key: str = "article"
|
30
|
+
"""Connect the article with the article_outline and article_proposal."""
|
31
|
+
|
32
|
+
async def _execute(
|
33
|
+
self,
|
34
|
+
article_briefing: str,
|
35
|
+
article_proposal: ArticleProposal,
|
36
|
+
article_outline: ArticleOutline,
|
37
|
+
article: Article,
|
38
|
+
**cxt,
|
39
|
+
) -> Article:
|
40
|
+
"""Connect the article with the article_outline and article_proposal."""
|
41
|
+
return article.update_ref(article_outline.update_ref(article_proposal.update_ref(article_briefing)))
|
42
|
+
|
43
|
+
|
44
|
+
async def main(article: bool, rule: bool = False, fintune: bool = False) -> None:
|
45
|
+
"""Main function."""
|
46
|
+
Role(
|
47
|
+
name="Undergraduate Researcher",
|
48
|
+
description="Write an outline for an article in typst format.",
|
49
|
+
llm_model="openai/deepseek-v3-250324",
|
50
|
+
llm_temperature=1.3,
|
51
|
+
llm_top_p=1.0,
|
52
|
+
llm_max_tokens=8191,
|
53
|
+
llm_rpm=1000,
|
54
|
+
llm_tpm=5000000,
|
55
|
+
registry={
|
56
|
+
Event.quick_instantiate(ns := "article"): WorkFlow(
|
57
|
+
name="Generate Article Outline",
|
58
|
+
description="Generate an outline for an article. dump the outline to the given path. in typst format.",
|
59
|
+
steps=(
|
60
|
+
RetrieveFromLatest(
|
61
|
+
retrieve_cls=RuleSet,
|
62
|
+
load_path="persistent_ruleset/outline_ruleset",
|
63
|
+
output_key="outline_ruleset",
|
64
|
+
),
|
65
|
+
RetrieveFromLatest(
|
66
|
+
retrieve_cls=RuleSet,
|
67
|
+
load_path="persistent_ruleset/dep_ref_ruleset",
|
68
|
+
output_key="dep_ref_ruleset",
|
69
|
+
),
|
70
|
+
RetrieveFromLatest(
|
71
|
+
retrieve_cls=RuleSet,
|
72
|
+
load_path="persistent_ruleset/rev_dep_ref_ruleset",
|
73
|
+
output_key="rev_dep_ref_ruleset",
|
74
|
+
),
|
75
|
+
RetrieveFromLatest(
|
76
|
+
retrieve_cls=RuleSet, load_path="persistent_ruleset/cite_ruleset", output_key="cite_ruleset"
|
77
|
+
),
|
78
|
+
RetrieveFromLatest(
|
79
|
+
retrieve_cls=RuleSet, load_path="persistent_ruleset/para_ruleset", output_key="para_ruleset"
|
80
|
+
),
|
81
|
+
RetrieveFromLatest(
|
82
|
+
retrieve_cls=RuleSet, load_path="persistent_ruleset/ref_ruleset", output_key="ref_ruleset"
|
83
|
+
),
|
84
|
+
RetrieveFromLatest(
|
85
|
+
retrieve_cls=RuleSet, load_path="persistent_ruleset/lang_ruleset", output_key="lang_ruleset"
|
86
|
+
),
|
87
|
+
GenerateArticleProposal(llm_temperature=1.3),
|
88
|
+
GenerateInitialOutline(
|
89
|
+
output_key="article_outline",
|
90
|
+
),
|
91
|
+
GatherRuleset(output_key="intro_fix_ruleset", to_gather=["para_ruleset"]),
|
92
|
+
FixIntrospectedErrors(
|
93
|
+
output_key="article_outline",
|
94
|
+
),
|
95
|
+
PersistentAll,
|
96
|
+
GatherRuleset(output_key="ref_fix_ruleset", to_gather=["ref_ruleset"]),
|
97
|
+
GatherRuleset(output_key="ref_twk_ruleset", to_gather=["dep_ref_ruleset", "ref_ruleset"]),
|
98
|
+
GatherRuleset(output_key="article_gen_ruleset", to_gather=["para_ruleset"]),
|
99
|
+
GenerateArticle(
|
100
|
+
output_key="article",
|
101
|
+
),
|
102
|
+
PersistentAll,
|
103
|
+
GatherRuleset(
|
104
|
+
output_key="twk_rag_ruleset", to_gather=["para_ruleset", "cite_ruleset", "lang_ruleset"]
|
105
|
+
),
|
106
|
+
TweakArticleRAG(output_key="to_dump"),
|
107
|
+
DumpFinalizedOutput(output_key="task_output"),
|
108
|
+
PersistentAll,
|
109
|
+
),
|
110
|
+
).update_init_context(
|
111
|
+
article_briefing=Path("./article_briefing.txt").read_text(),
|
112
|
+
dump_path="out.typ",
|
113
|
+
persist_dir="persistent",
|
114
|
+
collection_name="article_essence_0324",
|
115
|
+
),
|
116
|
+
Event.quick_instantiate(finetune := "article_finetune"): WorkFlow(
|
117
|
+
name="Generate Article Outline",
|
118
|
+
description="Generate an outline for an article. dump the outline to the given path. in typst format.",
|
119
|
+
steps=(
|
120
|
+
RetrieveFromLatest(
|
121
|
+
retrieve_cls=RuleSet,
|
122
|
+
load_path="persistent_ruleset/outline_ruleset",
|
123
|
+
output_key="outline_ruleset",
|
124
|
+
),
|
125
|
+
RetrieveFromLatest(
|
126
|
+
retrieve_cls=RuleSet,
|
127
|
+
load_path="persistent_ruleset/dep_ref_ruleset",
|
128
|
+
output_key="dep_ref_ruleset",
|
129
|
+
),
|
130
|
+
RetrieveFromLatest(
|
131
|
+
retrieve_cls=RuleSet,
|
132
|
+
load_path="persistent_ruleset/rev_dep_ref_ruleset",
|
133
|
+
output_key="rev_dep_ref_ruleset",
|
134
|
+
),
|
135
|
+
RetrieveFromLatest(
|
136
|
+
retrieve_cls=RuleSet, load_path="persistent_ruleset/cite_ruleset", output_key="cite_ruleset"
|
137
|
+
),
|
138
|
+
RetrieveFromLatest(
|
139
|
+
retrieve_cls=RuleSet, load_path="persistent_ruleset/para_ruleset", output_key="para_ruleset"
|
140
|
+
),
|
141
|
+
RetrieveFromLatest(
|
142
|
+
retrieve_cls=RuleSet, load_path="persistent_ruleset/ref_ruleset", output_key="ref_ruleset"
|
143
|
+
),
|
144
|
+
RetrieveFromLatest(
|
145
|
+
retrieve_cls=ArticleProposal,
|
146
|
+
load_path="persistent/article_proposal",
|
147
|
+
output_key="article_proposal",
|
148
|
+
),
|
149
|
+
RetrieveFromLatest(
|
150
|
+
retrieve_cls=ArticleOutline,
|
151
|
+
load_path="persistent/article_outline",
|
152
|
+
output_key="article_outline",
|
153
|
+
),
|
154
|
+
RetrieveFromLatest(retrieve_cls=Article, load_path="persistent/article", output_key="article"),
|
155
|
+
Connect,
|
156
|
+
GatherRuleset(output_key="intro_fix_ruleset", to_gather=["para_ruleset"]),
|
157
|
+
GatherRuleset(output_key="ref_fix_ruleset", to_gather=["ref_ruleset"]),
|
158
|
+
GatherRuleset(output_key="article_gen_ruleset", to_gather=["para_ruleset"]),
|
159
|
+
GatherRuleset(output_key="twk_rag_ruleset", to_gather=["para_ruleset", "cite_ruleset"]),
|
160
|
+
TweakArticleRAG(
|
161
|
+
output_key="to_dump",
|
162
|
+
),
|
163
|
+
DumpFinalizedOutput(output_key="task_output"),
|
164
|
+
PersistentAll,
|
165
|
+
),
|
166
|
+
).update_init_context(
|
167
|
+
article_briefing=Path("./article_briefing.txt").read_text(),
|
168
|
+
dump_path="out_fix.typ",
|
169
|
+
persist_dir="persistent_fix",
|
170
|
+
collection_name="article_essence_0324",
|
171
|
+
),
|
172
|
+
Event.quick_instantiate(rule_ns := "rule"): WorkFlow(
|
173
|
+
name="Generate Draft Rule Set",
|
174
|
+
description="Generate a draft rule set for the article.",
|
175
|
+
llm_model="openai/deepseek-v3-250324",
|
176
|
+
llm_stream=False,
|
177
|
+
steps=(
|
178
|
+
# 精简后的para_ruleset规则
|
179
|
+
DraftRuleSet(
|
180
|
+
ruleset_requirement="如果`paragraphs`字段为空列表,那么你就需要按照`expected_word_count`来为章节补充内容",
|
181
|
+
output_key="para_ruleset",
|
182
|
+
rule_count=1,
|
183
|
+
),
|
184
|
+
# 精简后的cite_ruleset规则
|
185
|
+
DraftRuleSet(
|
186
|
+
ruleset_requirement="1. 参考文献引用格式:(作者等, 年份)#cite(<bibtex_key>)\n"
|
187
|
+
"2. #cite()必须用尖括号包裹单个BibTeX键,多引用需重复使用",
|
188
|
+
output_key="cite_ruleset",
|
189
|
+
rule_count=1,
|
190
|
+
),
|
191
|
+
# 新增中文检测规则集
|
192
|
+
DraftRuleSet(
|
193
|
+
ruleset_requirement="1. 所有标题和正文内容必须使用中文,如果不为中文你需要翻译过来\n"
|
194
|
+
"2. 术语和专业词汇需使用中文表述,英文缩写第一次出现的时候需要在其后面‘()’来辅助说明",
|
195
|
+
output_key="lang_ruleset",
|
196
|
+
rule_count=1,
|
197
|
+
),
|
198
|
+
# 其他规则集保持原有结构但简化内容
|
199
|
+
DraftRuleSet(
|
200
|
+
ruleset_requirement="章节的`depend_on`字段的`ArticleRef`只能引用当前章节之前的元素。\n",
|
201
|
+
output_key="dep_ref_ruleset",
|
202
|
+
rule_count=1,
|
203
|
+
),
|
204
|
+
DraftRuleSet(
|
205
|
+
ruleset_requirement="章节的`support_to`字段的`ArticleRef`只能引用当前章节之后的元素。\n",
|
206
|
+
output_key="rev_dep_ref_ruleset",
|
207
|
+
rule_count=1,
|
208
|
+
),
|
209
|
+
DraftRuleSet(
|
210
|
+
ruleset_requirement="ArticleRef必须指向已定义元素",
|
211
|
+
output_key="ref_ruleset",
|
212
|
+
rule_count=1,
|
213
|
+
),
|
214
|
+
DraftRuleSet(
|
215
|
+
ruleset_requirement="标题使用学术术语",
|
216
|
+
output_key="outline_ruleset",
|
217
|
+
rule_count=1,
|
218
|
+
),
|
219
|
+
GatherAsList(gather_suffix="ruleset").to_task_output(),
|
220
|
+
PersistentAll(persist_dir="persistent_ruleset"),
|
221
|
+
),
|
222
|
+
),
|
223
|
+
},
|
224
|
+
)
|
225
|
+
|
226
|
+
if rule:
|
227
|
+
draft_rule_task: Task[List[RuleSet]] = Task(name="draft a rule set")
|
228
|
+
rule_set = ok(await draft_rule_task.delegate(rule_ns), "Failed to generate ruleset")
|
229
|
+
logger.success(f"Ruleset:\n{len(rule_set)}")
|
230
|
+
if article:
|
231
|
+
proposed_task = Task(name="write an article")
|
232
|
+
path = ok(await proposed_task.delegate(ns), "Failed to generate ruleset")
|
233
|
+
logger.success(f"The outline is saved in:\n{path}")
|
234
|
+
if fintune:
|
235
|
+
proposed_task = Task(name="finetune an article")
|
236
|
+
path = ok(await proposed_task.delegate(finetune), "Failed to generate ruleset")
|
237
|
+
logger.success(f"The outline is saved in:\n{path}")
|
238
|
+
|
239
|
+
|
240
|
+
if __name__ == "__main__":
|
241
|
+
asyncio.run(main(True, False, False))
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[project]
|
2
2
|
name = "fabricatio"
|
3
|
-
version = "0.2.
|
3
|
+
version = "0.2.10-dev1"
|
4
4
|
description = "A LLM multi-agent framework."
|
5
5
|
readme = "README.md"
|
6
6
|
license = { file = "LICENSE" }
|
@@ -42,7 +42,6 @@ dependencies = [
|
|
42
42
|
"questionary>=2.1.0",
|
43
43
|
"regex>=2024.11.6",
|
44
44
|
"rich>=13.9.4",
|
45
|
-
"rtoml>=0.12.0",
|
46
45
|
]
|
47
46
|
|
48
47
|
[project.urls]
|
@@ -4,6 +4,7 @@ from asyncio import gather
|
|
4
4
|
from pathlib import Path
|
5
5
|
from typing import Callable, List, Optional
|
6
6
|
|
7
|
+
from fabricatio.rust import BibManager, detect_language
|
7
8
|
from more_itertools import filter_map
|
8
9
|
|
9
10
|
from fabricatio.capabilities.censor import Censor
|
@@ -11,14 +12,12 @@ from fabricatio.capabilities.propose import Propose
|
|
11
12
|
from fabricatio.fs import safe_text_read
|
12
13
|
from fabricatio.journal import logger
|
13
14
|
from fabricatio.models.action import Action
|
14
|
-
from fabricatio.models.extra.article_base import SubSectionBase
|
15
15
|
from fabricatio.models.extra.article_essence import ArticleEssence
|
16
16
|
from fabricatio.models.extra.article_main import Article
|
17
17
|
from fabricatio.models.extra.article_outline import ArticleOutline
|
18
18
|
from fabricatio.models.extra.article_proposal import ArticleProposal
|
19
19
|
from fabricatio.models.extra.rule import RuleSet
|
20
20
|
from fabricatio.models.task import Task
|
21
|
-
from fabricatio.rust import BibManager, detect_language
|
22
21
|
from fabricatio.utils import ok
|
23
22
|
|
24
23
|
|
@@ -79,7 +78,7 @@ class FixArticleEssence(Action):
|
|
79
78
|
out = []
|
80
79
|
count = 0
|
81
80
|
for a in article_essence:
|
82
|
-
if key := (bib_mgr.
|
81
|
+
if key := (bib_mgr.get_cite_key_by_title(a.title) or bib_mgr.get_cite_key_fuzzy(a.title)):
|
83
82
|
a.title = bib_mgr.get_title_by_key(key) or a.title
|
84
83
|
a.authors = bib_mgr.get_author_by_key(key) or a.authors
|
85
84
|
a.publication_year = bib_mgr.get_year_by_key(key) or a.publication_year
|
@@ -142,11 +141,17 @@ class GenerateInitialOutline(Action, Propose):
|
|
142
141
|
article_proposal: ArticleProposal,
|
143
142
|
**_,
|
144
143
|
) -> Optional[ArticleOutline]:
|
144
|
+
raw_outline = await self.aask(
|
145
|
+
f"{(article_proposal.as_prompt())}\n\nNote that you should use `{article_proposal.language}` to write the `ArticleOutline`\n"
|
146
|
+
f"Design each chapter of a proper and academic and ready for release manner.\n"
|
147
|
+
f"You Must make sure every chapter have sections, and every section have subsections.\n"
|
148
|
+
f"Make the chapter and sections and subsections bing divided into a specific enough article component.",
|
149
|
+
)
|
150
|
+
|
145
151
|
return ok(
|
146
152
|
await self.propose(
|
147
153
|
ArticleOutline,
|
148
|
-
f"{
|
149
|
-
f"You Must make sure every chapter have sections, and every section have subsections.",
|
154
|
+
f"{raw_outline}\n\n\n\noutline provided above is the outline i need to extract to a JSON,",
|
150
155
|
),
|
151
156
|
"Could not generate the initial outline.",
|
152
157
|
).update_ref(article_proposal)
|
@@ -178,7 +183,7 @@ class FixIntrospectedErrors(Action, Censor):
|
|
178
183
|
await self.censor_obj(
|
179
184
|
article_outline,
|
180
185
|
ruleset=ok(intro_fix_ruleset or self.ruleset, "No ruleset provided"),
|
181
|
-
reference=f"{article_outline.
|
186
|
+
reference=f"{article_outline.display()}\n # Fatal Error of the Original Article Outline\n{pack}",
|
182
187
|
),
|
183
188
|
"Could not correct the component.",
|
184
189
|
).update_ref(origin)
|
@@ -191,107 +196,6 @@ class FixIntrospectedErrors(Action, Censor):
|
|
191
196
|
return article_outline
|
192
197
|
|
193
198
|
|
194
|
-
class FixIllegalReferences(Action, Censor):
|
195
|
-
"""Fix illegal references in the article outline."""
|
196
|
-
|
197
|
-
output_key: str = "illegal_references_fixed_outline"
|
198
|
-
"""The key of the output data."""
|
199
|
-
|
200
|
-
ruleset: Optional[RuleSet] = None
|
201
|
-
"""Ruleset to use to fix the illegal references."""
|
202
|
-
max_error_count: Optional[int] = None
|
203
|
-
"""The maximum number of errors to fix."""
|
204
|
-
|
205
|
-
async def _execute(
|
206
|
-
self,
|
207
|
-
article_outline: ArticleOutline,
|
208
|
-
ref_fix_ruleset: Optional[RuleSet] = None,
|
209
|
-
**_,
|
210
|
-
) -> Optional[ArticleOutline]:
|
211
|
-
counter = 0
|
212
|
-
while pack := article_outline.find_illegal_ref(gather_identical=True):
|
213
|
-
logger.info(f"Found {counter}th illegal references")
|
214
|
-
ref_seq, err = ok(pack)
|
215
|
-
logger.warning(f"Found illegal referring error: {err}")
|
216
|
-
new = ok(
|
217
|
-
await self.censor_obj(
|
218
|
-
ref_seq[0],
|
219
|
-
ruleset=ok(ref_fix_ruleset or self.ruleset, "No ruleset provided"),
|
220
|
-
reference=f"{article_outline.as_prompt()}\n# Some Basic errors found that need to be fixed\n{err}",
|
221
|
-
),
|
222
|
-
"Could not correct the component",
|
223
|
-
)
|
224
|
-
for r in ref_seq:
|
225
|
-
r.update_from(new)
|
226
|
-
if self.max_error_count and counter > self.max_error_count:
|
227
|
-
logger.warning("Max error count reached, stopping.")
|
228
|
-
break
|
229
|
-
counter += 1
|
230
|
-
|
231
|
-
return article_outline
|
232
|
-
|
233
|
-
|
234
|
-
class TweakOutlineForwardRef(Action, Censor):
|
235
|
-
"""Tweak the forward references in the article outline.
|
236
|
-
|
237
|
-
Ensures that the conclusions of the current chapter effectively support the analysis of subsequent chapters.
|
238
|
-
"""
|
239
|
-
|
240
|
-
output_key: str = "article_outline_fw_ref_checked"
|
241
|
-
ruleset: Optional[RuleSet] = None
|
242
|
-
"""Ruleset to use to fix the illegal references."""
|
243
|
-
|
244
|
-
async def _execute(
|
245
|
-
self, article_outline: ArticleOutline, ref_twk_ruleset: Optional[RuleSet] = None, **cxt
|
246
|
-
) -> ArticleOutline:
|
247
|
-
return await self._inner(
|
248
|
-
article_outline,
|
249
|
-
ruleset=ok(ref_twk_ruleset or self.ruleset, "No ruleset provided"),
|
250
|
-
field_name="support_to",
|
251
|
-
)
|
252
|
-
|
253
|
-
async def _inner(self, article_outline: ArticleOutline, ruleset: RuleSet, field_name: str) -> ArticleOutline:
|
254
|
-
await gather(
|
255
|
-
*[self._loop(a[-1], article_outline, field_name, ruleset) for a in article_outline.iter_subsections()],
|
256
|
-
)
|
257
|
-
|
258
|
-
return article_outline
|
259
|
-
|
260
|
-
async def _loop(
|
261
|
-
self, a: SubSectionBase, article_outline: ArticleOutline, field_name: str, ruleset: RuleSet
|
262
|
-
) -> None:
|
263
|
-
if judge := await self.evidently_judge(
|
264
|
-
f"{article_outline.as_prompt()}\n\n{a.display()}\n"
|
265
|
-
f"Does the `{a.__class__.__name__}`'s `{field_name}` field need to be extended or tweaked?"
|
266
|
-
):
|
267
|
-
await self.censor_obj_inplace(
|
268
|
-
a,
|
269
|
-
ruleset=ruleset,
|
270
|
-
reference=f"{article_outline.as_prompt()}\n"
|
271
|
-
f"The Article component titled `{a.title}` whose `{field_name}` field needs to be extended or tweaked.\n"
|
272
|
-
f"# Judgement\n{judge.display()}",
|
273
|
-
)
|
274
|
-
|
275
|
-
|
276
|
-
class TweakOutlineBackwardRef(TweakOutlineForwardRef):
|
277
|
-
"""Tweak the backward references in the article outline.
|
278
|
-
|
279
|
-
Ensures that the prerequisites of the current chapter are correctly referenced in the `depend_on` field.
|
280
|
-
"""
|
281
|
-
|
282
|
-
output_key: str = "article_outline_bw_ref_checked"
|
283
|
-
ruleset: Optional[RuleSet] = None
|
284
|
-
|
285
|
-
async def _execute(
|
286
|
-
self, article_outline: ArticleOutline, ref_twk_ruleset: Optional[RuleSet] = None, **cxt
|
287
|
-
) -> ArticleOutline:
|
288
|
-
return await self._inner(
|
289
|
-
article_outline,
|
290
|
-
ruleset=ok(ref_twk_ruleset or self.ruleset, "No ruleset provided"),
|
291
|
-
field_name="depend_on",
|
292
|
-
)
|
293
|
-
|
294
|
-
|
295
199
|
class GenerateArticle(Action, Censor):
|
296
200
|
"""Generate the article based on the outline."""
|
297
201
|
|
@@ -1,11 +1,15 @@
|
|
1
1
|
"""A module for writing articles using RAG (Retrieval-Augmented Generation) capabilities."""
|
2
2
|
|
3
3
|
from asyncio import gather
|
4
|
-
from
|
4
|
+
from pathlib import Path
|
5
|
+
from typing import List, Optional
|
5
6
|
|
7
|
+
from fabricatio import BibManager
|
6
8
|
from fabricatio.capabilities.censor import Censor
|
7
9
|
from fabricatio.capabilities.rag import RAG
|
8
10
|
from fabricatio.models.action import Action
|
11
|
+
from fabricatio.models.extra.aricle_rag import ArticleChunk
|
12
|
+
from fabricatio.models.extra.article_essence import ArticleEssence
|
9
13
|
from fabricatio.models.extra.article_main import Article, ArticleSubsection
|
10
14
|
from fabricatio.models.extra.rule import RuleSet
|
11
15
|
from fabricatio.utils import ok
|
@@ -97,9 +101,36 @@ class TweakArticleRAG(Action, RAG, Censor):
|
|
97
101
|
await self.censor_obj_inplace(
|
98
102
|
subsec,
|
99
103
|
ruleset=ruleset,
|
100
|
-
reference=f"{await self.
|
104
|
+
reference=f"{'\n\n'.join(d.display() for d in await self.aretrieve(refind_q, document_model=ArticleEssence, final_limit=self.ref_limit))}\n\n"
|
101
105
|
f"You can use Reference above to rewrite the `{subsec.__class__.__name__}`.\n"
|
102
106
|
f"You should Always use `{subsec.language}` as written language, "
|
103
107
|
f"which is the original language of the `{subsec.title}`. "
|
104
108
|
f"since rewrite a `{subsec.__class__.__name__}` in a different language is usually a bad choice",
|
105
109
|
)
|
110
|
+
|
111
|
+
|
112
|
+
class ChunkArticle(Action):
|
113
|
+
"""Chunk an article into smaller chunks."""
|
114
|
+
|
115
|
+
output_key:str = "article_chunks"
|
116
|
+
"""The key used to store the output of the action."""
|
117
|
+
max_chunk_size: Optional[int] = None
|
118
|
+
"""The maximum size of each chunk."""
|
119
|
+
max_overlapping_rate: Optional[float] = None
|
120
|
+
"""The maximum overlapping rate between chunks."""
|
121
|
+
|
122
|
+
async def _execute(
|
123
|
+
self,
|
124
|
+
article_path: str | Path,
|
125
|
+
bib_manager: BibManager,
|
126
|
+
max_chunk_size: Optional[int] = None,
|
127
|
+
max_overlapping_rate: Optional[float] = None,
|
128
|
+
**_,
|
129
|
+
) -> List[ArticleChunk]:
|
130
|
+
return ArticleChunk.from_file(
|
131
|
+
article_path,
|
132
|
+
bib_manager,
|
133
|
+
max_chunk_size=ok(max_chunk_size or self.max_chunk_size, "No max_chunk_size provided!"),
|
134
|
+
max_overlapping_rate=ok(max_overlapping_rate or self.max_overlapping_rate, "No max_overlapping_rate provided!"),
|
135
|
+
)
|
136
|
+
|