fabricatio 0.2.13.dev0__tar.gz → 0.2.13.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.13.dev0 → fabricatio-0.2.13.dev2}/PKG-INFO +5 -1
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/README.md +4 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/write_article/write_article.py +42 -9
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/pyproject.toml +1 -1
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/actions/article.py +49 -1
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/actions/article_rag.py +23 -59
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/capabilities/advanced_rag.py +5 -1
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/capabilities/rag.py +37 -5
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/config.py +8 -3
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/action.py +16 -3
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/adv_kwargs_types.py +4 -1
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/extra/aricle_rag.py +26 -11
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/extra/article_base.py +40 -7
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/extra/article_main.py +22 -33
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/extra/article_outline.py +1 -3
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/generic.py +3 -3
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/kwargs_types.py +9 -1
- fabricatio-0.2.13.dev2/python/fabricatio/utils.py +255 -0
- fabricatio-0.2.13.dev2/templates/built-in/chap_summary.hbs +31 -0
- fabricatio-0.2.13.dev2/templates.tar.gz +0 -0
- fabricatio-0.2.13.dev2/uv.lock +1706 -0
- fabricatio-0.2.13.dev0/python/fabricatio/utils.py +0 -94
- fabricatio-0.2.13.dev0/templates.tar.gz +0 -0
- fabricatio-0.2.13.dev0/uv.lock +0 -1709
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/.github/workflows/build-package.yaml +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/.github/workflows/ruff.yaml +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/.github/workflows/tests.yaml +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/.gitignore +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/.python-version +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/Cargo.lock +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/Cargo.toml +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/LICENSE +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/Makefile +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/correct/correct.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/correct/correct_loop.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/extract_and_inject/.gitignore +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/extract_and_inject/article_rag.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/extract_and_inject/ask.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/extract_and_inject/chunk_article.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/extract_and_inject/extract_and_inject.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/extract_article/extract.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/llm_usages/llm_usage.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/make_a_rating/rating.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/make_diary/commits.json +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/make_diary/diary.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/minor/hello_fabricatio.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/minor/write_a_poem.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/propose_task/.gitignore +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/propose_task/propose.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/reviewer/censor.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/reviewer/review.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/rules/.gitignore +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/rules/draft_ruleset.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/search_bibtex/.gitignore +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/search_bibtex/search.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/simple_chat/chat.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/simple_rag/simple_rag.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/task_handle/handle_task.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/write_article/.gitignore +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/write_article/article_rag.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/write_article/post_process.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/write_outline/.gitignore +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/write_outline/write_outline.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/examples/write_outline/write_outline_corrected.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/__init__.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/actions/__init__.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/actions/fs.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/actions/output.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/actions/rag.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/actions/rules.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/capabilities/__init__.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/capabilities/advanced_judge.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/capabilities/censor.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/capabilities/check.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/capabilities/correct.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/capabilities/extract.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/capabilities/propose.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/capabilities/rating.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/capabilities/review.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/capabilities/task.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/constants.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/core.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/decorators.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/fs/__init__.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/fs/curd.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/fs/readers.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/journal.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/events.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/extra/__init__.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/extra/advanced_judge.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/extra/article_essence.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/extra/article_proposal.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/extra/patches.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/extra/problem.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/extra/rag.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/extra/rule.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/role.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/task.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/tool.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/usages.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/parser.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/py.typed +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/rust.pyi +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/rust_instances.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/toolboxes/__init__.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/toolboxes/arithmetic.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/toolboxes/fs.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/workflows/__init__.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/workflows/articles.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/workflows/rag.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/src/bib_tools.rs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/src/hash.rs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/src/hbs_helpers.rs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/src/language.rs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/src/lib.rs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/src/templates.rs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/src/typst_tools.rs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/src/word_split.rs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/as_prompt.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/check_string.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/claude-xml.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/clean-up-code.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/co_validation.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/create_json_obj.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/dependencies.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/document-the-code.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/draft_rating_criteria.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/draft_rating_manual.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/draft_rating_weights_klee.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/draft_tool_usage_code.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/extract.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/extract_criteria_from_reasons.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/extract_reasons_from_examples.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/fix-bugs.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/fix_troubled_obj.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/fix_troubled_string.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/generic_string.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/improve-performance.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/liststr.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/make_choice.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/make_judgment.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/pathstr.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/rate_fine_grind.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/refactor.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/refined_query.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/retrieved_display.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/review_string.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/rule_requirement.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/ruleset_requirement_breakdown.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/task_briefing.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/web-ctf-solver.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/write-git-commit.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/write-github-pull-request.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/templates/built-in/write-github-readme.hbs +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/tests/test_config.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/tests/test_models/test_action.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/tests/test_models/test_advanced.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/tests/test_models/test_generic.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/tests/test_models/test_problem.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/tests/test_models/test_role.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/tests/test_models/test_task.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/tests/test_models/test_tool.py +0 -0
- {fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/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.13.
|
3
|
+
Version: 0.2.13.dev2
|
4
4
|
Classifier: License :: OSI Approved :: MIT License
|
5
5
|
Classifier: Programming Language :: Rust
|
6
6
|
Classifier: Programming Language :: Python :: 3.12
|
@@ -165,6 +165,10 @@ max_tokens = 8192
|
|
165
165
|
```bash
|
166
166
|
make test
|
167
167
|
```
|
168
|
+
## TODO
|
169
|
+
|
170
|
+
- Add an element based format strategy
|
171
|
+
|
168
172
|
|
169
173
|
## Contributing
|
170
174
|
|
@@ -2,12 +2,20 @@
|
|
2
2
|
|
3
3
|
import asyncio
|
4
4
|
from pathlib import Path
|
5
|
+
from typing import Optional
|
5
6
|
|
6
7
|
import typer
|
7
8
|
from fabricatio import Event, Role, WorkFlow, logger
|
8
|
-
from fabricatio.actions.article import
|
9
|
+
from fabricatio.actions.article import (
|
10
|
+
ExtractOutlineFromRaw,
|
11
|
+
GenerateArticleProposal,
|
12
|
+
GenerateInitialOutline,
|
13
|
+
WriteChapterSummary,
|
14
|
+
)
|
9
15
|
from fabricatio.actions.article_rag import ArticleConsultRAG, WriteArticleContentRAG
|
10
16
|
from fabricatio.actions.output import DumpFinalizedOutput, PersistentAll, RenderedDump
|
17
|
+
from fabricatio.fs import safe_text_read
|
18
|
+
from fabricatio.models.extra.article_main import Article
|
11
19
|
from fabricatio.models.extra.article_outline import ArticleOutline
|
12
20
|
from fabricatio.models.task import Task
|
13
21
|
from fabricatio.utils import ok
|
@@ -18,10 +26,9 @@ from typer import Typer
|
|
18
26
|
Role(
|
19
27
|
name="Undergraduate Researcher",
|
20
28
|
description="Write an outline for an article in typst format.",
|
21
|
-
llm_model="openai/
|
22
|
-
llm_temperature=0.45,
|
29
|
+
llm_model="openai/qwen3-235b-a22b",
|
23
30
|
# llm_api_endpoint=HttpUrl("https://dashscope.aliyuncs.com/compatible-mode/v1"),
|
24
|
-
|
31
|
+
llm_stream=True,
|
25
32
|
llm_max_tokens=8191,
|
26
33
|
llm_rpm=600,
|
27
34
|
llm_tpm=900000,
|
@@ -41,7 +48,7 @@ Role(
|
|
41
48
|
threshold=0.58,
|
42
49
|
result_per_query=2,
|
43
50
|
extractor_model={"model": "openai/qwen-max"},
|
44
|
-
query_model={"model": "openai/qwen-turbo"
|
51
|
+
query_model={"model": "openai/qwen-turbo"},
|
45
52
|
)
|
46
53
|
),
|
47
54
|
PersistentAll,
|
@@ -74,7 +81,12 @@ Role(
|
|
74
81
|
Event.quick_instantiate(ns4 := "consult"): WorkFlow(
|
75
82
|
name="Consult Article",
|
76
83
|
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(),),
|
84
|
+
steps=(ArticleConsultRAG(ref_q_model={"model": "openai/qwen-turbo"}).to_task_output(),),
|
85
|
+
),
|
86
|
+
Event.quick_instantiate(ns5 := "chap-suma"): WorkFlow(
|
87
|
+
name="Chapter Summary",
|
88
|
+
description="Generate chapter summary based on given article outline. dump the outline to the given path. in typst format.",
|
89
|
+
steps=(WriteChapterSummary().to_task_output(),),
|
78
90
|
),
|
79
91
|
},
|
80
92
|
)
|
@@ -86,13 +98,12 @@ app = Typer()
|
|
86
98
|
@app.command()
|
87
99
|
def consult(
|
88
100
|
collection_name: str = typer.Option("article_chunks", "-c", "--collection-name", help="Name of the collection."),
|
101
|
+
tei_endpoint: Optional[str] = typer.Option(None, "-t", "--tei-endpoint", help="TEI endpoint."),
|
89
102
|
) -> None:
|
90
103
|
"""Consult an article based on a given article outline."""
|
91
104
|
_ = asyncio.run(
|
92
105
|
Task(name="Answer Question")
|
93
|
-
.update_init_context(
|
94
|
-
collection_name=collection_name,
|
95
|
-
)
|
106
|
+
.update_init_context(collection_name=collection_name, tei_endpoint=tei_endpoint)
|
96
107
|
.delegate(ns4)
|
97
108
|
)
|
98
109
|
|
@@ -193,5 +204,27 @@ def write(
|
|
193
204
|
logger.success(f"The outline is saved in:\n{path}")
|
194
205
|
|
195
206
|
|
207
|
+
@app.command()
|
208
|
+
def suma(
|
209
|
+
article_path: Path = typer.Option( # noqa: B008
|
210
|
+
Path("article.typ"), "-a", "--article-path", help="Path to the article file."
|
211
|
+
),
|
212
|
+
dump_path: Path = typer.Option(Path("out.typ"), "-d", "--dump-path", help="Path to dump the final output."), # noqa: B008
|
213
|
+
) -> None:
|
214
|
+
"""Write chap summary based on given article."""
|
215
|
+
path = ok(
|
216
|
+
asyncio.run(
|
217
|
+
Task(name="write an article")
|
218
|
+
.update_init_context(
|
219
|
+
article=Article.from_typst_code("article", body=safe_text_read(article_path)),
|
220
|
+
write_to=dump_path,
|
221
|
+
)
|
222
|
+
.delegate(ns5)
|
223
|
+
),
|
224
|
+
"Failed to generate an article ",
|
225
|
+
)
|
226
|
+
logger.success(f"The outline is saved in:\n{path}")
|
227
|
+
|
228
|
+
|
196
229
|
if __name__ == "__main__":
|
197
230
|
app()
|
@@ -8,10 +8,12 @@ from more_itertools import filter_map
|
|
8
8
|
from pydantic import Field
|
9
9
|
from rich import print as r_print
|
10
10
|
|
11
|
+
from fabricatio import TEMPLATE_MANAGER
|
11
12
|
from fabricatio.capabilities.censor import Censor
|
12
13
|
from fabricatio.capabilities.extract import Extract
|
13
14
|
from fabricatio.capabilities.propose import Propose
|
14
|
-
from fabricatio.
|
15
|
+
from fabricatio.config import configs
|
16
|
+
from fabricatio.fs import dump_text, safe_text_read
|
15
17
|
from fabricatio.journal import logger
|
16
18
|
from fabricatio.models.action import Action
|
17
19
|
from fabricatio.models.extra.article_essence import ArticleEssence
|
@@ -21,6 +23,7 @@ from fabricatio.models.extra.article_proposal import ArticleProposal
|
|
21
23
|
from fabricatio.models.extra.rule import RuleSet
|
22
24
|
from fabricatio.models.kwargs_types import ValidateKwargs
|
23
25
|
from fabricatio.models.task import Task
|
26
|
+
from fabricatio.models.usages import LLMUsage
|
24
27
|
from fabricatio.rust import BibManager, detect_language
|
25
28
|
from fabricatio.utils import ok, wrapp_in_block
|
26
29
|
|
@@ -271,3 +274,48 @@ class LoadArticle(Action):
|
|
271
274
|
|
272
275
|
async def _execute(self, article_outline: ArticleOutline, typst_code: str, **cxt) -> Article:
|
273
276
|
return Article.from_mixed_source(article_outline, typst_code)
|
277
|
+
|
278
|
+
|
279
|
+
class WriteChapterSummary(Action, LLMUsage):
|
280
|
+
"""Write the chapter summary."""
|
281
|
+
|
282
|
+
output_key: str = "chapter_summaries"
|
283
|
+
|
284
|
+
paragraph_count: int = 1
|
285
|
+
|
286
|
+
summary_word_count: int = 200
|
287
|
+
|
288
|
+
summary_title: str = "Chapter Summary"
|
289
|
+
write_to: Optional[Path] = None
|
290
|
+
|
291
|
+
async def _execute(self, article: Article, write_to: Optional[Path] = None, **cxt) -> List[str]:
|
292
|
+
logger.info(";".join(a.title for a in article.chapters))
|
293
|
+
|
294
|
+
ret = [
|
295
|
+
f"== {self.summary_title}\n{raw}"
|
296
|
+
for raw in (
|
297
|
+
await self.aask(
|
298
|
+
TEMPLATE_MANAGER.render_template(
|
299
|
+
configs.templates.chap_summary_template,
|
300
|
+
[
|
301
|
+
{
|
302
|
+
"chapter": a.to_typst_code(),
|
303
|
+
"title": a.title,
|
304
|
+
"language": a.language,
|
305
|
+
"summary_word_count": self.summary_word_count,
|
306
|
+
"paragraph_count": self.paragraph_count,
|
307
|
+
}
|
308
|
+
for a in article.chapters
|
309
|
+
],
|
310
|
+
)
|
311
|
+
)
|
312
|
+
)
|
313
|
+
]
|
314
|
+
|
315
|
+
if (to := (self.write_to or write_to)) is not None:
|
316
|
+
dump_text(
|
317
|
+
to,
|
318
|
+
"\n\n\n".join(f"//{a.title}\n\n{s}" for a, s in zip(article.chapters, ret, strict=True)),
|
319
|
+
)
|
320
|
+
|
321
|
+
return ret
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
from asyncio import gather
|
4
4
|
from pathlib import Path
|
5
|
-
from typing import List, Optional
|
5
|
+
from typing import ClassVar, List, Optional
|
6
6
|
|
7
7
|
from pydantic import Field, PositiveInt
|
8
8
|
|
@@ -21,17 +21,17 @@ from fabricatio.models.extra.article_outline import ArticleOutline
|
|
21
21
|
from fabricatio.models.extra.rule import RuleSet
|
22
22
|
from fabricatio.models.kwargs_types import ChooseKwargs, LLMKwargs
|
23
23
|
from fabricatio.rust import convert_to_block_formula, convert_to_inline_formula
|
24
|
-
from fabricatio.utils import
|
24
|
+
from fabricatio.utils import ok
|
25
25
|
|
26
26
|
TYPST_CITE_USAGE = (
|
27
|
-
"citation number is REQUIRED to cite any reference
|
28
|
-
"Everything is build upon the typst language, which is similar to latex, \n"
|
27
|
+
"citation number is REQUIRED to cite any reference!'\n"
|
29
28
|
"Legal citing syntax examples(seperated by |): [[1]]|[[1,2]]|[[1-3]]|[[12,13-15]]|[[1-3,5-7]]\n"
|
30
29
|
"Illegal citing syntax examples(seperated by |): [[1],[2],[3]]|[[1],[1-2]]\n"
|
30
|
+
"You SHALL not cite a single reference more than once!"
|
31
31
|
"Those reference mark shall not be omitted during the extraction\n"
|
32
32
|
"It's recommended to cite multiple references that supports your conclusion at a time.\n"
|
33
33
|
"Wrap inline expression with '\\(' and '\\)',like '\\(>5m\\)' '\\(89%\\)', and wrap block equation with '\\[' and '\\]'.\n"
|
34
|
-
"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
|
+
"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 and should never be written within the formula block.\n"
|
35
35
|
"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."
|
36
36
|
"Below is two usage example:\n"
|
37
37
|
"```typst\n"
|
@@ -47,6 +47,7 @@ TYPST_CITE_USAGE = (
|
|
47
47
|
class WriteArticleContentRAG(Action, RAG, Extract):
|
48
48
|
"""Write an article based on the provided outline."""
|
49
49
|
|
50
|
+
ctx_override: ClassVar[bool] = True
|
50
51
|
search_increment_multiplier: float = 1.6
|
51
52
|
"""The increment multiplier of the search increment."""
|
52
53
|
ref_limit: int = 35
|
@@ -63,6 +64,7 @@ class WriteArticleContentRAG(Action, RAG, Extract):
|
|
63
64
|
"""The number of results to be returned per query."""
|
64
65
|
req: str = TYPST_CITE_USAGE
|
65
66
|
"""The req of the write article content."""
|
67
|
+
tei_endpoint: Optional[str] = None
|
66
68
|
|
67
69
|
async def _execute(
|
68
70
|
self,
|
@@ -108,16 +110,7 @@ class WriteArticleContentRAG(Action, RAG, Extract):
|
|
108
110
|
|
109
111
|
while not await confirm("Accept this version and continue?").ask_async():
|
110
112
|
if inst := await text("Search for more refs for additional spec.").ask_async():
|
111
|
-
await self.search_database(
|
112
|
-
article,
|
113
|
-
article_outline,
|
114
|
-
chap,
|
115
|
-
sec,
|
116
|
-
subsec,
|
117
|
-
cm,
|
118
|
-
supervisor=True,
|
119
|
-
extra_instruction=inst,
|
120
|
-
)
|
113
|
+
await self.search_database(article, article_outline, chap, sec, subsec, cm, extra_instruction=inst)
|
121
114
|
|
122
115
|
if instruction := await text("Enter the instructions to improve").ask_async():
|
123
116
|
raw = await self.write_raw(article, article_outline, chap, sec, subsec, cm, instruction)
|
@@ -200,7 +193,6 @@ class WriteArticleContentRAG(Action, RAG, Extract):
|
|
200
193
|
subsec: ArticleSubsection,
|
201
194
|
cm: CitationManager,
|
202
195
|
extra_instruction: str = "",
|
203
|
-
supervisor: bool = False,
|
204
196
|
) -> None:
|
205
197
|
"""Search database for related references."""
|
206
198
|
search_req = (
|
@@ -208,61 +200,31 @@ class WriteArticleContentRAG(Action, RAG, Extract):
|
|
208
200
|
f"More specifically, i m witting the Chapter `{chap.title}` >> Section `{sec.title}` >> Subsection `{subsec.title}`.\n"
|
209
201
|
f"I need to search related references to build up the content of the subsec mentioned above, which is `{subsec.title}`.\n"
|
210
202
|
f"provide 10~16 queries as possible, to get best result!\n"
|
211
|
-
f"You should provide both English version and chinese version of the refined queries!\n{extra_instruction}
|
203
|
+
f"You should provide both English version and chinese version of the refined queries!\n{extra_instruction}"
|
212
204
|
)
|
213
205
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
ref_q = await ask_retain(ref_q)
|
224
|
-
ret = await self.aretrieve(
|
225
|
-
ref_q,
|
226
|
-
ArticleChunk,
|
227
|
-
max_accepted=self.ref_limit,
|
228
|
-
result_per_query=self.result_per_query,
|
229
|
-
similarity_threshold=self.threshold,
|
230
|
-
)
|
231
|
-
|
232
|
-
cm.add_chunks(ok(ret))
|
233
|
-
ref_q = await self.arefined_query(
|
234
|
-
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}",
|
235
|
-
**self.query_model,
|
236
|
-
)
|
237
|
-
|
238
|
-
if ref_q is None:
|
239
|
-
logger.warning("Second refine query is None, skipping.")
|
240
|
-
return
|
241
|
-
if supervisor:
|
242
|
-
ref_q = await ask_retain(ref_q)
|
243
|
-
|
244
|
-
ret = await self.aretrieve(
|
245
|
-
ref_q,
|
246
|
-
ArticleChunk,
|
247
|
-
max_accepted=int(self.ref_limit * self.search_increment_multiplier),
|
248
|
-
result_per_query=int(self.result_per_query * self.search_increment_multiplier),
|
249
|
-
similarity_threshold=self.threshold,
|
206
|
+
await self.clued_search(
|
207
|
+
search_req,
|
208
|
+
cm,
|
209
|
+
refinery_kwargs=self.ref_q_model,
|
210
|
+
expand_multiplier=self.search_increment_multiplier,
|
211
|
+
base_accepted=self.ref_limit,
|
212
|
+
result_per_query=self.ref_per_q,
|
213
|
+
similarity_threshold=self.similarity_threshold,
|
214
|
+
tei_endpoint=self.tei_endpoint,
|
250
215
|
)
|
251
|
-
if ret is None:
|
252
|
-
logger.warning("Second retrieve is None, skipping.")
|
253
|
-
return
|
254
|
-
cm.add_chunks(ret)
|
255
216
|
|
256
217
|
|
257
218
|
class ArticleConsultRAG(Action, AdvancedRAG):
|
258
219
|
"""Write an article based on the provided outline."""
|
259
220
|
|
221
|
+
ctx_override: ClassVar[bool] = True
|
260
222
|
output_key: str = "consult_count"
|
261
223
|
search_increment_multiplier: float = 1.6
|
262
224
|
"""The multiplier to increase the limit of references to retrieve per query."""
|
263
|
-
ref_limit: int =
|
225
|
+
ref_limit: int = 26
|
264
226
|
"""The final limit of references."""
|
265
|
-
ref_per_q: int =
|
227
|
+
ref_per_q: int = 13
|
266
228
|
"""The limit of references to retrieve per query."""
|
267
229
|
similarity_threshold: float = 0.62
|
268
230
|
"""The similarity threshold of references to retrieve."""
|
@@ -270,6 +232,7 @@ class ArticleConsultRAG(Action, AdvancedRAG):
|
|
270
232
|
"""The model to use for refining query."""
|
271
233
|
req: str = TYPST_CITE_USAGE
|
272
234
|
"""The request for the rag model."""
|
235
|
+
tei_endpoint: Optional[str] = None
|
273
236
|
|
274
237
|
@precheck_package(
|
275
238
|
"questionary", "`questionary` is required for supervisor mode, please install it by `fabricatio[qa]`"
|
@@ -300,6 +263,7 @@ class ArticleConsultRAG(Action, AdvancedRAG):
|
|
300
263
|
base_accepted=self.ref_limit,
|
301
264
|
result_per_query=self.ref_per_q,
|
302
265
|
similarity_threshold=self.similarity_threshold,
|
266
|
+
tei_endpoint=self.tei_endpoint,
|
303
267
|
)
|
304
268
|
|
305
269
|
ret = await self.aask(f"{cm.as_prompt()}\n{self.req}\n{req}")
|
{fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/capabilities/advanced_rag.py
RENAMED
@@ -7,6 +7,7 @@ from fabricatio.journal import logger
|
|
7
7
|
from fabricatio.models.adv_kwargs_types import FetchKwargs
|
8
8
|
from fabricatio.models.extra.aricle_rag import ArticleChunk, CitationManager
|
9
9
|
from fabricatio.models.kwargs_types import ChooseKwargs
|
10
|
+
from fabricatio.utils import fallback_kwargs
|
10
11
|
|
11
12
|
|
12
13
|
class AdvancedRAG(RAG):
|
@@ -40,10 +41,13 @@ class AdvancedRAG(RAG):
|
|
40
41
|
f"\n\n{requirement}",
|
41
42
|
**refinery_kwargs,
|
42
43
|
)
|
44
|
+
|
43
45
|
if ref_q is None:
|
44
46
|
logger.error(f"At round [{i}/{max_round}] search, failed to refine the query, exit.")
|
45
47
|
return cm
|
46
|
-
refs = await self.aretrieve(
|
48
|
+
refs = await self.aretrieve(
|
49
|
+
ref_q, ArticleChunk, base_accepted, **fallback_kwargs(kwargs, filter_expr=cm.as_milvus_filter_expr())
|
50
|
+
)
|
47
51
|
|
48
52
|
if (max_capacity := max_capacity - len(refs)) < 0:
|
49
53
|
cm.add_chunks(refs[0:max_capacity])
|
@@ -143,21 +143,27 @@ class RAG(EmbeddingUsage):
|
|
143
143
|
|
144
144
|
async def afetch_document[D: MilvusDataBase](
|
145
145
|
self,
|
146
|
-
|
146
|
+
query: List[str],
|
147
147
|
document_model: Type[D],
|
148
148
|
collection_name: Optional[str] = None,
|
149
149
|
similarity_threshold: float = 0.37,
|
150
150
|
result_per_query: int = 10,
|
151
|
+
tei_endpoint: Optional[str] = None,
|
152
|
+
reranker_threshold: float = 0.7,
|
153
|
+
filter_expr: str = "",
|
151
154
|
) -> List[D]:
|
152
155
|
"""Asynchronously fetches documents from a Milvus database based on input vectors.
|
153
156
|
|
154
157
|
Args:
|
155
|
-
|
158
|
+
query (List[str]): A list of vectors to search for in the database.
|
156
159
|
document_model (Type[D]): The model class used to convert fetched data into document objects.
|
157
160
|
collection_name (Optional[str]): The name of the collection to search within.
|
158
161
|
If None, the currently viewed collection is used.
|
159
162
|
similarity_threshold (float): The similarity threshold for vector search. Defaults to 0.37.
|
160
163
|
result_per_query (int): The maximum number of results to return per query. Defaults to 10.
|
164
|
+
tei_endpoint (str): the endpoint of the TEI api.
|
165
|
+
reranker_threshold (float): The threshold used to filtered low relativity document.
|
166
|
+
filter_expr (str): filter_expression parsed into pymilvus search.
|
161
167
|
|
162
168
|
Returns:
|
163
169
|
List[D]: A list of document objects created from the fetched data.
|
@@ -165,15 +171,38 @@ class RAG(EmbeddingUsage):
|
|
165
171
|
# Step 1: Search for vectors
|
166
172
|
search_results = self.check_client().client.search(
|
167
173
|
collection_name or self.safe_target_collection,
|
168
|
-
|
174
|
+
await self.vectorize(query),
|
169
175
|
search_params={"radius": similarity_threshold},
|
170
176
|
output_fields=list(document_model.model_fields),
|
177
|
+
filter=filter_expr,
|
171
178
|
limit=result_per_query,
|
172
179
|
)
|
180
|
+
if tei_endpoint is not None:
|
181
|
+
from fabricatio.utils import RerankerAPI
|
182
|
+
|
183
|
+
reranker = RerankerAPI(base_url=tei_endpoint)
|
184
|
+
|
185
|
+
retrieved_id = set()
|
186
|
+
raw_result = []
|
187
|
+
|
188
|
+
for q, g in zip(query, search_results, strict=True):
|
189
|
+
models = document_model.from_sequence([res["entity"] for res in g if res["id"] not in retrieved_id])
|
190
|
+
logger.debug(f"Retrived {len(g)} raw document, filtered out {len(models)}.")
|
191
|
+
retrieved_id.update(res["id"] for res in g)
|
192
|
+
if not models:
|
193
|
+
continue
|
194
|
+
rank_scores = await reranker.arerank(q, [m.prepare_vectorization() for m in models], truncate=True)
|
195
|
+
raw_result.extend(
|
196
|
+
(models[s["index"]], s["score"]) for s in rank_scores if s["score"] > reranker_threshold
|
197
|
+
)
|
198
|
+
|
199
|
+
raw_result_sorted = sorted(raw_result, key=lambda x: x[1], reverse=True)
|
200
|
+
return [r[0] for r in raw_result_sorted]
|
173
201
|
|
174
202
|
# Step 2: Flatten the search results
|
175
203
|
flattened_results = flatten(search_results)
|
176
204
|
unique_results = unique(flattened_results, key=itemgetter("id"))
|
205
|
+
|
177
206
|
# Step 3: Sort by distance (descending)
|
178
207
|
sorted_results = sorted(unique_results, key=itemgetter("distance"), reverse=True)
|
179
208
|
|
@@ -205,15 +234,18 @@ class RAG(EmbeddingUsage):
|
|
205
234
|
"""
|
206
235
|
if isinstance(query, str):
|
207
236
|
query = [query]
|
237
|
+
|
208
238
|
return (
|
209
239
|
await self.afetch_document(
|
210
|
-
|
240
|
+
query=query,
|
211
241
|
document_model=document_model,
|
212
242
|
**kwargs,
|
213
243
|
)
|
214
244
|
)[:max_accepted]
|
215
245
|
|
216
|
-
async def arefined_query(
|
246
|
+
async def arefined_query(
|
247
|
+
self, question: List[str] | str, **kwargs: Unpack[ChooseKwargs[Optional[List[str]]]]
|
248
|
+
) -> Optional[List[str]]:
|
217
249
|
"""Refines the given question using a template.
|
218
250
|
|
219
251
|
Args:
|
@@ -86,10 +86,12 @@ class LLMConfig(BaseModel):
|
|
86
86
|
|
87
87
|
tpm: Optional[PositiveInt] = Field(default=1000000)
|
88
88
|
"""The rate limit of the LLM model in tokens per minute. None means not checked."""
|
89
|
-
presence_penalty:Optional[PositiveFloat]=None
|
89
|
+
presence_penalty: Optional[PositiveFloat] = None
|
90
90
|
"""The presence penalty of the LLM model."""
|
91
|
-
frequency_penalty:Optional[PositiveFloat]=None
|
91
|
+
frequency_penalty: Optional[PositiveFloat] = None
|
92
92
|
"""The frequency penalty of the LLM model."""
|
93
|
+
|
94
|
+
|
93
95
|
class EmbeddingConfig(BaseModel):
|
94
96
|
"""Embedding configuration class."""
|
95
97
|
|
@@ -252,10 +254,13 @@ class TemplateConfig(BaseModel):
|
|
252
254
|
rule_requirement_template: str = Field(default="rule_requirement")
|
253
255
|
"""The name of the rule requirement template which will be used to generate a rule requirement."""
|
254
256
|
|
255
|
-
|
256
257
|
extract_template: str = Field(default="extract")
|
257
258
|
"""The name of the extract template which will be used to extract model from string."""
|
258
259
|
|
260
|
+
chap_summary_template: str = Field(default="chap_summary")
|
261
|
+
"""The name of the chap summary template which will be used to generate a chapter summary."""
|
262
|
+
|
263
|
+
|
259
264
|
class MagikaConfig(BaseModel):
|
260
265
|
"""Magika configuration class."""
|
261
266
|
|
@@ -12,7 +12,7 @@ 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, Sequence, Tuple, Type, Union, final
|
15
|
+
from typing import Any, ClassVar, Dict, Self, Sequence, Tuple, Type, Union, final
|
16
16
|
|
17
17
|
from fabricatio.journal import logger
|
18
18
|
from fabricatio.models.generic import WithBriefing
|
@@ -33,6 +33,9 @@ class Action(WithBriefing):
|
|
33
33
|
a specific operation and can modify the shared context data.
|
34
34
|
"""
|
35
35
|
|
36
|
+
ctx_override: ClassVar[bool] = False
|
37
|
+
"""Whether to override the instance attr by the context variable."""
|
38
|
+
|
36
39
|
name: str = Field(default="")
|
37
40
|
"""The name of the action."""
|
38
41
|
|
@@ -157,6 +160,15 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
|
|
157
160
|
action.personality = personality
|
158
161
|
return self
|
159
162
|
|
163
|
+
def override_action_variable(self, action: Action, ctx: Dict[str, Any]) -> Self:
|
164
|
+
"""Override action variable with context values."""
|
165
|
+
if action.ctx_override:
|
166
|
+
for k, v in ctx.items():
|
167
|
+
if hasattr(action, k):
|
168
|
+
setattr(action, k, v)
|
169
|
+
|
170
|
+
return self
|
171
|
+
|
160
172
|
async def serve(self, task: Task) -> None:
|
161
173
|
"""Execute workflow to complete given task.
|
162
174
|
|
@@ -178,11 +190,12 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
|
|
178
190
|
try:
|
179
191
|
# Process each action in sequence
|
180
192
|
for i, step in enumerate(self._instances):
|
181
|
-
current_action
|
182
|
-
logger.info(f"Executing step [{i}] >> {current_action}")
|
193
|
+
logger.info(f"Executing step [{i}] >> {(current_action := step.name)}")
|
183
194
|
|
184
195
|
# Get current context and execute action
|
185
196
|
context = await self._context.get()
|
197
|
+
|
198
|
+
self.override_action_variable(step, context)
|
186
199
|
act_task = create_task(step.act(context))
|
187
200
|
# Handle task cancellation
|
188
201
|
if task.is_cancelled():
|
{fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/adv_kwargs_types.py
RENAMED
@@ -1,7 +1,7 @@
|
|
1
1
|
"""A module containing kwargs types for content correction and checking operations."""
|
2
2
|
|
3
3
|
from importlib.util import find_spec
|
4
|
-
from typing import NotRequired, TypedDict
|
4
|
+
from typing import NotRequired, Optional, TypedDict
|
5
5
|
|
6
6
|
from fabricatio.models.extra.problem import Improvement
|
7
7
|
from fabricatio.models.extra.rule import RuleSet
|
@@ -58,3 +58,6 @@ if find_spec("pymilvus"):
|
|
58
58
|
collection_name: NotRequired[str | None]
|
59
59
|
similarity_threshold: NotRequired[float]
|
60
60
|
result_per_query: NotRequired[int]
|
61
|
+
tei_endpoint: NotRequired[Optional[str]]
|
62
|
+
reranker_threshold: NotRequired[float]
|
63
|
+
filter_expr: NotRequired[str]
|
{fabricatio-0.2.13.dev0 → fabricatio-0.2.13.dev2}/python/fabricatio/models/extra/aricle_rag.py
RENAMED
@@ -1,6 +1,7 @@
|
|
1
1
|
"""A Module containing the article rag models."""
|
2
2
|
|
3
3
|
import re
|
4
|
+
from itertools import groupby
|
4
5
|
from pathlib import Path
|
5
6
|
from typing import ClassVar, Dict, List, Optional, Self, Unpack
|
6
7
|
|
@@ -10,12 +11,13 @@ from fabricatio.models.extra.rag import MilvusDataBase
|
|
10
11
|
from fabricatio.models.generic import AsPrompt
|
11
12
|
from fabricatio.models.kwargs_types import ChunkKwargs
|
12
13
|
from fabricatio.rust import BibManager, blake3_hash, split_into_chunks
|
13
|
-
from fabricatio.utils import ok
|
14
|
+
from fabricatio.utils import ok, wrapp_in_block
|
15
|
+
from more_itertools.more import first
|
14
16
|
from more_itertools.recipes import flatten, unique
|
15
17
|
from pydantic import Field
|
16
18
|
|
17
19
|
|
18
|
-
class ArticleChunk(MilvusDataBase
|
20
|
+
class ArticleChunk(MilvusDataBase):
|
19
21
|
"""The chunk of an article."""
|
20
22
|
|
21
23
|
etc_word: ClassVar[str] = "等"
|
@@ -51,10 +53,9 @@ class ArticleChunk(MilvusDataBase, AsPrompt):
|
|
51
53
|
bibtex_cite_key: str
|
52
54
|
"""The bibtex cite key of the article"""
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
}
|
56
|
+
@property
|
57
|
+
def reference_header(self) -> str:
|
58
|
+
return f"[[{ok(self._cite_number, 'You need to update cite number first.')}]] reference `{self.article_title}` from {self.as_auther_seq()}"
|
58
59
|
|
59
60
|
@property
|
60
61
|
def cite_number(self) -> int:
|
@@ -204,13 +205,23 @@ class CitationManager(AsPrompt):
|
|
204
205
|
|
205
206
|
def set_cite_number_all(self) -> Self:
|
206
207
|
"""Set citation numbers for all article chunks."""
|
207
|
-
|
208
|
-
|
208
|
+
number_mapping = {a.bibtex_cite_key: 0 for a in self.article_chunks}
|
209
|
+
|
210
|
+
for i, k in enumerate(number_mapping.keys()):
|
211
|
+
number_mapping[k] = i
|
212
|
+
|
213
|
+
for a in self.article_chunks:
|
214
|
+
a.update_cite_number(number_mapping[a.bibtex_cite_key])
|
209
215
|
return self
|
210
216
|
|
211
217
|
def _as_prompt_inner(self) -> Dict[str, str]:
|
212
218
|
"""Generate prompt inner representation."""
|
213
|
-
|
219
|
+
seg = []
|
220
|
+
for k, g in groupby(self.article_chunks, key=lambda a: a.bibtex_cite_key):
|
221
|
+
g = list(g)
|
222
|
+
logger.debug(f"Group [{k}]: {len(g)}")
|
223
|
+
seg.append(wrapp_in_block("\n\n".join(a.chunk for a in g), first(g).reference_header))
|
224
|
+
return {"References": "\n".join(seg)}
|
214
225
|
|
215
226
|
def apply(self, string: str) -> str:
|
216
227
|
"""Apply citation replacements to the input string."""
|
@@ -261,5 +272,9 @@ class CitationManager(AsPrompt):
|
|
261
272
|
|
262
273
|
def unpack_cite_seq(self, citation_seq: List[int]) -> str:
|
263
274
|
"""Unpack citation sequence into a string."""
|
264
|
-
chunk_seq =
|
265
|
-
return "".join(a.as_typst_cite() for a in chunk_seq)
|
275
|
+
chunk_seq = {a.bibtex_cite_key: a for a in self.article_chunks if a.cite_number in citation_seq}
|
276
|
+
return "".join(a.as_typst_cite() for a in chunk_seq.values())
|
277
|
+
|
278
|
+
def as_milvus_filter_expr(self, blacklist: bool = True) -> str:
|
279
|
+
if blacklist:
|
280
|
+
return " and ".join(f'bibtex_cite_key != "{a.bibtex_cite_key}"' for a in self.article_chunks)
|