fabricatio 0.2.11.dev3__tar.gz → 0.2.12.dev2__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.dev2}/.gitignore +2 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/PKG-INFO +1 -1
- fabricatio-0.2.12.dev2/examples/write_article/.gitignore +4 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/write_article/write_article.py +88 -31
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/write_outline/write_outline.py +5 -2
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/pyproject.toml +3 -2
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/actions/article_rag.py +171 -71
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/actions/output.py +43 -2
- fabricatio-0.2.12.dev2/python/fabricatio/capabilities/advanced_rag.py +53 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/capabilities/rag.py +4 -4
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/config.py +3 -3
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/fs/curd.py +1 -1
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/models/action.py +6 -8
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/models/extra/aricle_rag.py +42 -19
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/models/extra/article_base.py +55 -26
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/models/extra/article_main.py +58 -5
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/models/generic.py +10 -6
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/models/kwargs_types.py +1 -1
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/models/role.py +5 -4
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/rust.pyi +10 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/utils.py +1 -1
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/src/templates.rs +1 -1
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/src/typst_tools.rs +38 -7
- fabricatio-0.2.12.dev2/templates.tar.gz +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/tests/test_models/test_problem.py +17 -37
- fabricatio-0.2.12.dev2/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.dev2}/.github/workflows/build-package.yaml +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/.github/workflows/ruff.yaml +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/.github/workflows/tests.yaml +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/.python-version +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/Cargo.lock +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/Cargo.toml +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/LICENSE +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/Makefile +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/README.md +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/correct/correct.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/correct/correct_loop.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/extract_and_inject/.gitignore +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/extract_and_inject/article_rag.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/extract_and_inject/ask.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/extract_and_inject/chunk_article.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/extract_and_inject/extract_and_inject.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/extract_article/extract.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/llm_usages/llm_usage.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/make_a_rating/rating.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/make_diary/commits.json +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/make_diary/diary.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/minor/hello_fabricatio.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/minor/write_a_poem.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/propose_task/.gitignore +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/propose_task/propose.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/reviewer/censor.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/reviewer/review.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/rules/.gitignore +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/rules/draft_ruleset.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/search_bibtex/.gitignore +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/search_bibtex/search.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/simple_chat/chat.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/simple_rag/simple_rag.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/task_handle/handle_task.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/write_article/article_rag.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/write_article/post_process.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/write_outline/.gitignore +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/examples/write_outline/write_outline_corrected.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/__init__.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/actions/__init__.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/actions/article.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/actions/fs.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/actions/rag.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/actions/rules.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/capabilities/__init__.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/capabilities/advanced_judge.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/capabilities/censor.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/capabilities/check.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/capabilities/correct.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/capabilities/extract.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/capabilities/propose.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/capabilities/rating.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/capabilities/review.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/capabilities/task.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/constants.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/core.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/decorators.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/fs/__init__.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/fs/readers.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/journal.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/models/adv_kwargs_types.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/models/events.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/models/extra/__init__.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/models/extra/advanced_judge.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/models/extra/article_essence.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/models/extra/article_outline.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/models/extra/article_proposal.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/models/extra/patches.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/models/extra/problem.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/models/extra/rag.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/models/extra/rule.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/models/task.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/models/tool.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/models/usages.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/parser.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/py.typed +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/rust_instances.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/toolboxes/__init__.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/toolboxes/arithmetic.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/toolboxes/fs.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/workflows/__init__.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/workflows/articles.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/python/fabricatio/workflows/rag.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/src/bib_tools.rs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/src/hash.rs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/src/hbs_helpers.rs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/src/language.rs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/src/lib.rs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/src/word_split.rs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/as_prompt.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/check_string.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/claude-xml.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/clean-up-code.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/co_validation.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/create_json_obj.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/dependencies.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/document-the-code.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/draft_rating_criteria.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/draft_rating_manual.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/draft_rating_weights_klee.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/draft_tool_usage_code.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/extract.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/extract_criteria_from_reasons.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/extract_reasons_from_examples.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/fix-bugs.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/fix_troubled_obj.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/fix_troubled_string.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/generic_string.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/improve-performance.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/liststr.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/make_choice.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/make_judgment.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/pathstr.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/rate_fine_grind.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/refactor.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/refined_query.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/retrieved_display.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/review_string.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/rule_requirement.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/ruleset_requirement_breakdown.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/task_briefing.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/web-ctf-solver.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/write-git-commit.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/write-github-pull-request.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/templates/built-in/write-github-readme.hbs +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/tests/test_config.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/tests/test_models/test_action.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/tests/test_models/test_advanced.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/tests/test_models/test_generic.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/tests/test_models/test_role.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/tests/test_models/test_task.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/tests/test_models/test_tool.py +0 -0
- {fabricatio-0.2.11.dev3 → fabricatio-0.2.12.dev2}/tests/test_models/test_usages.py +0 -0
@@ -6,25 +6,26 @@ 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, RenderedDump
|
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/
|
22
|
-
llm_temperature=0.
|
23
|
-
|
24
|
-
llm_top_p=0.
|
21
|
+
llm_model="openai/deepseek-v3-250324",
|
22
|
+
llm_temperature=0.45,
|
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
26
|
llm_rpm=600,
|
27
27
|
llm_tpm=900000,
|
28
|
+
llm_timeout=600,
|
28
29
|
registry={
|
29
30
|
Event.quick_instantiate(ns := "article"): WorkFlow(
|
30
31
|
name="Generate Article",
|
@@ -33,38 +34,48 @@ Role(
|
|
33
34
|
GenerateArticleProposal,
|
34
35
|
GenerateInitialOutline(output_key="article_outline"),
|
35
36
|
PersistentAll,
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
(
|
38
|
+
a := WriteArticleContentRAG(
|
39
|
+
output_key="to_dump",
|
40
|
+
ref_limit=18,
|
41
|
+
threshold=0.58,
|
42
|
+
result_per_query=2,
|
43
|
+
extractor_model={"model": "openai/qwen-max"},
|
44
|
+
query_model={"model": "openai/qwen-turbo", "temperature": 0.3, "top_p": 0.85},
|
45
|
+
)
|
44
46
|
),
|
45
|
-
DumpFinalizedOutput(output_key="task_output"),
|
46
47
|
PersistentAll,
|
48
|
+
DumpFinalizedOutput(dump_path="median.typ"),
|
49
|
+
RenderedDump(template_name="article").to_task_output(),
|
47
50
|
),
|
48
51
|
),
|
49
|
-
Event.quick_instantiate(ns2 := ""): WorkFlow(
|
52
|
+
Event.quick_instantiate(ns2 := "complete"): WorkFlow(
|
50
53
|
name="Generate Article",
|
51
54
|
description="Generate an article with given raw article outline. dump the outline to the given path. in typst format.",
|
52
55
|
steps=(
|
53
|
-
ExtractOutlineFromRaw,
|
56
|
+
ExtractOutlineFromRaw(output_key="article_outline"),
|
54
57
|
PersistentAll,
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
58
|
+
a,
|
59
|
+
PersistentAll,
|
60
|
+
DumpFinalizedOutput(dump_path="median.typ"),
|
61
|
+
RenderedDump(template_name="article").to_task_output(),
|
62
|
+
),
|
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,
|
65
69
|
PersistentAll,
|
70
|
+
DumpFinalizedOutput(dump_path="median.typ"),
|
71
|
+
RenderedDump(template_name="article").to_task_output(),
|
66
72
|
),
|
67
73
|
),
|
74
|
+
Event.quick_instantiate(ns4 := "consult"): WorkFlow(
|
75
|
+
name="Consult Article",
|
76
|
+
description="Consult an article with given article outline. dump the outline to the given path. in typst format.",
|
77
|
+
steps=(ArticleConsultRAG(ref_q_model={"model":"openai/qwen-turbo"}).to_task_output(),),
|
78
|
+
),
|
68
79
|
},
|
69
80
|
)
|
70
81
|
|
@@ -72,6 +83,52 @@ Role(
|
|
72
83
|
app = Typer()
|
73
84
|
|
74
85
|
|
86
|
+
@app.command()
|
87
|
+
def consult(
|
88
|
+
collection_name: str = typer.Option("article_chunks", "-c", "--collection-name", help="Name of the collection."),
|
89
|
+
) -> None:
|
90
|
+
"""Consult an article based on a given article outline."""
|
91
|
+
_ = asyncio.run(
|
92
|
+
Task(name="Answer Question")
|
93
|
+
.update_init_context(
|
94
|
+
collection_name=collection_name,
|
95
|
+
)
|
96
|
+
.delegate(ns4)
|
97
|
+
)
|
98
|
+
|
99
|
+
logger.info("Finished")
|
100
|
+
|
101
|
+
|
102
|
+
@app.command()
|
103
|
+
def finish(
|
104
|
+
article_outline_path: Path = typer.Argument( # noqa: B008
|
105
|
+
help="Path to the article outline raw file."
|
106
|
+
),
|
107
|
+
dump_path: Path = typer.Option(Path("out.typ"), "-d", "--dump-path", help="Path to dump the final output."), # noqa: B008
|
108
|
+
persist_dir: Path = typer.Option( # noqa: B008
|
109
|
+
Path("persistent"), "-p", "--persist-dir", help="Directory to persist the output."
|
110
|
+
),
|
111
|
+
collection_name: str = typer.Option("article_chunks", "-c", "--collection-name", help="Name of the collection."),
|
112
|
+
supervisor: bool = typer.Option(False, "-s", "--supervisor", help="Whether to use the supervisor mode."),
|
113
|
+
) -> None:
|
114
|
+
"""Finish an article based on a given article outline."""
|
115
|
+
path = ok(
|
116
|
+
asyncio.run(
|
117
|
+
Task(name="write an article")
|
118
|
+
.update_init_context(
|
119
|
+
article_outline=ArticleOutline.from_persistent(article_outline_path),
|
120
|
+
dump_path=dump_path,
|
121
|
+
persist_dir=persist_dir,
|
122
|
+
collection_name=collection_name,
|
123
|
+
supervisor=supervisor,
|
124
|
+
)
|
125
|
+
.delegate(ns3)
|
126
|
+
),
|
127
|
+
"Failed to generate an article ",
|
128
|
+
)
|
129
|
+
logger.success(f"The outline is saved in:\n{path}")
|
130
|
+
|
131
|
+
|
75
132
|
@app.command()
|
76
133
|
def completion(
|
77
134
|
article_outline_raw_path: Path = typer.Option( # noqa: B008
|
@@ -95,7 +152,7 @@ def completion(
|
|
95
152
|
collection_name=collection_name,
|
96
153
|
supervisor=supervisor,
|
97
154
|
)
|
98
|
-
.delegate(
|
155
|
+
.delegate(ns2)
|
99
156
|
),
|
100
157
|
"Failed to generate an article ",
|
101
158
|
)
|
@@ -3,6 +3,8 @@
|
|
3
3
|
import asyncio
|
4
4
|
|
5
5
|
from fabricatio import Event, Role, logger
|
6
|
+
from fabricatio.models.task import Task
|
7
|
+
from fabricatio.utils import ok
|
6
8
|
from fabricatio.workflows.articles import WriteOutlineCorrectedWorkFlow
|
7
9
|
|
8
10
|
|
@@ -14,10 +16,11 @@ async def main() -> None:
|
|
14
16
|
registry={Event.quick_instantiate(ns := "article"): WriteOutlineCorrectedWorkFlow},
|
15
17
|
)
|
16
18
|
|
17
|
-
proposed_task = await role.
|
19
|
+
proposed_task = await role.propose(
|
20
|
+
Task,
|
18
21
|
"You need to read the `./article_briefing.txt` file and write an outline for the article in typst format. The outline should be saved in the `./out.typ` file.",
|
19
22
|
)
|
20
|
-
path = await proposed_task.delegate(ns)
|
23
|
+
path = await ok(proposed_task).delegate(ns)
|
21
24
|
logger.success(f"The outline is saved in:\n{path}")
|
22
25
|
|
23
26
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[project]
|
2
2
|
name = "fabricatio"
|
3
|
-
version = "0.2.
|
3
|
+
version = "0.2.12-dev2"
|
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,7 +4,10 @@ from asyncio import gather
|
|
4
4
|
from pathlib import Path
|
5
5
|
from typing import List, Optional
|
6
6
|
|
7
|
+
from pydantic import Field, PositiveInt
|
8
|
+
|
7
9
|
from fabricatio import BibManager
|
10
|
+
from fabricatio.capabilities.advanced_rag import AdvancedRAG
|
8
11
|
from fabricatio.capabilities.censor import Censor
|
9
12
|
from fabricatio.capabilities.extract import Extract
|
10
13
|
from fabricatio.capabilities.rag import RAG
|
@@ -16,59 +19,63 @@ from fabricatio.models.extra.article_essence import ArticleEssence
|
|
16
19
|
from fabricatio.models.extra.article_main import Article, ArticleChapter, ArticleSection, ArticleSubsection
|
17
20
|
from fabricatio.models.extra.article_outline import ArticleOutline
|
18
21
|
from fabricatio.models.extra.rule import RuleSet
|
22
|
+
from fabricatio.models.kwargs_types import ChooseKwargs, LLMKwargs
|
19
23
|
from fabricatio.utils import ask_retain, ok
|
20
24
|
|
25
|
+
TYPST_CITE_USAGE = (
|
26
|
+
"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"
|
27
|
+
"Everything is build upon the typst language, which is similar to latex, \n"
|
28
|
+
"Legal citing syntax examples(seperated by |): [[1]]|[[1,2]]|[[1-3]]|[[12,13-15]]|[[1-3,5-7]]\n"
|
29
|
+
"Illegal citing syntax examples(seperated by |): [[1],[2],[3]]|[[1],[1-2]]\n"
|
30
|
+
"Those reference mark shall not be omitted during the extraction\n"
|
31
|
+
"It's recommended to cite multiple references that supports your conclusion at a time.\n"
|
32
|
+
"Wrap inline expression with '\\(' and '\\)',like '\\(>5m\\)' '\\(89%\\)', and wrap block equation with '\\[' and '\\]'.\n"
|
33
|
+
"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"
|
34
|
+
"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."
|
35
|
+
"Below is two usage example:\n"
|
36
|
+
"```typst\n"
|
37
|
+
"See @eqt:mass-energy-equation , it's the foundation of physics.\n"
|
38
|
+
"\\[\n"
|
39
|
+
"E = m c^2\n"
|
40
|
+
"\\] <mass-energy-equation>\n\n\n"
|
41
|
+
"In @eqt:mass-energy-equation , \\(m\\) stands for mass, \\(c\\) stands for speed of light, and \\(E\\) stands for energy. \n"
|
42
|
+
"```\n"
|
43
|
+
)
|
44
|
+
|
21
45
|
|
22
46
|
class WriteArticleContentRAG(Action, RAG, Extract):
|
23
47
|
"""Write an article based on the provided outline."""
|
24
48
|
|
49
|
+
search_increment_multiplier: float = 1.6
|
50
|
+
"""The increment multiplier of the search increment."""
|
25
51
|
ref_limit: int = 35
|
26
52
|
"""The limit of references to be retrieved"""
|
27
|
-
threshold: float = 0.
|
53
|
+
threshold: float = 0.62
|
28
54
|
"""The threshold of relevance"""
|
29
|
-
extractor_model:
|
55
|
+
extractor_model: LLMKwargs
|
30
56
|
"""The model to use for extracting the content from the retrieved references."""
|
31
|
-
query_model:
|
57
|
+
query_model: LLMKwargs
|
32
58
|
"""The model to use for querying the database"""
|
33
59
|
supervisor: bool = False
|
34
60
|
"""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
|
-
)
|
61
|
+
result_per_query: PositiveInt = 4
|
62
|
+
"""The number of results to be returned per query."""
|
63
|
+
req: str = TYPST_CITE_USAGE
|
64
|
+
"""The req of the write article content."""
|
55
65
|
|
56
66
|
async def _execute(
|
57
67
|
self,
|
58
68
|
article_outline: ArticleOutline,
|
59
|
-
collection_name: str =
|
69
|
+
collection_name: Optional[str] = None,
|
60
70
|
supervisor: Optional[bool] = None,
|
61
71
|
**cxt,
|
62
72
|
) -> Article:
|
63
73
|
article = Article.from_outline(article_outline).update_ref(article_outline)
|
64
|
-
|
74
|
+
self.target_collection = collection_name or self.safe_target_collection
|
65
75
|
if supervisor or (supervisor is None and self.supervisor):
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
for chap, sec, subsec in article.iter_subsections()
|
70
|
-
]
|
71
|
-
)
|
76
|
+
for chap, sec, subsec in article.iter_subsections():
|
77
|
+
await self._supervisor_inner(article, article_outline, chap, sec, subsec)
|
78
|
+
|
72
79
|
else:
|
73
80
|
await gather(
|
74
81
|
*[
|
@@ -92,22 +99,29 @@ class WriteArticleContentRAG(Action, RAG, Extract):
|
|
92
99
|
from questionary import confirm, text
|
93
100
|
from rich import print as r_print
|
94
101
|
|
95
|
-
|
96
|
-
|
97
|
-
cm = CitationManager(article_chunks=await ask_retain([r.chunk for r in ret], ret)).set_cite_number_all()
|
102
|
+
cm = CitationManager()
|
103
|
+
await self.search_database(article, article_outline, chap, sec, subsec, cm)
|
98
104
|
|
99
105
|
raw = await self.write_raw(article, article_outline, chap, sec, subsec, cm)
|
100
106
|
r_print(raw)
|
101
107
|
|
102
108
|
while not await confirm("Accept this version and continue?").ask_async():
|
103
|
-
if await
|
104
|
-
|
105
|
-
|
109
|
+
if inst := await text("Search for more refs for additional spec.").ask_async():
|
110
|
+
await self.search_database(
|
111
|
+
article,
|
112
|
+
article_outline,
|
113
|
+
chap,
|
114
|
+
sec,
|
115
|
+
subsec,
|
116
|
+
cm,
|
117
|
+
supervisor=True,
|
118
|
+
extra_instruction=inst,
|
119
|
+
)
|
106
120
|
|
107
|
-
instruction
|
108
|
-
|
109
|
-
if await
|
110
|
-
raw =
|
121
|
+
if instruction := await text("Enter the instructions to improve").ask_async():
|
122
|
+
raw = await self.write_raw(article, article_outline, chap, sec, subsec, cm, instruction)
|
123
|
+
if edt := await text("Edit", default=raw).ask_async():
|
124
|
+
raw = edt
|
111
125
|
|
112
126
|
r_print(raw)
|
113
127
|
|
@@ -121,11 +135,14 @@ class WriteArticleContentRAG(Action, RAG, Extract):
|
|
121
135
|
sec: ArticleSection,
|
122
136
|
subsec: ArticleSubsection,
|
123
137
|
) -> ArticleSubsection:
|
124
|
-
|
125
|
-
|
138
|
+
cm = CitationManager()
|
139
|
+
|
140
|
+
await self.search_database(article, article_outline, chap, sec, subsec, cm)
|
126
141
|
|
127
142
|
raw_paras = await self.write_raw(article, article_outline, chap, sec, subsec, cm)
|
128
143
|
|
144
|
+
raw_paras = "\n".join(p for p in raw_paras.splitlines() if p and not p.endswith("**") and not p.startswith("#"))
|
145
|
+
|
129
146
|
return await self.extract_new_subsec(subsec, raw_paras, cm)
|
130
147
|
|
131
148
|
async def extract_new_subsec(
|
@@ -139,11 +156,12 @@ class WriteArticleContentRAG(Action, RAG, Extract):
|
|
139
156
|
f"Above is the subsection titled `{subsec.title}`.\n"
|
140
157
|
f"I need you to extract the content to update my subsection obj provided below.\n{self.req}"
|
141
158
|
f"{subsec.display()}\n",
|
159
|
+
**self.extractor_model,
|
142
160
|
),
|
143
161
|
"Failed to propose new subsection.",
|
144
162
|
)
|
145
163
|
for p in new_subsec.paragraphs:
|
146
|
-
p.content = cm.apply(p.content)
|
164
|
+
p.content = cm.apply(p.content)
|
147
165
|
subsec.update_from(new_subsec)
|
148
166
|
logger.debug(f"{subsec.title}:rpl\n{subsec.display()}")
|
149
167
|
return subsec
|
@@ -159,23 +177,16 @@ class WriteArticleContentRAG(Action, RAG, Extract):
|
|
159
177
|
extra_instruction: str = "",
|
160
178
|
) -> str:
|
161
179
|
"""Write the raw paragraphs of the subsec."""
|
162
|
-
return (
|
163
|
-
(
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
)
|
173
|
-
.replace(r" \( ", "$")
|
174
|
-
.replace(r" \) ", "$")
|
175
|
-
.replace(r"\(", "$")
|
176
|
-
.replace(r"\)", "$")
|
177
|
-
.replace("\\[\n", "$$\n")
|
178
|
-
.replace("\n\\]", "\n$$")
|
180
|
+
return await self.aask(
|
181
|
+
f"{cm.as_prompt()}\nAbove is some related reference from other auther retrieved for you."
|
182
|
+
f"{article_outline.finalized_dump()}\n\nAbove is my article outline, I m writing graduate thesis titled `{article.title}`. "
|
183
|
+
f"More specifically, i m witting the Chapter `{chap.title}` >> Section `{sec.title}` >> Subsection `{subsec.title}`.\n"
|
184
|
+
f"Please help me write the paragraphs of the subsec mentioned above, which is `{subsec.title}`.\n"
|
185
|
+
f"{self.req}\n"
|
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."
|
179
190
|
)
|
180
191
|
|
181
192
|
async def search_database(
|
@@ -185,28 +196,117 @@ class WriteArticleContentRAG(Action, RAG, Extract):
|
|
185
196
|
chap: ArticleChapter,
|
186
197
|
sec: ArticleSection,
|
187
198
|
subsec: ArticleSubsection,
|
199
|
+
cm: CitationManager,
|
188
200
|
extra_instruction: str = "",
|
189
201
|
supervisor: bool = False,
|
190
|
-
) ->
|
202
|
+
) -> None:
|
191
203
|
"""Search database for related references."""
|
204
|
+
search_req = (
|
205
|
+
f"{article_outline.finalized_dump()}\n\nAbove is my article outline, I m writing graduate thesis titled `{article.title}`. "
|
206
|
+
f"More specifically, i m witting the Chapter `{chap.title}` >> Section `{sec.title}` >> Subsection `{subsec.title}`.\n"
|
207
|
+
f"I need to search related references to build up the content of the subsec mentioned above, which is `{subsec.title}`.\n"
|
208
|
+
f"provide 10~16 queries as possible, to get best result!\n"
|
209
|
+
f"You should provide both English version and chinese version of the refined queries!\n{extra_instruction}\n"
|
210
|
+
)
|
211
|
+
|
192
212
|
ref_q = ok(
|
193
213
|
await self.arefined_query(
|
194
|
-
|
195
|
-
|
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",
|
199
|
-
model=self.query_model,
|
214
|
+
search_req,
|
215
|
+
**self.query_model,
|
200
216
|
),
|
201
217
|
"Failed to refine query.",
|
202
218
|
)
|
203
219
|
|
220
|
+
if supervisor:
|
221
|
+
ref_q = await ask_retain(ref_q)
|
222
|
+
ret = await self.aretrieve(
|
223
|
+
ref_q,
|
224
|
+
ArticleChunk,
|
225
|
+
max_accepted=self.ref_limit,
|
226
|
+
result_per_query=self.result_per_query,
|
227
|
+
similarity_threshold=self.threshold,
|
228
|
+
)
|
229
|
+
|
230
|
+
cm.add_chunks(ok(ret))
|
231
|
+
ref_q = await self.arefined_query(
|
232
|
+
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}",
|
233
|
+
**self.query_model,
|
234
|
+
)
|
235
|
+
|
236
|
+
if ref_q is None:
|
237
|
+
logger.warning("Second refine query is None, skipping.")
|
238
|
+
return
|
204
239
|
if supervisor:
|
205
240
|
ref_q = await ask_retain(ref_q)
|
206
241
|
|
207
|
-
|
208
|
-
ref_q,
|
242
|
+
ret = await self.aretrieve(
|
243
|
+
ref_q,
|
244
|
+
ArticleChunk,
|
245
|
+
max_accepted=int(self.ref_limit * self.search_increment_multiplier),
|
246
|
+
result_per_query=int(self.result_per_query * self.search_increment_multiplier),
|
247
|
+
similarity_threshold=self.threshold,
|
209
248
|
)
|
249
|
+
if ret is None:
|
250
|
+
logger.warning("Second retrieve is None, skipping.")
|
251
|
+
return
|
252
|
+
cm.add_chunks(ret)
|
253
|
+
|
254
|
+
|
255
|
+
class ArticleConsultRAG(Action, AdvancedRAG):
|
256
|
+
"""Write an article based on the provided outline."""
|
257
|
+
|
258
|
+
output_key: str = "consult_count"
|
259
|
+
search_increment_multiplier: float = 1.6
|
260
|
+
"""The multiplier to increase the limit of references to retrieve per query."""
|
261
|
+
ref_limit: int = 20
|
262
|
+
"""The final limit of references."""
|
263
|
+
ref_per_q: int = 3
|
264
|
+
"""The limit of references to retrieve per query."""
|
265
|
+
similarity_threshold: float = 0.62
|
266
|
+
"""The similarity threshold of references to retrieve."""
|
267
|
+
ref_q_model: ChooseKwargs = Field(default_factory=ChooseKwargs)
|
268
|
+
"""The model to use for refining query."""
|
269
|
+
req: str = TYPST_CITE_USAGE
|
270
|
+
"""The request for the rag model."""
|
271
|
+
|
272
|
+
@precheck_package(
|
273
|
+
"questionary", "`questionary` is required for supervisor mode, please install it by `fabricatio[qa]`"
|
274
|
+
)
|
275
|
+
async def _execute(self, collection_name: Optional[str] = None, **cxt) -> int:
|
276
|
+
from questionary import confirm, text
|
277
|
+
from rich import print as r_print
|
278
|
+
|
279
|
+
from fabricatio.rust import convert_all_block_tex, convert_all_inline_tex, fix_misplaced_labels
|
280
|
+
|
281
|
+
self.target_collection = collection_name or self.safe_target_collection
|
282
|
+
|
283
|
+
cm = CitationManager()
|
284
|
+
|
285
|
+
counter = 0
|
286
|
+
while (req := await text("User: ").ask_async()) is not None:
|
287
|
+
if await confirm("Empty the cm?").ask_async():
|
288
|
+
cm.empty()
|
289
|
+
await self.clued_search(
|
290
|
+
req,
|
291
|
+
cm,
|
292
|
+
refinery_kwargs=self.ref_q_model,
|
293
|
+
expand_multiplier=self.search_increment_multiplier,
|
294
|
+
base_accepted=self.ref_limit,
|
295
|
+
result_per_query=self.ref_per_q,
|
296
|
+
similarity_threshold=self.similarity_threshold,
|
297
|
+
)
|
298
|
+
|
299
|
+
ret = await self.aask(f"{cm.as_prompt()}\n{self.req}\n{req}")
|
300
|
+
|
301
|
+
ret = fix_misplaced_labels(ret)
|
302
|
+
ret = convert_all_inline_tex(ret)
|
303
|
+
ret = convert_all_block_tex(ret)
|
304
|
+
ret = cm.apply(ret)
|
305
|
+
|
306
|
+
r_print(ret)
|
307
|
+
counter += 1
|
308
|
+
logger.info(f"{counter} rounds of conversation.")
|
309
|
+
return counter
|
210
310
|
|
211
311
|
|
212
312
|
class TweakArticleRAG(Action, RAG, Censor):
|
@@ -290,7 +390,7 @@ class TweakArticleRAG(Action, RAG, Censor):
|
|
290
390
|
await self.censor_obj_inplace(
|
291
391
|
subsec,
|
292
392
|
ruleset=ruleset,
|
293
|
-
reference=f"{'\n\n'.join(d.display() for d in await self.aretrieve(refind_q, document_model=ArticleEssence,
|
393
|
+
reference=f"{'\n\n'.join(d.display() for d in await self.aretrieve(refind_q, document_model=ArticleEssence, max_accepted=self.ref_limit))}\n\n"
|
294
394
|
f"You can use Reference above to rewrite the `{subsec.__class__.__name__}`.\n"
|
295
395
|
f"You should Always use `{subsec.language}` as written language, "
|
296
396
|
f"which is the original language of the `{subsec.title}`. "
|
@@ -3,14 +3,17 @@
|
|
3
3
|
from pathlib import Path
|
4
4
|
from typing import Any, Iterable, List, Mapping, Optional, Type
|
5
5
|
|
6
|
+
from fabricatio import TEMPLATE_MANAGER
|
7
|
+
from fabricatio.fs import dump_text
|
6
8
|
from fabricatio.journal import logger
|
7
9
|
from fabricatio.models.action import Action
|
8
10
|
from fabricatio.models.generic import FinalizedDumpAble, FromMapping, PersistentAble
|
9
11
|
from fabricatio.models.task import Task
|
12
|
+
from fabricatio.models.usages import LLMUsage
|
10
13
|
from fabricatio.utils import ok
|
11
14
|
|
12
15
|
|
13
|
-
class DumpFinalizedOutput(Action):
|
16
|
+
class DumpFinalizedOutput(Action, LLMUsage):
|
14
17
|
"""Dump the finalized output to a file."""
|
15
18
|
|
16
19
|
output_key: str = "dump_path"
|
@@ -38,7 +41,45 @@ class DumpFinalizedOutput(Action):
|
|
38
41
|
return dump_path.as_posix()
|
39
42
|
|
40
43
|
|
41
|
-
class
|
44
|
+
class RenderedDump(Action, LLMUsage):
|
45
|
+
"""Render the data to a file."""
|
46
|
+
|
47
|
+
output_key: str = "dump_path"
|
48
|
+
dump_path: Optional[str] = None
|
49
|
+
|
50
|
+
template_name: str
|
51
|
+
"""The template name to render the data."""
|
52
|
+
|
53
|
+
async def _execute(
|
54
|
+
self,
|
55
|
+
to_dump: FinalizedDumpAble,
|
56
|
+
task_input: Optional[Task] = None,
|
57
|
+
dump_path: Optional[str | Path] = None,
|
58
|
+
**_,
|
59
|
+
) -> str:
|
60
|
+
dump_path = Path(
|
61
|
+
dump_path
|
62
|
+
or self.dump_path
|
63
|
+
or ok(
|
64
|
+
await self.awhich_pathstr(
|
65
|
+
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."
|
66
|
+
),
|
67
|
+
"Could not find the path of file to dump the data.",
|
68
|
+
)
|
69
|
+
)
|
70
|
+
|
71
|
+
logger.info(f"Saving output to {dump_path.as_posix()}")
|
72
|
+
dump_text(
|
73
|
+
dump_path,
|
74
|
+
TEMPLATE_MANAGER.render_template(
|
75
|
+
self.template_name, {to_dump.__class__.__name__: to_dump.finalized_dump()}
|
76
|
+
),
|
77
|
+
)
|
78
|
+
|
79
|
+
return dump_path.as_posix()
|
80
|
+
|
81
|
+
|
82
|
+
class PersistentAll(Action, LLMUsage):
|
42
83
|
"""Persist all the data to a file."""
|
43
84
|
|
44
85
|
output_key: str = "persistent_count"
|