fabricatio 0.2.11.dev3__tar.gz → 0.2.12.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.11.dev3 → fabricatio-0.2.12.dev1}/.gitignore +2 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/PKG-INFO +1 -1
- fabricatio-0.2.12.dev1/examples/write_article/.gitignore +4 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/write_article/write_article.py +86 -30
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/pyproject.toml +3 -2
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/actions/article_rag.py +157 -51
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/actions/output.py +35 -3
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/config.py +3 -3
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/fs/curd.py +1 -1
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/models/action.py +6 -8
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/models/extra/aricle_rag.py +42 -19
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/models/extra/article_base.py +55 -26
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/models/extra/article_main.py +56 -4
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/models/generic.py +10 -6
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/models/kwargs_types.py +1 -1
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/models/role.py +5 -4
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/utils.py +1 -1
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/src/typst_tools.rs +8 -3
- fabricatio-0.2.12.dev1/templates.tar.gz +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/tests/test_models/test_problem.py +17 -37
- fabricatio-0.2.12.dev1/uv.lock +1706 -0
- fabricatio-0.2.11.dev3/examples/write_article/.gitignore +0 -3
- fabricatio-0.2.11.dev3/templates.tar.gz +0 -0
- fabricatio-0.2.11.dev3/uv.lock +0 -1706
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/.github/workflows/build-package.yaml +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/.github/workflows/ruff.yaml +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/.github/workflows/tests.yaml +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/.python-version +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/Cargo.lock +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/Cargo.toml +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/LICENSE +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/Makefile +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/README.md +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/correct/correct.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/correct/correct_loop.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/extract_and_inject/.gitignore +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/extract_and_inject/article_rag.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/extract_and_inject/ask.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/extract_and_inject/chunk_article.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/extract_and_inject/extract_and_inject.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/extract_article/extract.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/llm_usages/llm_usage.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/make_a_rating/rating.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/make_diary/commits.json +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/make_diary/diary.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/minor/hello_fabricatio.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/minor/write_a_poem.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/propose_task/.gitignore +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/propose_task/propose.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/reviewer/censor.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/reviewer/review.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/rules/.gitignore +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/rules/draft_ruleset.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/search_bibtex/.gitignore +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/search_bibtex/search.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/simple_chat/chat.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/simple_rag/simple_rag.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/task_handle/handle_task.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/write_article/article_rag.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/write_article/post_process.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/write_outline/.gitignore +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/write_outline/write_outline.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/examples/write_outline/write_outline_corrected.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/__init__.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/actions/__init__.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/actions/article.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/actions/fs.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/actions/rag.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/actions/rules.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/capabilities/__init__.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/capabilities/advanced_judge.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/capabilities/censor.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/capabilities/check.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/capabilities/correct.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/capabilities/extract.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/capabilities/propose.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/capabilities/rag.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/capabilities/rating.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/capabilities/review.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/capabilities/task.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/constants.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/core.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/decorators.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/fs/__init__.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/fs/readers.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/journal.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/models/adv_kwargs_types.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/models/events.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/models/extra/__init__.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/models/extra/advanced_judge.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/models/extra/article_essence.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/models/extra/article_outline.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/models/extra/article_proposal.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/models/extra/patches.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/models/extra/problem.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/models/extra/rag.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/models/extra/rule.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/models/task.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/models/tool.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/models/usages.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/parser.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/py.typed +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/rust.pyi +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/rust_instances.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/toolboxes/__init__.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/toolboxes/arithmetic.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/toolboxes/fs.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/workflows/__init__.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/workflows/articles.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/python/fabricatio/workflows/rag.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/src/bib_tools.rs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/src/hash.rs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/src/hbs_helpers.rs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/src/language.rs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/src/lib.rs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/src/templates.rs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/src/word_split.rs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/as_prompt.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/check_string.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/claude-xml.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/clean-up-code.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/co_validation.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/create_json_obj.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/dependencies.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/document-the-code.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/draft_rating_criteria.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/draft_rating_manual.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/draft_rating_weights_klee.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/draft_tool_usage_code.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/extract.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/extract_criteria_from_reasons.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/extract_reasons_from_examples.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/fix-bugs.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/fix_troubled_obj.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/fix_troubled_string.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/generic_string.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/improve-performance.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/liststr.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/make_choice.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/make_judgment.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/pathstr.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/rate_fine_grind.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/refactor.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/refined_query.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/retrieved_display.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/review_string.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/rule_requirement.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/ruleset_requirement_breakdown.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/task_briefing.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/web-ctf-solver.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/write-git-commit.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/write-github-pull-request.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/templates/built-in/write-github-readme.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/tests/test_config.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/tests/test_models/test_action.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/tests/test_models/test_advanced.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/tests/test_models/test_generic.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/tests/test_models/test_role.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/tests/test_models/test_task.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/tests/test_models/test_tool.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev1}/tests/test_models/test_usages.py +0 -0
@@ -6,25 +6,27 @@ from pathlib import Path
|
|
6
6
|
import typer
|
7
7
|
from fabricatio import Event, Role, WorkFlow, logger
|
8
8
|
from fabricatio.actions.article import ExtractOutlineFromRaw, GenerateArticleProposal, GenerateInitialOutline
|
9
|
-
from fabricatio.actions.article_rag import WriteArticleContentRAG
|
10
|
-
from fabricatio.actions.output import
|
11
|
-
|
12
|
-
PersistentAll,
|
13
|
-
)
|
9
|
+
from fabricatio.actions.article_rag import ArticleConsultRAG, WriteArticleContentRAG
|
10
|
+
from fabricatio.actions.output import DumpFinalizedOutput, PersistentAll
|
11
|
+
from fabricatio.models.extra.article_outline import ArticleOutline
|
14
12
|
from fabricatio.models.task import Task
|
15
13
|
from fabricatio.utils import ok
|
16
14
|
from typer import Typer
|
17
15
|
|
16
|
+
# from pydantic import HttpUrl
|
17
|
+
|
18
18
|
Role(
|
19
19
|
name="Undergraduate Researcher",
|
20
20
|
description="Write an outline for an article in typst format.",
|
21
|
-
llm_model="openai/qwen-
|
22
|
-
llm_temperature=0.
|
23
|
-
|
24
|
-
llm_top_p=0.
|
21
|
+
llm_model="openai/qwen-plus",
|
22
|
+
llm_temperature=0.35,
|
23
|
+
# llm_api_endpoint=HttpUrl("https://dashscope.aliyuncs.com/compatible-mode/v1"),
|
24
|
+
llm_top_p=0.95,
|
25
25
|
llm_max_tokens=8191,
|
26
|
+
llm_stream=True,
|
26
27
|
llm_rpm=600,
|
27
|
-
llm_tpm=
|
28
|
+
llm_tpm=1000000,
|
29
|
+
llm_timeout=600,
|
28
30
|
registry={
|
29
31
|
Event.quick_instantiate(ns := "article"): WorkFlow(
|
30
32
|
name="Generate Article",
|
@@ -33,38 +35,46 @@ Role(
|
|
33
35
|
GenerateArticleProposal,
|
34
36
|
GenerateInitialOutline(output_key="article_outline"),
|
35
37
|
PersistentAll,
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
(
|
39
|
+
a := WriteArticleContentRAG(
|
40
|
+
output_key="to_dump",
|
41
|
+
ref_limit=18,
|
42
|
+
threshold=0.58,
|
43
|
+
result_per_query=2,
|
44
|
+
llm_model="openai/qwq-plus",
|
45
|
+
extractor_model="openai/qwen-max",
|
46
|
+
query_model="openai/qwen-turbo",
|
47
|
+
)
|
44
48
|
),
|
45
49
|
DumpFinalizedOutput(output_key="task_output"),
|
46
50
|
PersistentAll,
|
47
51
|
),
|
48
52
|
),
|
49
|
-
Event.quick_instantiate(ns2 := ""): WorkFlow(
|
53
|
+
Event.quick_instantiate(ns2 := "complete"): WorkFlow(
|
50
54
|
name="Generate Article",
|
51
55
|
description="Generate an article with given raw article outline. dump the outline to the given path. in typst format.",
|
52
56
|
steps=(
|
53
|
-
ExtractOutlineFromRaw,
|
57
|
+
ExtractOutlineFromRaw(output_key="article_outline"),
|
54
58
|
PersistentAll,
|
55
|
-
|
56
|
-
output_key="to_dump",
|
57
|
-
llm_top_p=0.9,
|
58
|
-
ref_limit=35,
|
59
|
-
llm_model="openai/qwq-plus",
|
60
|
-
target_collection="article_chunks",
|
61
|
-
extractor_model="openai/qwen-plus",
|
62
|
-
query_model="openai/qwen-max",
|
63
|
-
),
|
59
|
+
a,
|
64
60
|
DumpFinalizedOutput(output_key="task_output"),
|
65
61
|
PersistentAll,
|
66
62
|
),
|
67
63
|
),
|
64
|
+
Event.quick_instantiate(ns3 := "finish"): WorkFlow(
|
65
|
+
name="Finish Article",
|
66
|
+
description="Finish an article with given article outline. dump the outline to the given path. in typst format.",
|
67
|
+
steps=(
|
68
|
+
a,
|
69
|
+
DumpFinalizedOutput(output_key="task_output"),
|
70
|
+
PersistentAll,
|
71
|
+
),
|
72
|
+
),
|
73
|
+
Event.quick_instantiate(ns4 := "consult"): WorkFlow(
|
74
|
+
name="Consult Article",
|
75
|
+
description="Consult an article with given article outline. dump the outline to the given path. in typst format.",
|
76
|
+
steps=(ArticleConsultRAG().to_task_output(),),
|
77
|
+
),
|
68
78
|
},
|
69
79
|
)
|
70
80
|
|
@@ -72,6 +82,52 @@ Role(
|
|
72
82
|
app = Typer()
|
73
83
|
|
74
84
|
|
85
|
+
@app.command()
|
86
|
+
def consult(
|
87
|
+
collection_name: str = typer.Option("article_chunks", "-c", "--collection-name", help="Name of the collection."),
|
88
|
+
) -> None:
|
89
|
+
"""Consult an article based on a given article outline."""
|
90
|
+
_ = asyncio.run(
|
91
|
+
Task(name="Answer Question")
|
92
|
+
.update_init_context(
|
93
|
+
collection_name=collection_name,
|
94
|
+
)
|
95
|
+
.delegate(ns4)
|
96
|
+
)
|
97
|
+
|
98
|
+
logger.info("Finished")
|
99
|
+
|
100
|
+
|
101
|
+
@app.command()
|
102
|
+
def finish(
|
103
|
+
article_outline_path: Path = typer.Argument( # noqa: B008
|
104
|
+
help="Path to the article outline raw file."
|
105
|
+
),
|
106
|
+
dump_path: Path = typer.Option(Path("out.typ"), "-d", "--dump-path", help="Path to dump the final output."), # noqa: B008
|
107
|
+
persist_dir: Path = typer.Option( # noqa: B008
|
108
|
+
Path("persistent"), "-p", "--persist-dir", help="Directory to persist the output."
|
109
|
+
),
|
110
|
+
collection_name: str = typer.Option("article_chunks", "-c", "--collection-name", help="Name of the collection."),
|
111
|
+
supervisor: bool = typer.Option(False, "-s", "--supervisor", help="Whether to use the supervisor mode."),
|
112
|
+
) -> None:
|
113
|
+
"""Finish an article based on a given article outline."""
|
114
|
+
path = ok(
|
115
|
+
asyncio.run(
|
116
|
+
Task(name="write an article")
|
117
|
+
.update_init_context(
|
118
|
+
article_outline=ArticleOutline.from_persistent(article_outline_path),
|
119
|
+
dump_path=dump_path,
|
120
|
+
persist_dir=persist_dir,
|
121
|
+
collection_name=collection_name,
|
122
|
+
supervisor=supervisor,
|
123
|
+
)
|
124
|
+
.delegate(ns3)
|
125
|
+
),
|
126
|
+
"Failed to generate an article ",
|
127
|
+
)
|
128
|
+
logger.success(f"The outline is saved in:\n{path}")
|
129
|
+
|
130
|
+
|
75
131
|
@app.command()
|
76
132
|
def completion(
|
77
133
|
article_outline_raw_path: Path = typer.Option( # noqa: B008
|
@@ -95,7 +151,7 @@ def completion(
|
|
95
151
|
collection_name=collection_name,
|
96
152
|
supervisor=supervisor,
|
97
153
|
)
|
98
|
-
.delegate(
|
154
|
+
.delegate(ns2)
|
99
155
|
),
|
100
156
|
"Failed to generate an article ",
|
101
157
|
)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[project]
|
2
2
|
name = "fabricatio"
|
3
|
-
version = "0.2.
|
3
|
+
version = "0.2.12-dev1"
|
4
4
|
description = "A LLM multi-agent framework."
|
5
5
|
readme = "README.md"
|
6
6
|
license = { file = "LICENSE" }
|
@@ -137,7 +137,8 @@ ignore = [
|
|
137
137
|
"PYI063",
|
138
138
|
"PYI021",
|
139
139
|
"ASYNC109",
|
140
|
-
"RUF001"
|
140
|
+
"RUF001",
|
141
|
+
"PYI019"
|
141
142
|
]
|
142
143
|
[tool.ruff.lint.pydocstyle]
|
143
144
|
convention = "google"
|
@@ -4,6 +4,8 @@ from asyncio import gather
|
|
4
4
|
from pathlib import Path
|
5
5
|
from typing import List, Optional
|
6
6
|
|
7
|
+
from pydantic import PositiveInt
|
8
|
+
|
7
9
|
from fabricatio import BibManager
|
8
10
|
from fabricatio.capabilities.censor import Censor
|
9
11
|
from fabricatio.capabilities.extract import Extract
|
@@ -18,13 +20,35 @@ from fabricatio.models.extra.article_outline import ArticleOutline
|
|
18
20
|
from fabricatio.models.extra.rule import RuleSet
|
19
21
|
from fabricatio.utils import ask_retain, ok
|
20
22
|
|
23
|
+
TYPST_CITE_USAGE = (
|
24
|
+
"citation number is REQUIRED to cite any reference!,for example in Auther Pattern: 'Doe et al.[[1]], Jack et al.[[2]]' or in Sentence Suffix Sattern: 'Global requirement is incresing[[1]].'\n"
|
25
|
+
"Everything is build upon the typst language, which is similar to latex, \n"
|
26
|
+
"Legal citing syntax examples(seperated by |): [[1]]|[[1,2]]|[[1-3]]|[[12,13-15]]|[[1-3,5-7]]\n"
|
27
|
+
"Illegal citing syntax examples(seperated by |): [[1],[2],[3]]|[[1],[1-2]]\n"
|
28
|
+
"Those reference mark shall not be omitted during the extraction\n"
|
29
|
+
"It's recommended to cite multiple references that supports your conclusion at a time.\n"
|
30
|
+
"Wrapp inline expression using $ $,like '$>5m$' '$89%$' , and wrapp block equation using $$ $$. if you are using '$' as the money unit, you should add a '\\' before it to avoid being interpreted as a inline equation. For example 'The pants worths 5\\$.'\n"
|
31
|
+
"In addition to that, you can add a label outside the block equation which can be used as a cross reference identifier, the label is a string wrapped in `<` and `>` like `<energy-release-rate-equation>`.Note that the label string should be a summarizing title for the equation being labeled.\n"
|
32
|
+
"you can refer to that label by using the syntax with prefix of `@eqt:`, which indicate that this notation is citing a label from the equations. For example ' @eqt:energy-release-rate-equation ' DO remember that the notation shall have both suffixed and prefixed space char which enable the compiler to distinguish the notation from the plaintext."
|
33
|
+
"Below is a usage example:\n"
|
34
|
+
"```typst\n"
|
35
|
+
"See @eqt:mass-energy-equation , it's the foundation of physics.\n"
|
36
|
+
"$$\n"
|
37
|
+
"E = m c^2\n"
|
38
|
+
"$$ <mass-energy-equation>\n\n\n"
|
39
|
+
"In @eqt:mass-energy-equation , $m$ stands for mass, $c$ stands for speed of light, and $E$ stands for energy. \n"
|
40
|
+
"```"
|
41
|
+
)
|
42
|
+
|
21
43
|
|
22
44
|
class WriteArticleContentRAG(Action, RAG, Extract):
|
23
45
|
"""Write an article based on the provided outline."""
|
24
46
|
|
47
|
+
search_increment_multiplier: float = 1.6
|
48
|
+
"""The increment multiplier of the search increment."""
|
25
49
|
ref_limit: int = 35
|
26
50
|
"""The limit of references to be retrieved"""
|
27
|
-
threshold: float = 0.
|
51
|
+
threshold: float = 0.62
|
28
52
|
"""The threshold of relevance"""
|
29
53
|
extractor_model: str
|
30
54
|
"""The model to use for extracting the content from the retrieved references."""
|
@@ -32,43 +56,24 @@ class WriteArticleContentRAG(Action, RAG, Extract):
|
|
32
56
|
"""The model to use for querying the database"""
|
33
57
|
supervisor: bool = False
|
34
58
|
"""Whether to use supervisor mode"""
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
"Illegal citing syntax examples(seperated by |): [[1],[2],[3]]|[[1],[1-2]]\n"
|
40
|
-
"Those reference mark shall not be omitted during the extraction\n"
|
41
|
-
"It's recommended to cite multiple references that supports your conclusion at a time.\n"
|
42
|
-
"Wrapp inline expression using $ $, and wrapp block equation using $$ $$."
|
43
|
-
"In addition to that, you can add a label outside the block equation which can be used as a cross reference identifier, the label is a string wrapped in `<` and `>`,"
|
44
|
-
"you can refer to that label by using the syntax with prefix of `@eqt:`"
|
45
|
-
"Below is a usage example:\n"
|
46
|
-
"```typst\n"
|
47
|
-
"See @eqt:mass-energy-equation , it's the foundation of physics.\n"
|
48
|
-
"$$\n"
|
49
|
-
"E = m c^2"
|
50
|
-
"$$\n"
|
51
|
-
"<mass-energy-equation>\n\n"
|
52
|
-
"In @eqt:mass-energy-equation , $m$ stands for mass, $c$ stands for speed of light, and $E$ stands for energy. \n"
|
53
|
-
"```"
|
54
|
-
)
|
59
|
+
result_per_query: PositiveInt = 4
|
60
|
+
"""The number of results to be returned per query."""
|
61
|
+
req: str = TYPST_CITE_USAGE
|
62
|
+
"""The req of the write article content."""
|
55
63
|
|
56
64
|
async def _execute(
|
57
65
|
self,
|
58
66
|
article_outline: ArticleOutline,
|
59
|
-
collection_name: str =
|
67
|
+
collection_name: Optional[str] = None,
|
60
68
|
supervisor: Optional[bool] = None,
|
61
69
|
**cxt,
|
62
70
|
) -> Article:
|
63
71
|
article = Article.from_outline(article_outline).update_ref(article_outline)
|
64
|
-
|
72
|
+
self.target_collection = collection_name or self.safe_target_collection
|
65
73
|
if supervisor or (supervisor is None and self.supervisor):
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
for chap, sec, subsec in article.iter_subsections()
|
70
|
-
]
|
71
|
-
)
|
74
|
+
for chap, sec, subsec in article.iter_subsections():
|
75
|
+
await self._supervisor_inner(article, article_outline, chap, sec, subsec)
|
76
|
+
|
72
77
|
else:
|
73
78
|
await gather(
|
74
79
|
*[
|
@@ -92,22 +97,29 @@ class WriteArticleContentRAG(Action, RAG, Extract):
|
|
92
97
|
from questionary import confirm, text
|
93
98
|
from rich import print as r_print
|
94
99
|
|
95
|
-
|
96
|
-
|
97
|
-
cm = CitationManager(article_chunks=await ask_retain([r.chunk for r in ret], ret)).set_cite_number_all()
|
100
|
+
cm = CitationManager()
|
101
|
+
await self.search_database(article, article_outline, chap, sec, subsec, cm)
|
98
102
|
|
99
103
|
raw = await self.write_raw(article, article_outline, chap, sec, subsec, cm)
|
100
104
|
r_print(raw)
|
101
105
|
|
102
106
|
while not await confirm("Accept this version and continue?").ask_async():
|
103
|
-
if await
|
104
|
-
|
105
|
-
|
107
|
+
if inst := await text("Search for more refs for additional spec.").ask_async():
|
108
|
+
await self.search_database(
|
109
|
+
article,
|
110
|
+
article_outline,
|
111
|
+
chap,
|
112
|
+
sec,
|
113
|
+
subsec,
|
114
|
+
cm,
|
115
|
+
supervisor=True,
|
116
|
+
extra_instruction=inst,
|
117
|
+
)
|
106
118
|
|
107
|
-
instruction
|
108
|
-
|
109
|
-
if await
|
110
|
-
raw =
|
119
|
+
if instruction := await text("Enter the instructions to improve").ask_async():
|
120
|
+
raw = await self.write_raw(article, article_outline, chap, sec, subsec, cm, instruction)
|
121
|
+
if edt := await text("Edit", default=raw).ask_async():
|
122
|
+
raw = edt
|
111
123
|
|
112
124
|
r_print(raw)
|
113
125
|
|
@@ -121,11 +133,14 @@ class WriteArticleContentRAG(Action, RAG, Extract):
|
|
121
133
|
sec: ArticleSection,
|
122
134
|
subsec: ArticleSubsection,
|
123
135
|
) -> ArticleSubsection:
|
124
|
-
|
125
|
-
|
136
|
+
cm = CitationManager()
|
137
|
+
|
138
|
+
await self.search_database(article, article_outline, chap, sec, subsec, cm)
|
126
139
|
|
127
140
|
raw_paras = await self.write_raw(article, article_outline, chap, sec, subsec, cm)
|
128
141
|
|
142
|
+
raw_paras = "\n".join(p for p in raw_paras.splitlines() if p and not p.endswith("**") and not p.startswith("#"))
|
143
|
+
|
129
144
|
return await self.extract_new_subsec(subsec, raw_paras, cm)
|
130
145
|
|
131
146
|
async def extract_new_subsec(
|
@@ -139,6 +154,7 @@ class WriteArticleContentRAG(Action, RAG, Extract):
|
|
139
154
|
f"Above is the subsection titled `{subsec.title}`.\n"
|
140
155
|
f"I need you to extract the content to update my subsection obj provided below.\n{self.req}"
|
141
156
|
f"{subsec.display()}\n",
|
157
|
+
model=self.extractor_model,
|
142
158
|
),
|
143
159
|
"Failed to propose new subsection.",
|
144
160
|
)
|
@@ -162,12 +178,15 @@ class WriteArticleContentRAG(Action, RAG, Extract):
|
|
162
178
|
return (
|
163
179
|
(
|
164
180
|
await self.aask(
|
165
|
-
f"{cm.as_prompt()}\nAbove is some related reference retrieved for you."
|
181
|
+
f"{cm.as_prompt()}\nAbove is some related reference from other auther retrieved for you."
|
166
182
|
f"{article_outline.finalized_dump()}\n\nAbove is my article outline, I m writing graduate thesis titled `{article.title}`. "
|
167
183
|
f"More specifically, i m witting the Chapter `{chap.title}` >> Section `{sec.title}` >> Subsection `{subsec.title}`.\n"
|
168
184
|
f"Please help me write the paragraphs of the subsec mentioned above, which is `{subsec.title}`.\n"
|
169
185
|
f"{self.req}\n"
|
170
|
-
f"You SHALL use `{article.language}` as writing language.\n{extra_instruction}"
|
186
|
+
f"You SHALL use `{article.language}` as writing language.\n{extra_instruction}\n"
|
187
|
+
f"Do not use numbered list to display the outcome, you should regard you are writing the main text of the thesis.\n"
|
188
|
+
f"You should not copy others' works from the references directly on to my thesis, we can only harness the conclusion they have drawn.\n"
|
189
|
+
f"No extra explanation is allowed."
|
171
190
|
)
|
172
191
|
)
|
173
192
|
.replace(r" \( ", "$")
|
@@ -175,7 +194,9 @@ class WriteArticleContentRAG(Action, RAG, Extract):
|
|
175
194
|
.replace(r"\(", "$")
|
176
195
|
.replace(r"\)", "$")
|
177
196
|
.replace("\\[\n", "$$\n")
|
197
|
+
.replace("\\[ ", "$$\n")
|
178
198
|
.replace("\n\\]", "\n$$")
|
199
|
+
.replace(" \\]", "\n$$")
|
179
200
|
)
|
180
201
|
|
181
202
|
async def search_database(
|
@@ -185,28 +206,113 @@ class WriteArticleContentRAG(Action, RAG, Extract):
|
|
185
206
|
chap: ArticleChapter,
|
186
207
|
sec: ArticleSection,
|
187
208
|
subsec: ArticleSubsection,
|
209
|
+
cm: CitationManager,
|
188
210
|
extra_instruction: str = "",
|
189
211
|
supervisor: bool = False,
|
190
|
-
) ->
|
212
|
+
) -> None:
|
191
213
|
"""Search database for related references."""
|
214
|
+
search_req = (
|
215
|
+
f"{article_outline.finalized_dump()}\n\nAbove is my article outline, I m writing graduate thesis titled `{article.title}`. "
|
216
|
+
f"More specifically, i m witting the Chapter `{chap.title}` >> Section `{sec.title}` >> Subsection `{subsec.title}`.\n"
|
217
|
+
f"I need to search related references to build up the content of the subsec mentioned above, which is `{subsec.title}`.\n"
|
218
|
+
f"provide 10~16 queries as possible, to get best result!\n"
|
219
|
+
f"You should provide both English version and chinese version of the refined queries!\n{extra_instruction}\n"
|
220
|
+
)
|
221
|
+
|
192
222
|
ref_q = ok(
|
193
223
|
await self.arefined_query(
|
194
|
-
|
195
|
-
f"More specifically, i m witting the Chapter `{chap.title}` >> Section `{sec.title}` >> Subsection `{subsec.title}`.\n"
|
196
|
-
f"I need to search related references to build up the content of the subsec mentioned above, which is `{subsec.title}`.\n"
|
197
|
-
f"provide 10~16 queries as possible, to get best result!\n"
|
198
|
-
f"You should provide both English version and chinese version of the refined queries!\n{extra_instruction}\n",
|
224
|
+
search_req,
|
199
225
|
model=self.query_model,
|
200
226
|
),
|
201
227
|
"Failed to refine query.",
|
202
228
|
)
|
203
229
|
|
230
|
+
if supervisor:
|
231
|
+
ref_q = await ask_retain(ref_q)
|
232
|
+
ret = await self.aretrieve(
|
233
|
+
ref_q,
|
234
|
+
ArticleChunk,
|
235
|
+
final_limit=self.ref_limit,
|
236
|
+
result_per_query=self.result_per_query,
|
237
|
+
similarity_threshold=self.threshold,
|
238
|
+
)
|
239
|
+
|
240
|
+
cm.add_chunks(ok(ret))
|
241
|
+
ref_q = await self.arefined_query(
|
242
|
+
f"{cm.as_prompt()}\n\nAbove is the retrieved references in the first RAG, now we need to perform the second RAG.\n\n{search_req}",
|
243
|
+
model=self.query_model,
|
244
|
+
)
|
245
|
+
|
246
|
+
if ref_q is None:
|
247
|
+
logger.warning("Second refine query is None, skipping.")
|
248
|
+
return
|
204
249
|
if supervisor:
|
205
250
|
ref_q = await ask_retain(ref_q)
|
206
251
|
|
207
|
-
|
208
|
-
ref_q,
|
252
|
+
ret = await self.aretrieve(
|
253
|
+
ref_q,
|
254
|
+
ArticleChunk,
|
255
|
+
final_limit=int(self.ref_limit * self.search_increment_multiplier),
|
256
|
+
result_per_query=int(self.result_per_query * self.search_increment_multiplier),
|
257
|
+
similarity_threshold=self.threshold,
|
209
258
|
)
|
259
|
+
if ret is None:
|
260
|
+
logger.warning("Second retrieve is None, skipping.")
|
261
|
+
return
|
262
|
+
cm.add_chunks(ret)
|
263
|
+
|
264
|
+
|
265
|
+
class ArticleConsultRAG(Action, RAG):
|
266
|
+
"""Write an article based on the provided outline."""
|
267
|
+
|
268
|
+
output_key: str = "consult_count"
|
269
|
+
|
270
|
+
ref_limit: int = 20
|
271
|
+
"""The final limit of references."""
|
272
|
+
ref_per_q: int = 3
|
273
|
+
"""The limit of references to retrieve per query."""
|
274
|
+
similarity_threshold: float = 0.62
|
275
|
+
"""The similarity threshold of references to retrieve."""
|
276
|
+
ref_q_model: Optional[str] = None
|
277
|
+
"""The model to use for refining query."""
|
278
|
+
req: str = TYPST_CITE_USAGE
|
279
|
+
"""The request for the rag model."""
|
280
|
+
|
281
|
+
@precheck_package(
|
282
|
+
"questionary", "`questionary` is required for supervisor mode, please install it by `fabricatio[qa]`"
|
283
|
+
)
|
284
|
+
async def _execute(self, collection_name: Optional[str] = None, **cxt) -> int:
|
285
|
+
from questionary import confirm, text
|
286
|
+
from rich import print as r_print
|
287
|
+
|
288
|
+
from fabricatio.rust import convert_all_block_tex, convert_all_inline_tex
|
289
|
+
|
290
|
+
self.target_collection = collection_name or self.safe_target_collection
|
291
|
+
|
292
|
+
cm = CitationManager()
|
293
|
+
|
294
|
+
counter = 0
|
295
|
+
while (req := await text("User: ").ask_async()) is not None:
|
296
|
+
if await confirm("Empty the cm?").ask_async():
|
297
|
+
cm.empty()
|
298
|
+
ref_q = await self.arefined_query(req, model=self.ref_q_model)
|
299
|
+
refs = await self.aretrieve(
|
300
|
+
ok(ref_q, "Failed to refine query."),
|
301
|
+
ArticleChunk,
|
302
|
+
final_limit=self.ref_limit,
|
303
|
+
result_per_query=self.ref_per_q,
|
304
|
+
similarity_threshold=self.similarity_threshold,
|
305
|
+
)
|
306
|
+
|
307
|
+
ret = await self.aask(f"{cm.add_chunks(refs).as_prompt()}\n{self.req}\n{req}")
|
308
|
+
ret = convert_all_inline_tex(ret)
|
309
|
+
ret = convert_all_block_tex(ret)
|
310
|
+
ret = cm.apply(ret)
|
311
|
+
|
312
|
+
r_print(ret)
|
313
|
+
counter += 1
|
314
|
+
logger.info(f"{counter} rounds of conversation.")
|
315
|
+
return counter
|
210
316
|
|
211
317
|
|
212
318
|
class TweakArticleRAG(Action, RAG, Censor):
|
@@ -1,16 +1,18 @@
|
|
1
1
|
"""Dump the finalized output to a file."""
|
2
2
|
|
3
3
|
from pathlib import Path
|
4
|
-
from typing import Any, Iterable, List, Mapping, Optional, Type
|
4
|
+
from typing import Any, Dict, Iterable, List, Mapping, Optional, Type
|
5
5
|
|
6
|
+
from fabricatio import TEMPLATE_MANAGER
|
6
7
|
from fabricatio.journal import logger
|
7
8
|
from fabricatio.models.action import Action
|
8
9
|
from fabricatio.models.generic import FinalizedDumpAble, FromMapping, PersistentAble
|
9
10
|
from fabricatio.models.task import Task
|
11
|
+
from fabricatio.models.usages import LLMUsage
|
10
12
|
from fabricatio.utils import ok
|
11
13
|
|
12
14
|
|
13
|
-
class DumpFinalizedOutput(Action):
|
15
|
+
class DumpFinalizedOutput(Action, LLMUsage):
|
14
16
|
"""Dump the finalized output to a file."""
|
15
17
|
|
16
18
|
output_key: str = "dump_path"
|
@@ -38,7 +40,37 @@ class DumpFinalizedOutput(Action):
|
|
38
40
|
return dump_path.as_posix()
|
39
41
|
|
40
42
|
|
41
|
-
class
|
43
|
+
class RenderedDump(Action, LLMUsage):
|
44
|
+
"""Render the data to a file."""
|
45
|
+
|
46
|
+
output_key: str = "dump_path"
|
47
|
+
dump_path: Optional[str] = None
|
48
|
+
|
49
|
+
template_name: str
|
50
|
+
"""The template name to render the data."""
|
51
|
+
|
52
|
+
async def _execute(
|
53
|
+
self,
|
54
|
+
to_dump: Dict[str, Any],
|
55
|
+
task_input: Optional[Task] = None,
|
56
|
+
dump_path: Optional[str | Path] = None,
|
57
|
+
**_,
|
58
|
+
) -> str:
|
59
|
+
dump_path = Path(
|
60
|
+
dump_path
|
61
|
+
or self.dump_path
|
62
|
+
or ok(
|
63
|
+
await self.awhich_pathstr(
|
64
|
+
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."
|
65
|
+
),
|
66
|
+
"Could not find the path of file to dump the data.",
|
67
|
+
)
|
68
|
+
)
|
69
|
+
logger.info(f"Saving output to {dump_path.as_posix()}")
|
70
|
+
return TEMPLATE_MANAGER.render_template(self.template_name, to_dump)
|
71
|
+
|
72
|
+
|
73
|
+
class PersistentAll(Action, LLMUsage):
|
42
74
|
"""Persist all the data to a file."""
|
43
75
|
|
44
76
|
output_key: str = "persistent_count"
|
@@ -328,9 +328,9 @@ class RoutingConfig(BaseModel):
|
|
328
328
|
allowed_fails: Optional[int] = 3
|
329
329
|
"""The number of allowed fails before the routing is considered failed."""
|
330
330
|
retry_after: int = 15
|
331
|
-
"""
|
332
|
-
cooldown_time: Optional[int] =
|
333
|
-
"""
|
331
|
+
"""Minimum time to wait before retrying a failed request."""
|
332
|
+
cooldown_time: Optional[int] = 60
|
333
|
+
"""Time to cooldown a deployment after failure in seconds."""
|
334
334
|
|
335
335
|
|
336
336
|
class Settings(BaseSettings):
|
@@ -20,7 +20,7 @@ def dump_text(path: Union[str, Path], text: str) -> None:
|
|
20
20
|
Returns:
|
21
21
|
None
|
22
22
|
"""
|
23
|
-
Path(path).write_text(text, encoding="utf-8", errors="ignore")
|
23
|
+
Path(path).write_text(text, encoding="utf-8", errors="ignore", newline="\n")
|
24
24
|
|
25
25
|
|
26
26
|
def copy_file(src: Union[str, Path], dst: Union[str, Path]) -> None:
|
@@ -12,12 +12,12 @@ Classes:
|
|
12
12
|
import traceback
|
13
13
|
from abc import abstractmethod
|
14
14
|
from asyncio import Queue, create_task
|
15
|
-
from typing import Any, Dict, Self, Tuple, Type, Union, final
|
15
|
+
from typing import Any, Dict, Self, Sequence, Tuple, Type, Union, final
|
16
16
|
|
17
17
|
from fabricatio.journal import logger
|
18
18
|
from fabricatio.models.generic import WithBriefing
|
19
19
|
from fabricatio.models.task import Task
|
20
|
-
from fabricatio.models.usages import
|
20
|
+
from fabricatio.models.usages import ToolBoxUsage
|
21
21
|
from fabricatio.utils import override_kwargs
|
22
22
|
from pydantic import Field, PrivateAttr
|
23
23
|
|
@@ -26,7 +26,7 @@ OUTPUT_KEY = "task_output"
|
|
26
26
|
INPUT_KEY = "task_input"
|
27
27
|
|
28
28
|
|
29
|
-
class Action(WithBriefing
|
29
|
+
class Action(WithBriefing):
|
30
30
|
"""Class that represents an action to be executed in a workflow.
|
31
31
|
|
32
32
|
Actions are the atomic units of work in a workflow. Each action performs
|
@@ -96,9 +96,9 @@ class Action(WithBriefing, LLMUsage):
|
|
96
96
|
return f"## Your personality: \n{self.personality}\n# The action you are going to perform: \n{super().briefing}"
|
97
97
|
return f"# The action you are going to perform: \n{super().briefing}"
|
98
98
|
|
99
|
-
def to_task_output(self) -> Self:
|
99
|
+
def to_task_output(self, task_output_key: str = OUTPUT_KEY) -> Self:
|
100
100
|
"""Set the output key to OUTPUT_KEY and return the action instance."""
|
101
|
-
self.output_key =
|
101
|
+
self.output_key = task_output_key
|
102
102
|
return self
|
103
103
|
|
104
104
|
|
@@ -123,9 +123,7 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
|
|
123
123
|
_instances: Tuple[Action, ...] = PrivateAttr(default_factory=tuple)
|
124
124
|
"""Instantiated action objects to be executed in this workflow."""
|
125
125
|
|
126
|
-
steps:
|
127
|
-
frozen=True,
|
128
|
-
)
|
126
|
+
steps: Sequence[Union[Type[Action], Action]] = Field(frozen=True)
|
129
127
|
"""The sequence of actions to be executed, can be action classes or instances."""
|
130
128
|
|
131
129
|
task_input_key: str = Field(default=INPUT_KEY)
|