fabricatio 0.2.7.dev0__tar.gz → 0.2.7.dev1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/.gitignore +1 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/PKG-INFO +6 -2
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/extract_and_inject/extract_and_inject.py +1 -2
- fabricatio-0.2.7.dev1/examples/write_outline/.gitignore +2 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/pyproject.toml +11 -2
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/_rust.pyi +11 -2
- fabricatio-0.2.7.dev1/python/fabricatio/actions/article.py +158 -0
- fabricatio-0.2.7.dev1/python/fabricatio/actions/output.py +34 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/capabilities/correct.py +34 -4
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/capabilities/rag.py +41 -5
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/capabilities/rating.py +4 -4
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/capabilities/task.py +2 -2
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/config.py +3 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/models/extra.py +285 -258
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/models/generic.py +60 -9
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/models/kwargs_types.py +20 -2
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/models/usages.py +45 -37
- fabricatio-0.2.7.dev1/src/templates.rs +111 -0
- fabricatio-0.2.7.dev1/templates/built-in/as_prompt.hbs +3 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/refined_query.hbs +15 -4
- fabricatio-0.2.7.dev1/templates.tar.gz +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/uv.lock +136 -3
- fabricatio-0.2.7.dev0/python/fabricatio/actions/article.py +0 -131
- fabricatio-0.2.7.dev0/python/fabricatio/actions/output.py +0 -19
- fabricatio-0.2.7.dev0/src/templates.rs +0 -104
- fabricatio-0.2.7.dev0/templates.tar.gz +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/.github/workflows/build-package.yaml +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/.github/workflows/ruff.yaml +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/.github/workflows/tests.yaml +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/.python-version +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/Cargo.lock +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/Cargo.toml +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/LICENSE +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/Makefile +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/README.md +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/correct/correct.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/correct/correct_loop.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/extract_and_inject/.gitignore +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/extract_and_inject/article_rag.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/extract_article/extract.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/llm_usages/llm_usage.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/make_a_rating/rating.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/make_diary/commits.json +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/make_diary/diary.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/minor/hello_fabricatio.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/minor/write_a_poem.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/propose_task/propose.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/reviewer/review.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/search_bibtex/.gitignore +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/search_bibtex/search.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/simple_chat/chat.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/simple_rag/simple_rag.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/task_handle/handle_task.py +0 -0
- {fabricatio-0.2.7.dev0/examples/write_outline → fabricatio-0.2.7.dev1/examples/write_article}/.gitignore +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/write_outline/write_outline.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/write_outline/write_outline_corrected.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/__init__.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/_rust_instances.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/actions/rag.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/capabilities/propose.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/capabilities/review.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/core.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/decorators.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/fs/__init__.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/fs/curd.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/fs/readers.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/journal.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/models/action.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/models/events.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/models/role.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/models/task.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/models/tool.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/models/utils.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/parser.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/py.typed +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/toolboxes/__init__.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/toolboxes/arithmetic.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/toolboxes/fs.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/workflows/articles.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/python/fabricatio/workflows/rag.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/src/bib_tools.rs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/src/hash.rs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/src/hbs_helpers.rs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/src/lib.rs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/claude-xml.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/clean-up-code.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/co_validation.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/correct.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/create_json_obj.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/dependencies.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/document-the-code.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/draft_rating_criteria.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/draft_rating_manual.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/draft_rating_weights_klee.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/draft_tool_usage_code.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/extract_criteria_from_reasons.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/extract_reasons_from_examples.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/fix-bugs.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/generic_string.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/improve-performance.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/liststr.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/make_choice.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/make_judgment.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/pathstr.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/rate_fine_grind.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/refactor.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/retrieved_display.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/review_string.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/task_briefing.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/web-ctf-solver.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/write-git-commit.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/write-github-pull-request.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/templates/built-in/write-github-readme.hbs +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/tests/test_config.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/tests/test_models/test_action.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/tests/test_models/test_advanced.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/tests/test_models/test_generic.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/tests/test_models/test_role.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/tests/test_models/test_task.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/tests/test_models/test_tool.py +0 -0
- {fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/tests/test_models/test_usages.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: fabricatio
|
3
|
-
Version: 0.2.7.
|
3
|
+
Version: 0.2.7.dev1
|
4
4
|
Classifier: License :: OSI Approved :: MIT License
|
5
5
|
Classifier: Programming Language :: Rust
|
6
6
|
Classifier: Programming Language :: Python :: 3.12
|
@@ -24,9 +24,13 @@ Requires-Dist: questionary>=2.1.0
|
|
24
24
|
Requires-Dist: regex>=2024.11.6
|
25
25
|
Requires-Dist: rich>=13.9.4
|
26
26
|
Requires-Dist: pymilvus>=2.5.4 ; extra == 'rag'
|
27
|
-
Requires-Dist: fabricatio[rag] ; extra == 'full'
|
27
|
+
Requires-Dist: fabricatio[calc,plot,rag] ; extra == 'full'
|
28
|
+
Requires-Dist: sympy>=1.13.3 ; extra == 'calc'
|
29
|
+
Requires-Dist: matplotlib>=3.10.1 ; extra == 'plot'
|
28
30
|
Provides-Extra: rag
|
29
31
|
Provides-Extra: full
|
32
|
+
Provides-Extra: calc
|
33
|
+
Provides-Extra: plot
|
30
34
|
License-File: LICENSE
|
31
35
|
Summary: A LLM multi-agent framework.
|
32
36
|
Keywords: ai,agents,multi-agent,llm,pyo3
|
{fabricatio-0.2.7.dev0 → fabricatio-0.2.7.dev1}/examples/extract_and_inject/extract_and_inject.py
RENAMED
@@ -4,14 +4,13 @@ import asyncio
|
|
4
4
|
from pathlib import Path
|
5
5
|
from typing import List, Optional
|
6
6
|
|
7
|
-
from pydantic import HttpUrl
|
8
|
-
|
9
7
|
from fabricatio import Action, Event, Role, Task, WorkFlow, logger
|
10
8
|
from fabricatio.actions.article import ExtractArticleEssence
|
11
9
|
from fabricatio.actions.rag import InjectToDB
|
12
10
|
from fabricatio.fs.curd import dump_text, gather_files
|
13
11
|
from fabricatio.models.extra import ArticleEssence
|
14
12
|
from fabricatio.models.utils import ok
|
13
|
+
from pydantic import HttpUrl
|
15
14
|
|
16
15
|
|
17
16
|
class SaveToFS(Action):
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[project]
|
2
2
|
name = "fabricatio"
|
3
|
-
version = "0.2.7-
|
3
|
+
version = "0.2.7-dev1"
|
4
4
|
description = "A LLM multi-agent framework."
|
5
5
|
readme = "README.md"
|
6
6
|
license = { file = "LICENSE" }
|
@@ -81,7 +81,13 @@ rag = [
|
|
81
81
|
]
|
82
82
|
|
83
83
|
full = [
|
84
|
-
"fabricatio[rag]",
|
84
|
+
"fabricatio[calc,plot,rag]",
|
85
|
+
]
|
86
|
+
calc = [
|
87
|
+
"sympy>=1.13.3",
|
88
|
+
]
|
89
|
+
plot = [
|
90
|
+
"matplotlib>=3.10.1",
|
85
91
|
]
|
86
92
|
|
87
93
|
[tool.ruff]
|
@@ -140,6 +146,9 @@ testpaths = [
|
|
140
146
|
asyncio_mode = "auto"
|
141
147
|
asyncio_default_fixture_loop_scope = "function"
|
142
148
|
|
149
|
+
[tool.uv.sources]
|
150
|
+
fabricatio = { workspace = true }
|
151
|
+
|
143
152
|
[[tool.uv.index]]
|
144
153
|
url = "https://mirrors.bfsu.edu.cn/pypi/web/simple"
|
145
154
|
default = true
|
@@ -11,7 +11,7 @@ class TemplateManager:
|
|
11
11
|
"""
|
12
12
|
|
13
13
|
def __init__(
|
14
|
-
|
14
|
+
self, template_dirs: List[Path], suffix: Optional[str] = None, active_loading: Optional[bool] = None
|
15
15
|
) -> None:
|
16
16
|
"""Initialize the template manager.
|
17
17
|
|
@@ -55,6 +55,16 @@ class TemplateManager:
|
|
55
55
|
RuntimeError: If template rendering fails
|
56
56
|
"""
|
57
57
|
|
58
|
+
def render_template_raw(self, template: str, data: Dict[str, Any]) -> str:
|
59
|
+
"""Render a template with context data.
|
60
|
+
|
61
|
+
Args:
|
62
|
+
template: The template string
|
63
|
+
data: Context dictionary to provide variables to the template
|
64
|
+
|
65
|
+
Returns:
|
66
|
+
Rendered template content as string
|
67
|
+
"""
|
58
68
|
|
59
69
|
def blake3_hash(content: bytes) -> str:
|
60
70
|
"""Calculate the BLAKE3 cryptographic hash of data.
|
@@ -66,7 +76,6 @@ def blake3_hash(content: bytes) -> str:
|
|
66
76
|
Hex-encoded BLAKE3 hash string
|
67
77
|
"""
|
68
78
|
|
69
|
-
|
70
79
|
class BibManager:
|
71
80
|
"""BibTeX bibliography manager for parsing and querying citation data."""
|
72
81
|
|
@@ -0,0 +1,158 @@
|
|
1
|
+
"""Actions for transmitting tasks to targets."""
|
2
|
+
|
3
|
+
from pathlib import Path
|
4
|
+
from typing import Any, Callable, List, Optional
|
5
|
+
|
6
|
+
from fabricatio.fs import safe_text_read
|
7
|
+
from fabricatio.journal import logger
|
8
|
+
from fabricatio.models.action import Action
|
9
|
+
from fabricatio.models.extra import Article, ArticleEssence, ArticleOutline, ArticleProposal
|
10
|
+
from fabricatio.models.task import Task
|
11
|
+
from fabricatio.models.utils import ok
|
12
|
+
|
13
|
+
|
14
|
+
class ExtractArticleEssence(Action):
|
15
|
+
"""Extract the essence of article(s) in text format from the paths specified in the task dependencies.
|
16
|
+
|
17
|
+
Notes:
|
18
|
+
This action is designed to extract vital information from articles with Markdown format, which is pure text, and
|
19
|
+
which is converted from pdf files using `magic-pdf` from the `MinerU` project, see https://github.com/opendatalab/MinerU
|
20
|
+
"""
|
21
|
+
|
22
|
+
output_key: str = "article_essence"
|
23
|
+
"""The key of the output data."""
|
24
|
+
|
25
|
+
async def _execute(
|
26
|
+
self,
|
27
|
+
task_input: Task,
|
28
|
+
reader: Callable[[str], str] = lambda p: Path(p).read_text(encoding="utf-8"),
|
29
|
+
**_,
|
30
|
+
) -> Optional[List[ArticleEssence]]:
|
31
|
+
if not task_input.dependencies:
|
32
|
+
logger.info(err := "Task not approved, since no dependencies are provided.")
|
33
|
+
raise RuntimeError(err)
|
34
|
+
|
35
|
+
# trim the references
|
36
|
+
contents = ["References".join(c.split("References")[:-1]) for c in map(reader, task_input.dependencies)]
|
37
|
+
return await self.propose(
|
38
|
+
ArticleEssence,
|
39
|
+
contents,
|
40
|
+
system_message=f"# your personal briefing: \n{self.briefing}",
|
41
|
+
)
|
42
|
+
|
43
|
+
|
44
|
+
class GenerateArticleProposal(Action):
|
45
|
+
"""Generate an outline for the article based on the extracted essence."""
|
46
|
+
|
47
|
+
output_key: str = "article_proposal"
|
48
|
+
"""The key of the output data."""
|
49
|
+
|
50
|
+
async def _execute(
|
51
|
+
self,
|
52
|
+
task_input: Optional[Task] = None,
|
53
|
+
article_briefing: Optional[str] = None,
|
54
|
+
article_briefing_path: Optional[str] = None,
|
55
|
+
**_,
|
56
|
+
) -> Optional[ArticleProposal]:
|
57
|
+
if article_briefing is None and article_briefing_path is None and task_input is None:
|
58
|
+
logger.info("Task not approved, since ")
|
59
|
+
return None
|
60
|
+
if article_briefing_path is None and task_input:
|
61
|
+
article_briefing_path = await self.awhich_pathstr(
|
62
|
+
f"{task_input.briefing}\nExtract the path of file which contains the article briefing."
|
63
|
+
)
|
64
|
+
|
65
|
+
return (
|
66
|
+
await self.propose(
|
67
|
+
ArticleProposal,
|
68
|
+
briefing := (
|
69
|
+
article_briefing
|
70
|
+
or safe_text_read(ok(article_briefing_path, "Could not find the path of file to read."))
|
71
|
+
),
|
72
|
+
**self.prepend_sys_msg(),
|
73
|
+
)
|
74
|
+
).update_ref(briefing)
|
75
|
+
|
76
|
+
|
77
|
+
class GenerateOutline(Action):
|
78
|
+
"""Generate the article based on the outline."""
|
79
|
+
|
80
|
+
output_key: str = "article_outline"
|
81
|
+
"""The key of the output data."""
|
82
|
+
|
83
|
+
async def _execute(
|
84
|
+
self,
|
85
|
+
article_proposal: ArticleProposal,
|
86
|
+
**_,
|
87
|
+
) -> Optional[ArticleOutline]:
|
88
|
+
return (
|
89
|
+
await self.propose(
|
90
|
+
ArticleOutline,
|
91
|
+
article_proposal.as_prompt(),
|
92
|
+
**self.prepend_sys_msg(),
|
93
|
+
)
|
94
|
+
).update_ref(article_proposal)
|
95
|
+
|
96
|
+
|
97
|
+
class CorrectProposal(Action):
|
98
|
+
"""Correct the proposal of the article."""
|
99
|
+
|
100
|
+
output_key: str = "corrected_proposal"
|
101
|
+
|
102
|
+
async def _execute(self, article_proposal: ArticleProposal, **_) -> Any:
|
103
|
+
return (await self.censor_obj(article_proposal, reference=article_proposal.referenced)).update_ref(
|
104
|
+
article_proposal
|
105
|
+
)
|
106
|
+
|
107
|
+
|
108
|
+
class CorrectOutline(Action):
|
109
|
+
"""Correct the outline of the article."""
|
110
|
+
|
111
|
+
output_key: str = "corrected_outline"
|
112
|
+
"""The key of the output data."""
|
113
|
+
|
114
|
+
async def _execute(
|
115
|
+
self,
|
116
|
+
article_outline: ArticleOutline,
|
117
|
+
**_,
|
118
|
+
) -> ArticleOutline:
|
119
|
+
return (await self.censor_obj(article_outline, reference=article_outline.referenced.as_prompt())).update_ref(
|
120
|
+
article_outline
|
121
|
+
)
|
122
|
+
|
123
|
+
|
124
|
+
class GenerateArticle(Action):
|
125
|
+
"""Generate the article based on the outline."""
|
126
|
+
|
127
|
+
output_key: str = "article"
|
128
|
+
"""The key of the output data."""
|
129
|
+
|
130
|
+
async def _execute(
|
131
|
+
self,
|
132
|
+
article_outline: ArticleOutline,
|
133
|
+
**_,
|
134
|
+
) -> Optional[Article]:
|
135
|
+
article: Article = Article.from_outline(article_outline).update_ref(article_outline)
|
136
|
+
|
137
|
+
for c, deps in article.iter_dfs_with_deps():
|
138
|
+
out = await self.correct_obj(
|
139
|
+
c, reference=f"{article_outline.referenced.as_prompt()}\n" + "\n".join(d.display() for d in deps)
|
140
|
+
)
|
141
|
+
|
142
|
+
c.update_from(out)
|
143
|
+
return article
|
144
|
+
|
145
|
+
|
146
|
+
class CorrectArticle(Action):
|
147
|
+
"""Correct the article based on the outline."""
|
148
|
+
|
149
|
+
output_key: str = "corrected_article"
|
150
|
+
"""The key of the output data."""
|
151
|
+
|
152
|
+
async def _execute(
|
153
|
+
self,
|
154
|
+
article: Article,
|
155
|
+
article_outline: ArticleOutline,
|
156
|
+
**_,
|
157
|
+
) -> Article:
|
158
|
+
return await self.censor_obj(article, reference=article_outline.referenced.as_prompt())
|
@@ -0,0 +1,34 @@
|
|
1
|
+
"""Dump the finalized output to a file."""
|
2
|
+
|
3
|
+
from pathlib import Path
|
4
|
+
from typing import Optional
|
5
|
+
|
6
|
+
from fabricatio.models.action import Action
|
7
|
+
from fabricatio.models.generic import FinalizedDumpAble
|
8
|
+
from fabricatio.models.task import Task
|
9
|
+
from fabricatio.models.utils import ok
|
10
|
+
|
11
|
+
|
12
|
+
class DumpFinalizedOutput(Action):
|
13
|
+
"""Dump the finalized output to a file."""
|
14
|
+
|
15
|
+
output_key: str = "dump_path"
|
16
|
+
|
17
|
+
async def _execute(
|
18
|
+
self,
|
19
|
+
to_dump: FinalizedDumpAble,
|
20
|
+
task_input: Optional[Task] = None,
|
21
|
+
dump_path: Optional[str | Path] = None,
|
22
|
+
**_,
|
23
|
+
) -> str:
|
24
|
+
dump_path = Path(
|
25
|
+
dump_path
|
26
|
+
or ok(
|
27
|
+
await self.awhich_pathstr(
|
28
|
+
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."
|
29
|
+
),
|
30
|
+
"Could not find the path of file to dump the data.",
|
31
|
+
)
|
32
|
+
)
|
33
|
+
ok(to_dump, "Could not dump the data since the path is not specified.").finalized_dump_to(dump_path)
|
34
|
+
return dump_path.as_posix()
|
@@ -10,9 +10,11 @@ from typing import Optional, Unpack, cast
|
|
10
10
|
from fabricatio._rust_instances import TEMPLATE_MANAGER
|
11
11
|
from fabricatio.capabilities.review import Review, ReviewResult
|
12
12
|
from fabricatio.config import configs
|
13
|
-
from fabricatio.models.generic import Display, ProposedAble, WithBriefing
|
14
|
-
from fabricatio.models.kwargs_types import CorrectKwargs, ReviewKwargs
|
13
|
+
from fabricatio.models.generic import CensoredAble, Display, ProposedAble, WithBriefing
|
14
|
+
from fabricatio.models.kwargs_types import CensoredCorrectKwargs, CorrectKwargs, ReviewKwargs
|
15
15
|
from fabricatio.models.task import Task
|
16
|
+
from questionary import confirm, text
|
17
|
+
from rich import print as rprint
|
16
18
|
|
17
19
|
|
18
20
|
class Correct(Review):
|
@@ -55,7 +57,7 @@ class Correct(Review):
|
|
55
57
|
if supervisor_check:
|
56
58
|
await review_res.supervisor_check()
|
57
59
|
if "default" in kwargs:
|
58
|
-
cast(
|
60
|
+
cast("ReviewKwargs[None]", kwargs)["default"] = None
|
59
61
|
return await self.propose(
|
60
62
|
obj.__class__,
|
61
63
|
TEMPLATE_MANAGER.render_template(
|
@@ -89,7 +91,7 @@ class Correct(Review):
|
|
89
91
|
await review_res.supervisor_check()
|
90
92
|
|
91
93
|
if "default" in kwargs:
|
92
|
-
cast(
|
94
|
+
cast("ReviewKwargs[None]", kwargs)["default"] = None
|
93
95
|
return await self.ageneric_string(
|
94
96
|
TEMPLATE_MANAGER.render_template(
|
95
97
|
configs.templates.correct_template, {"content": input_text, "review": review_res.display()}
|
@@ -113,3 +115,31 @@ class Correct(Review):
|
|
113
115
|
Optional[Task[T]]: The corrected task, or None if correction fails.
|
114
116
|
"""
|
115
117
|
return await self.correct_obj(task, **kwargs)
|
118
|
+
|
119
|
+
async def censor_obj[M: CensoredAble](
|
120
|
+
self, obj: M, **kwargs: Unpack[CensoredCorrectKwargs[ReviewResult[str]]]
|
121
|
+
) -> M:
|
122
|
+
"""Censor and correct an object based on defined criteria and templates.
|
123
|
+
|
124
|
+
Args:
|
125
|
+
obj (M): The object to be reviewed and corrected.
|
126
|
+
**kwargs (Unpack[CensoredCorrectKwargs]): Additional keyword
|
127
|
+
|
128
|
+
Returns:
|
129
|
+
M: The censored and corrected object.
|
130
|
+
"""
|
131
|
+
last_modified_obj = obj
|
132
|
+
modified_obj = None
|
133
|
+
rprint(obj.finalized_dump())
|
134
|
+
while await confirm("Begin to correct obj above with human censorship?").ask_async():
|
135
|
+
while (topic := await text("What is the topic of the obj reviewing?").ask_async()) is not None and topic:
|
136
|
+
...
|
137
|
+
if (modified_obj := await self.correct_obj(
|
138
|
+
last_modified_obj,
|
139
|
+
topic=topic,
|
140
|
+
**kwargs,
|
141
|
+
)) is None:
|
142
|
+
break
|
143
|
+
last_modified_obj = modified_obj
|
144
|
+
rprint(last_modified_obj.finalized_dump())
|
145
|
+
return modified_obj or last_modified_obj
|
@@ -19,6 +19,7 @@ from fabricatio.models.kwargs_types import (
|
|
19
19
|
EmbeddingKwargs,
|
20
20
|
FetchKwargs,
|
21
21
|
LLMKwargs,
|
22
|
+
RetrievalKwargs,
|
22
23
|
)
|
23
24
|
from fabricatio.models.usages import EmbeddingUsage
|
24
25
|
from fabricatio.models.utils import MilvusData, ok
|
@@ -213,6 +214,25 @@ class RAG(EmbeddingUsage):
|
|
213
214
|
self.add_document(await self.pack(text), collection_name or self.safe_target_collection, flush=True)
|
214
215
|
return self
|
215
216
|
|
217
|
+
@overload
|
218
|
+
async def afetch_document[V: (int, str, float, bytes)](
|
219
|
+
self,
|
220
|
+
vecs: List[List[float]],
|
221
|
+
desired_fields: List[str],
|
222
|
+
collection_name: Optional[str] = None,
|
223
|
+
similarity_threshold: float = 0.37,
|
224
|
+
result_per_query: int = 10,
|
225
|
+
) -> List[Dict[str, V]]: ...
|
226
|
+
|
227
|
+
@overload
|
228
|
+
async def afetch_document[V: (int, str, float, bytes)](
|
229
|
+
self,
|
230
|
+
vecs: List[List[float]],
|
231
|
+
desired_fields: str,
|
232
|
+
collection_name: Optional[str] = None,
|
233
|
+
similarity_threshold: float = 0.37,
|
234
|
+
result_per_query: int = 10,
|
235
|
+
) -> List[V]: ...
|
216
236
|
async def afetch_document[V: (int, str, float, bytes)](
|
217
237
|
self,
|
218
238
|
vecs: List[List[float]],
|
@@ -275,7 +295,7 @@ class RAG(EmbeddingUsage):
|
|
275
295
|
if isinstance(query, str):
|
276
296
|
query = [query]
|
277
297
|
return cast(
|
278
|
-
|
298
|
+
"List[str]",
|
279
299
|
await self.afetch_document(
|
280
300
|
vecs=(await self.vectorize(query)),
|
281
301
|
desired_fields="text",
|
@@ -283,6 +303,24 @@ class RAG(EmbeddingUsage):
|
|
283
303
|
),
|
284
304
|
)[:final_limit]
|
285
305
|
|
306
|
+
async def aretrieve_compact(
|
307
|
+
self,
|
308
|
+
query: List[str] | str,
|
309
|
+
**kwargs: Unpack[RetrievalKwargs],
|
310
|
+
) -> str:
|
311
|
+
"""Retrieve data from the collection and format it for display.
|
312
|
+
|
313
|
+
Args:
|
314
|
+
query (List[str] | str): The query to be used for retrieval.
|
315
|
+
**kwargs (Unpack[RetrievalKwargs]): Additional keyword arguments for retrieval.
|
316
|
+
|
317
|
+
Returns:
|
318
|
+
str: A formatted string containing the retrieved data.
|
319
|
+
"""
|
320
|
+
return TEMPLATE_MANAGER.render_template(
|
321
|
+
configs.templates.retrieved_display_template, {"docs": (await self.aretrieve(query, **kwargs))}
|
322
|
+
)
|
323
|
+
|
286
324
|
async def aask_retrieved(
|
287
325
|
self,
|
288
326
|
question: str,
|
@@ -313,16 +351,14 @@ class RAG(EmbeddingUsage):
|
|
313
351
|
Returns:
|
314
352
|
str: A string response generated after asking with the context of retrieved documents.
|
315
353
|
"""
|
316
|
-
|
354
|
+
rendered = await self.aretrieve_compact(
|
317
355
|
query or question,
|
318
|
-
final_limit,
|
356
|
+
final_limit=final_limit,
|
319
357
|
collection_name=collection_name,
|
320
358
|
result_per_query=result_per_query,
|
321
359
|
similarity_threshold=similarity_threshold,
|
322
360
|
)
|
323
361
|
|
324
|
-
rendered = TEMPLATE_MANAGER.render_template(configs.templates.retrieved_display_template, {"docs": docs[::-1]})
|
325
|
-
|
326
362
|
logger.debug(f"Retrieved Documents: \n{rendered}")
|
327
363
|
return await self.aask(
|
328
364
|
question,
|
@@ -159,7 +159,7 @@ class GiveRating(WithBriefing, LLMUsage):
|
|
159
159
|
)
|
160
160
|
),
|
161
161
|
validator=_validator,
|
162
|
-
**self.
|
162
|
+
**self.prepend_sys_msg(kwargs),
|
163
163
|
)
|
164
164
|
|
165
165
|
async def draft_rating_criteria(
|
@@ -191,7 +191,7 @@ class GiveRating(WithBriefing, LLMUsage):
|
|
191
191
|
validator=lambda resp: set(out)
|
192
192
|
if (out := JsonCapture.validate_with(resp, list, str, criteria_count)) is not None
|
193
193
|
else out,
|
194
|
-
**self.
|
194
|
+
**self.prepend_sys_msg(kwargs),
|
195
195
|
)
|
196
196
|
|
197
197
|
async def draft_rating_criteria_from_examples(
|
@@ -244,7 +244,7 @@ class GiveRating(WithBriefing, LLMUsage):
|
|
244
244
|
validator=lambda resp: JsonCapture.validate_with(
|
245
245
|
resp, target_type=list, elements_type=str, length=reasons_count
|
246
246
|
),
|
247
|
-
**self.
|
247
|
+
**self.prepend_sys_msg(kwargs),
|
248
248
|
)
|
249
249
|
)
|
250
250
|
# extract certain mount of criteria from reasons according to their importance and frequency
|
@@ -301,7 +301,7 @@ class GiveRating(WithBriefing, LLMUsage):
|
|
301
301
|
for pair in windows
|
302
302
|
],
|
303
303
|
validator=lambda resp: JsonCapture.validate_with(resp, target_type=float),
|
304
|
-
**self.
|
304
|
+
**self.prepend_sys_msg(kwargs),
|
305
305
|
)
|
306
306
|
weights = [1]
|
307
307
|
for rw in relative_weights:
|
@@ -37,7 +37,7 @@ class ProposeTask(WithBriefing, Propose):
|
|
37
37
|
logger.error(err := f"{self.name}: Prompt must be provided.")
|
38
38
|
raise ValueError(err)
|
39
39
|
|
40
|
-
return await self.propose(Task, prompt, **self.
|
40
|
+
return await self.propose(Task, prompt, **self.prepend_sys_msg(cast("Dict[str, Any]", kwargs)))
|
41
41
|
|
42
42
|
|
43
43
|
class HandleTask(WithBriefing, ToolBoxUsage):
|
@@ -81,7 +81,7 @@ class HandleTask(WithBriefing, ToolBoxUsage):
|
|
81
81
|
return await self.aask_validate(
|
82
82
|
question=q,
|
83
83
|
validator=_validator,
|
84
|
-
**self.
|
84
|
+
**self.prepend_sys_msg(cast("Dict[str, Any]", kwargs)),
|
85
85
|
)
|
86
86
|
|
87
87
|
async def handle_fine_grind(
|
@@ -235,6 +235,9 @@ class TemplateConfig(BaseModel):
|
|
235
235
|
co_validation_template: str = Field(default="co_validation")
|
236
236
|
"""The name of the co-validation template which will be used to co-validate a string."""
|
237
237
|
|
238
|
+
as_prompt_template: str = Field(default="as_prompt")
|
239
|
+
"""The name of the as prompt template which will be used to convert a string to a prompt."""
|
240
|
+
|
238
241
|
|
239
242
|
class MagikaConfig(BaseModel):
|
240
243
|
"""Magika configuration class."""
|