fabricatio 0.2.6.dev2__tar.gz → 0.2.6.dev4__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.
Files changed (121) hide show
  1. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/Makefile +5 -5
  2. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/PKG-INFO +1 -1
  3. fabricatio-0.2.6.dev4/examples/correct/correct_loop.py +30 -0
  4. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/examples/extract_and_review/extract_and_review.py +2 -1
  5. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/examples/extract_article/extract.py +2 -1
  6. fabricatio-0.2.6.dev4/examples/search_bibtex/.gitignore +1 -0
  7. fabricatio-0.2.6.dev4/examples/search_bibtex/search.py +11 -0
  8. fabricatio-0.2.6.dev4/examples/write_outline/write_outline_corrected.py +44 -0
  9. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/pyproject.toml +2 -2
  10. fabricatio-0.2.6.dev4/python/fabricatio/__init__.py +43 -0
  11. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/_rust.pyi +14 -1
  12. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/actions/article.py +46 -2
  13. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/models/extra.py +3 -3
  14. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/models/kwargs_types.py +2 -2
  15. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/parser.py +1 -0
  16. fabricatio-0.2.6.dev4/python/fabricatio/workflows/articles.py +26 -0
  17. fabricatio-0.2.6.dev4/src/bib_tools.rs +88 -0
  18. fabricatio-0.2.6.dev4/templates.tar.gz +0 -0
  19. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/uv.lock +1 -1
  20. fabricatio-0.2.6.dev2/python/fabricatio/__init__.py +0 -60
  21. fabricatio-0.2.6.dev2/python/fabricatio/workflows/articles.py +0 -15
  22. fabricatio-0.2.6.dev2/src/bib_tools.rs +0 -73
  23. fabricatio-0.2.6.dev2/templates.tar.gz +0 -0
  24. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/.github/workflows/build-package.yaml +0 -0
  25. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/.github/workflows/ruff.yaml +0 -0
  26. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/.github/workflows/tests.yaml +0 -0
  27. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/.gitignore +0 -0
  28. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/.python-version +0 -0
  29. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/Cargo.lock +0 -0
  30. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/Cargo.toml +0 -0
  31. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/LICENSE +0 -0
  32. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/README.md +0 -0
  33. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/examples/correct/correct.py +0 -0
  34. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/examples/extract_and_review/.gitignore +0 -0
  35. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/examples/llm_usages/llm_usage.py +0 -0
  36. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/examples/make_a_rating/rating.py +0 -0
  37. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/examples/make_diary/commits.json +0 -0
  38. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/examples/make_diary/diary.py +0 -0
  39. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/examples/minor/hello_fabricatio.py +0 -0
  40. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/examples/minor/write_a_poem.py +0 -0
  41. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/examples/propose_task/propose.py +0 -0
  42. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/examples/reviewer/review.py +0 -0
  43. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/examples/simple_chat/chat.py +0 -0
  44. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/examples/simple_rag/simple_rag.py +0 -0
  45. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/examples/task_handle/handle_task.py +0 -0
  46. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/examples/write_outline/.gitignore +0 -0
  47. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/examples/write_outline/write_outline.py +0 -0
  48. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/_rust_instances.py +0 -0
  49. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/actions/output.py +0 -0
  50. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/actions/rag.py +0 -0
  51. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/capabilities/correct.py +0 -0
  52. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/capabilities/propose.py +0 -0
  53. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/capabilities/rag.py +0 -0
  54. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/capabilities/rating.py +0 -0
  55. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/capabilities/review.py +0 -0
  56. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/capabilities/task.py +0 -0
  57. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/config.py +0 -0
  58. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/core.py +0 -0
  59. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/decorators.py +0 -0
  60. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/fs/__init__.py +0 -0
  61. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/fs/curd.py +0 -0
  62. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/fs/readers.py +0 -0
  63. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/journal.py +0 -0
  64. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/models/action.py +0 -0
  65. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/models/events.py +0 -0
  66. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/models/generic.py +0 -0
  67. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/models/role.py +0 -0
  68. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/models/task.py +0 -0
  69. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/models/tool.py +0 -0
  70. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/models/usages.py +0 -0
  71. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/models/utils.py +0 -0
  72. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/py.typed +0 -0
  73. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/toolboxes/__init__.py +0 -0
  74. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/toolboxes/arithmetic.py +0 -0
  75. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/toolboxes/fs.py +0 -0
  76. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/python/fabricatio/workflows/rag.py +0 -0
  77. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/src/hash.rs +0 -0
  78. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/src/hbs_helpers.rs +0 -0
  79. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/src/lib.rs +0 -0
  80. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/src/templates.rs +0 -0
  81. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
  82. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/claude-xml.hbs +0 -0
  83. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/clean-up-code.hbs +0 -0
  84. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/correct.hbs +0 -0
  85. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/create_json_obj.hbs +0 -0
  86. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
  87. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/dependencies.hbs +0 -0
  88. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/document-the-code.hbs +0 -0
  89. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/draft_rating_criteria.hbs +0 -0
  90. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/draft_rating_manual.hbs +0 -0
  91. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/draft_rating_weights_klee.hbs +0 -0
  92. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/draft_tool_usage_code.hbs +0 -0
  93. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/extract_criteria_from_reasons.hbs +0 -0
  94. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/extract_reasons_from_examples.hbs +0 -0
  95. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
  96. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/fix-bugs.hbs +0 -0
  97. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/generic_string.hbs +0 -0
  98. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/improve-performance.hbs +0 -0
  99. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/liststr.hbs +0 -0
  100. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/make_choice.hbs +0 -0
  101. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/make_judgment.hbs +0 -0
  102. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/pathstr.hbs +0 -0
  103. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/rate_fine_grind.hbs +0 -0
  104. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/refactor.hbs +0 -0
  105. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/refined_query.hbs +0 -0
  106. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/retrieved_display.hbs +0 -0
  107. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
  108. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/review_string.hbs +0 -0
  109. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/task_briefing.hbs +0 -0
  110. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/web-ctf-solver.hbs +0 -0
  111. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/write-git-commit.hbs +0 -0
  112. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/write-github-pull-request.hbs +0 -0
  113. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/templates/built-in/write-github-readme.hbs +0 -0
  114. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/tests/test_config.py +0 -0
  115. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/tests/test_models/test_action.py +0 -0
  116. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/tests/test_models/test_advanced.py +0 -0
  117. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/tests/test_models/test_generic.py +0 -0
  118. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/tests/test_models/test_role.py +0 -0
  119. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/tests/test_models/test_task.py +0 -0
  120. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/tests/test_models/test_tool.py +0 -0
  121. {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev4}/tests/test_models/test_usages.py +0 -0
@@ -12,16 +12,16 @@ tools:
12
12
  rm $(DATA)/scripts/*.dwarf || true
13
13
 
14
14
  dev: tools
15
- uvx --with-editable . maturin develop --uv -r
15
+ uvx --project . maturin develop --uv -r
16
16
 
17
17
  bdist:clean tools
18
- uvx --with-editable . maturin sdist -o $(DIST)
19
- uvx --with-editable . maturin build -r -o $(DIST)
18
+ uvx --project . maturin sdist -o $(DIST)
19
+ uvx --project . maturin build -r -o $(DIST)
20
20
 
21
21
  clean:
22
22
  rm -rf $(DIST) $(DATA)
23
23
 
24
24
  publish:tools
25
- uvx --with-editable . maturin publish --skip-existing
26
- uvx --with-editable . maturin upload --skip-existing $(DIST)/*
25
+ uvx --project . maturin publish --skip-existing
26
+ uvx --project . maturin upload --skip-existing $(DIST)/*
27
27
  .PHONY: tools
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fabricatio
3
- Version: 0.2.6.dev2
3
+ Version: 0.2.6.dev4
4
4
  Classifier: License :: OSI Approved :: MIT License
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -0,0 +1,30 @@
1
+ """Example of review usage."""
2
+
3
+ import asyncio
4
+
5
+ from fabricatio import Role, logger
6
+ from questionary import confirm
7
+ from rich import print as r_print
8
+
9
+
10
+ async def main() -> None:
11
+ """Main function."""
12
+ role = Role(
13
+ name="Reviewer",
14
+ description="A role that reviews the code.",
15
+ )
16
+
17
+ code = await role.aask(
18
+ "write a cli app using rust with clap which can generate a basic manifest of a standard rust project, output code only,no extra explanation, you should using derive mode of clap."
19
+ )
20
+
21
+ logger.success(f"Code: \n{code}")
22
+
23
+ while await confirm("Do you want to review the code?").ask_async():
24
+ code = await role.correct_string(code, topic="If the cli app is of good design", supervisor_check=False)
25
+ r_print(code)
26
+ logger.success(f"Corrected: \n{code}")
27
+
28
+
29
+ if __name__ == "__main__":
30
+ asyncio.run(main())
@@ -4,7 +4,8 @@ import asyncio
4
4
  from pathlib import Path
5
5
  from typing import List
6
6
 
7
- from fabricatio import ArticleEssence, Event, ExtractArticleEssence, Role, Task, WorkFlow, logger
7
+ from fabricatio import ArticleEssence, Event, Role, Task, WorkFlow, logger
8
+ from fabricatio.actions.article import ExtractArticleEssence
8
9
  from fabricatio.fs.curd import dump_text, gather_files
9
10
 
10
11
 
@@ -3,7 +3,8 @@
3
3
  import asyncio
4
4
  from typing import List
5
5
 
6
- from fabricatio import ArticleEssence, Event, ExtractArticleEssence, Role, Task, WorkFlow, logger
6
+ from fabricatio import ArticleEssence, Event, Role, Task, WorkFlow, logger
7
+ from fabricatio.actions.article import ExtractArticleEssence
7
8
 
8
9
 
9
10
  async def main() -> None:
@@ -0,0 +1,11 @@
1
+ """Example of using BibManager."""
2
+ from fabricatio import BibManager, logger
3
+
4
+ b = BibManager("Exported Items.bib")
5
+ logger.success(
6
+ b.get_cite_key("A Negative Selection Immune System Inspired Methodology for Fault Diagnosis of Wind Turbines"))
7
+ logger.success(
8
+ b.get_cite_key_fuzzy(
9
+ "System Inspired Methodology for Fault"
10
+ )
11
+ )
@@ -0,0 +1,44 @@
1
+ """Example of using the library."""
2
+
3
+ import asyncio
4
+
5
+ from fabricatio import Event, Role, WorkFlow, logger
6
+ from fabricatio.actions.article import CorrectOutline, CorrectProposal, GenerateArticleProposal, GenerateOutline
7
+ from fabricatio.actions.output import DumpFinalizedOutput
8
+
9
+
10
+ async def main() -> None:
11
+ """Main function."""
12
+ role = Role(
13
+ name="Undergraduate Researcher",
14
+ description="Write an outline for an article in typst format.",
15
+ llm_top_p=0.8,
16
+ llm_temperature=1.15,
17
+ registry={
18
+ Event.quick_instantiate(ns := "article"): WorkFlow(
19
+ name="Generate Article Outline",
20
+ description="Generate an outline for an article. dump the outline to the given path. in typst format.",
21
+ steps=(
22
+ GenerateArticleProposal(llm_model="deepseek/deepseek-reasoner", llm_temperature=1.3),
23
+ CorrectProposal(
24
+ output_key="article_proposal",
25
+ llm_model="deepseek/deepseek-reasoner",
26
+ llm_temperature=1.3,
27
+ ),
28
+ GenerateOutline(llm_model="deepseek/deepseek-chat", llm_temperature=1.4, llm_top_p=0.5),
29
+ CorrectOutline(output_key="to_dump", llm_temperature=1.4, llm_top_p=0.45),
30
+ DumpFinalizedOutput(output_key="task_output"),
31
+ ),
32
+ )
33
+ },
34
+ )
35
+
36
+ proposed_task = await role.propose_task(
37
+ "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.",
38
+ )
39
+ path = await proposed_task.delegate(ns)
40
+ logger.success(f"The outline is saved in:\n{path}")
41
+
42
+
43
+ if __name__ == "__main__":
44
+ asyncio.run(main())
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "fabricatio"
3
- version = "0.2.6-dev2"
3
+ version = "0.2.6-dev4"
4
4
  description = "A LLM multi-agent framework."
5
5
  readme = "README.md"
6
6
  license = { file = "LICENSE" }
@@ -85,7 +85,7 @@ full = [
85
85
  ]
86
86
 
87
87
  [tool.ruff]
88
- include = ["pyproject.toml", "python/fabricatio/*.py","python/fabricatio/*.pyi", "examples/*.py"]
88
+ include = ["pyproject.toml", "python/fabricatio/*.py", "python/fabricatio/*.pyi", "examples/*.py"]
89
89
  line-length = 120
90
90
  target-version = "py312"
91
91
  [tool.ruff.format]
@@ -0,0 +1,43 @@
1
+ """Fabricatio is a Python library for building llm app using event-based agent structure."""
2
+
3
+ from importlib.util import find_spec
4
+
5
+ from fabricatio import actions, toolboxes, workflows
6
+ from fabricatio._rust import BibManager
7
+ from fabricatio._rust_instances import TEMPLATE_MANAGER
8
+ from fabricatio.core import env
9
+ from fabricatio.journal import logger
10
+ from fabricatio.models import extra
11
+ from fabricatio.models.action import Action, WorkFlow
12
+ from fabricatio.models.events import Event
13
+ from fabricatio.models.role import Role
14
+ from fabricatio.models.task import Task
15
+ from fabricatio.models.tool import ToolBox
16
+ from fabricatio.parser import Capture, GenericCapture, JsonCapture, PythonCapture
17
+
18
+ __all__ = [
19
+ "TEMPLATE_MANAGER",
20
+ "Action",
21
+ "BibManager",
22
+ "Capture",
23
+ "Event",
24
+ "GenericCapture",
25
+ "JsonCapture",
26
+ "PythonCapture",
27
+ "Role",
28
+ "Task",
29
+ "ToolBox",
30
+ "WorkFlow",
31
+ "actions",
32
+ "env",
33
+ "extra",
34
+ "logger",
35
+ "toolboxes",
36
+ "workflows",
37
+ ]
38
+
39
+
40
+ if find_spec("pymilvus"):
41
+ from fabricatio.capabilities.rag import RAG
42
+
43
+ __all__ += ["RAG"]
@@ -9,8 +9,9 @@ class TemplateManager:
9
9
 
10
10
  See: https://crates.io/crates/handlebars
11
11
  """
12
+
12
13
  def __init__(
13
- self, template_dirs: List[Path], suffix: Optional[str] = None, active_loading: Optional[bool] = None
14
+ self, template_dirs: List[Path], suffix: Optional[str] = None, active_loading: Optional[bool] = None
14
15
  ) -> None:
15
16
  """Initialize the template manager.
16
17
 
@@ -54,6 +55,7 @@ class TemplateManager:
54
55
  RuntimeError: If template rendering fails
55
56
  """
56
57
 
58
+
57
59
  def blake3_hash(content: bytes) -> str:
58
60
  """Calculate the BLAKE3 cryptographic hash of data.
59
61
 
@@ -64,6 +66,7 @@ def blake3_hash(content: bytes) -> str:
64
66
  Hex-encoded BLAKE3 hash string
65
67
  """
66
68
 
69
+
67
70
  class BibManager:
68
71
  """BibTeX bibliography manager for parsing and querying citation data."""
69
72
 
@@ -100,3 +103,13 @@ class BibManager:
100
103
  Uses nucleo_matcher for high-quality fuzzy text searching
101
104
  See: https://crates.io/crates/nucleo-matcher
102
105
  """
106
+
107
+ def list_titles(self, is_verbatim: Optional[bool] = False) -> List[str]:
108
+ """List all titles in the bibliography.
109
+
110
+ Args:
111
+ is_verbatim: Whether to return verbatim titles (without formatting)
112
+
113
+ Returns:
114
+ List of all titles in the bibliography
115
+ """
@@ -2,13 +2,15 @@
2
2
 
3
3
  from os import PathLike
4
4
  from pathlib import Path
5
- from typing import Callable, List, Optional
5
+ from typing import Any, Callable, List, Optional
6
6
 
7
7
  from fabricatio.fs import safe_text_read
8
8
  from fabricatio.journal import logger
9
9
  from fabricatio.models.action import Action
10
10
  from fabricatio.models.extra import ArticleEssence, ArticleOutline, ArticleProposal
11
11
  from fabricatio.models.task import Task
12
+ from questionary import confirm, text
13
+ from rich import print as rprint
12
14
 
13
15
 
14
16
  class ExtractArticleEssence(Action):
@@ -66,7 +68,7 @@ class GenerateArticleProposal(Action):
66
68
  class GenerateOutline(Action):
67
69
  """Generate the article based on the outline."""
68
70
 
69
- output_key: str = "article"
71
+ output_key: str = "article_outline"
70
72
  """The key of the output data."""
71
73
 
72
74
  async def _execute(
@@ -79,3 +81,45 @@ class GenerateOutline(Action):
79
81
  article_proposal.display(),
80
82
  system_message=f"# your personal briefing: \n{self.briefing}",
81
83
  )
84
+
85
+
86
+ class CorrectProposal(Action):
87
+ """Correct the proposal of the article."""
88
+
89
+ output_key: str = "corrected_proposal"
90
+
91
+ async def _execute(self, task_input: Task, article_proposal: ArticleProposal, **_) -> Any:
92
+ input_path = await self.awhich_pathstr(
93
+ f"{task_input.briefing}\nExtract the path of file, which contains the article briefing that I need to read."
94
+ )
95
+
96
+ rprint(article_proposal.display())
97
+ ret = None
98
+ while await confirm("Do you want to correct the Proposal?").ask_async():
99
+ topic = await text("What is the topic of the proposal?").ask_async()
100
+ ret = await self.correct_obj(
101
+ article_proposal,
102
+ safe_text_read(input_path),
103
+ topic=topic,
104
+ )
105
+ return ret or article_proposal
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
+ article_proposal: ArticleProposal,
118
+ **_,
119
+ ) -> Optional[str]:
120
+ rprint(article_outline.finalized_dump())
121
+ ret = None
122
+ while await confirm("Do you want to correct the outline?").ask_async():
123
+ topic = await text("What is the topic of the outline?").ask_async()
124
+ ret = await self.correct_obj(article_outline, article_proposal.display(), topic=topic)
125
+ return ret or article_outline
@@ -126,7 +126,7 @@ class ArticleSectionOutline(Base):
126
126
  """The title of the section."""
127
127
  description: str = Field(...)
128
128
  """A brief description of the section's content should be, how it fits into the overall structure of the paper, and its significance in the context of the research."""
129
- subsections: List[ArticleSubsectionOutline] = Field(default_factory=list)
129
+ subsections: List[ArticleSubsectionOutline]
130
130
  """The subsections of the section, outlining their content and significance."""
131
131
 
132
132
 
@@ -137,7 +137,7 @@ class ArticleChapterOutline(Base):
137
137
  """The title of the chapter."""
138
138
  description: str = Field(...)
139
139
  """A brief description of the chapter's content should be, how it fits into the overall structure of the paper, and its significance in the context of the research."""
140
- sections: List[ArticleSectionOutline] = Field(default_factory=list)
140
+ sections: List[ArticleSectionOutline]
141
141
  """The sections of the chapter, outlining their content and significance."""
142
142
 
143
143
 
@@ -150,7 +150,7 @@ class ArticleOutline(ProposedAble, Display, FinalizedDumpAble):
150
150
  prospect: str = Field(...)
151
151
  """A brief description of the research problem or question that the paper aims to address manipulating methods or techniques"""
152
152
 
153
- chapters: List[ArticleChapterOutline] = Field(default_factory=list)
153
+ chapters: List[ArticleChapterOutline]
154
154
  """The chapters of the paper, outlining their content and significance."""
155
155
 
156
156
  def finalized_dump(self) -> str:
@@ -1,6 +1,6 @@
1
1
  """This module contains the types for the keyword arguments of the methods in the models module."""
2
2
 
3
- from typing import Any, TypedDict
3
+ from typing import Any, Required, TypedDict
4
4
 
5
5
  from litellm.caching.caching import CacheMode
6
6
  from litellm.types.caching import CachingSupportedCallTypes
@@ -91,7 +91,7 @@ class ReviewKwargs[T](ValidateKwargs[T], total=False):
91
91
  specific topics and review criteria.
92
92
  """
93
93
 
94
- topic: str
94
+ topic: Required[str]
95
95
  criteria: set[str]
96
96
 
97
97
 
@@ -64,6 +64,7 @@ class Capture(BaseModel):
64
64
  """
65
65
  match = self._compiled.search(text)
66
66
  if match is None:
67
+ logger.debug(f"Capture Failed: \n{text}")
67
68
  return None
68
69
  groups = self.fix(match.groups()) if configs.general.use_json_repair else match.groups()
69
70
  if self.target_groups:
@@ -0,0 +1,26 @@
1
+ """Store article essence in the database."""
2
+
3
+ from fabricatio.actions.article import CorrectOutline, CorrectProposal, GenerateArticleProposal, GenerateOutline
4
+ from fabricatio.actions.output import DumpFinalizedOutput
5
+ from fabricatio.models.action import WorkFlow
6
+
7
+ WriteOutlineWorkFlow = WorkFlow(
8
+ name="Generate Article Outline",
9
+ description="Generate an outline for an article. dump the outline to the given path. in typst format.",
10
+ steps=(
11
+ GenerateArticleProposal,
12
+ GenerateOutline(output_key="to_dump"),
13
+ DumpFinalizedOutput(output_key="task_output"),
14
+ ),
15
+ )
16
+ WriteOutlineCorrectedWorkFlow = WorkFlow(
17
+ name="Generate Article Outline",
18
+ description="Generate an outline for an article. dump the outline to the given path. in typst format.",
19
+ steps=(
20
+ GenerateArticleProposal,
21
+ CorrectProposal(output_key="article_proposal"),
22
+ GenerateOutline,
23
+ CorrectOutline(output_key="to_dump"),
24
+ DumpFinalizedOutput(output_key="task_output"),
25
+ ),
26
+ )
@@ -0,0 +1,88 @@
1
+ use biblatex::{Bibliography, ChunksExt};
2
+ use nucleo_matcher::pattern::{AtomKind, CaseMatching, Normalization, Pattern};
3
+ use nucleo_matcher::{Config, Matcher, Utf32Str};
4
+ use pyo3::exceptions::PyRuntimeError;
5
+ use pyo3::prelude::*;
6
+ use rayon::prelude::*;
7
+
8
+ #[pyclass]
9
+ pub struct BibManager {
10
+ source: Bibliography,
11
+ }
12
+
13
+
14
+ #[pymethods]
15
+ impl BibManager {
16
+ /// Create a new BibManager instance.
17
+ #[new]
18
+ fn new(path: String) -> PyResult<Self> {
19
+ let bib = std::fs::read_to_string(path)
20
+ .map_err(|e| PyErr::new::<PyRuntimeError, _>(e.to_string()))?;
21
+
22
+ let source = Bibliography::parse(&bib)
23
+ .map_err(|e| PyErr::new::<PyRuntimeError, _>(e.to_string()))?;
24
+
25
+ Ok(BibManager { source })
26
+ }
27
+
28
+ /// find the cite key of an article with given title
29
+ fn get_cite_key(&self, title: String) -> Option<String> {
30
+ let title_lower = title.to_lowercase();
31
+
32
+ self.source.iter().par_bridge()
33
+ .find_map_any(|entry| {
34
+ let entry_title = entry.title()
35
+ .map_err(|e| PyErr::new::<PyRuntimeError, _>(format!("{}", e)))
36
+ .ok()?
37
+ .to_biblatex_string(false)
38
+ .replace("{", "")
39
+ .replace("}", "")
40
+ .to_lowercase();
41
+
42
+ (entry_title == title_lower).then(|| entry.key.clone())
43
+ })
44
+ }
45
+
46
+ /// Find the corresponding cite key of an article with given query string using fuzzy matcher
47
+ fn get_cite_key_fuzzy(&self, query: String) -> Option<String> {
48
+ let mut matcher = Matcher::new(Config::DEFAULT);
49
+ let pattern = Pattern::new(
50
+ query.as_str(),
51
+ CaseMatching::Ignore,
52
+ Normalization::Smart,
53
+ AtomKind::Substring,
54
+ );
55
+
56
+
57
+ self.source.iter()
58
+ .map(|entry| {
59
+ let mut buf = vec![];
60
+ let text = entry.to_biblatex_string().replace("{", "")
61
+ .replace("}", "");
62
+ (pattern.score(Utf32Str::new(text.as_str(), &mut buf), &mut matcher), entry)
63
+ })
64
+ .par_bridge()
65
+ // Use filter_map's more concise form with pattern matching
66
+ .filter_map(|(maybe_score, entry)| maybe_score.map(|score| (score, entry)))
67
+ .max_by_key(|(score, _)| *score)
68
+ .map(|(_, entry)| entry.key.clone())
69
+ }
70
+ #[pyo3(signature = (is_verbatim=false))]
71
+ fn list_titles(&self, is_verbatim: bool) -> Vec<String> {
72
+ self.source.iter().map(|entry| {
73
+ entry.title()
74
+ .map_err(|e| PyErr::new::<PyRuntimeError, _>(format!("{}", e)))
75
+ .ok()
76
+ .unwrap()
77
+ .to_biblatex_string(is_verbatim)
78
+ .replace("{", "")
79
+ .replace("}", "")
80
+ }).collect::<Vec<_>>()
81
+ }
82
+ }
83
+
84
+
85
+ pub(crate) fn register(_: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
86
+ m.add_class::<BibManager>()?;
87
+ Ok(())
88
+ }
Binary file
@@ -216,7 +216,7 @@ wheels = [
216
216
 
217
217
  [[package]]
218
218
  name = "fabricatio"
219
- version = "0.2.6.dev2"
219
+ version = "0.2.6.dev4"
220
220
  source = { editable = "." }
221
221
  dependencies = [
222
222
  { name = "appdirs" },
@@ -1,60 +0,0 @@
1
- """Fabricatio is a Python library for building llm app using event-based agent structure."""
2
-
3
- from importlib.util import find_spec
4
-
5
- from fabricatio._rust import BibManager
6
- from fabricatio._rust_instances import TEMPLATE_MANAGER
7
- from fabricatio.actions.article import ExtractArticleEssence, GenerateArticleProposal, GenerateOutline
8
- from fabricatio.actions.output import DumpFinalizedOutput
9
- from fabricatio.core import env
10
- from fabricatio.fs import MAGIKA, safe_json_read, safe_text_read
11
- from fabricatio.journal import logger
12
- from fabricatio.models.action import Action, WorkFlow
13
- from fabricatio.models.events import Event
14
- from fabricatio.models.extra import ArticleEssence
15
- from fabricatio.models.role import Role
16
- from fabricatio.models.task import Task
17
- from fabricatio.models.tool import ToolBox
18
- from fabricatio.models.utils import Message, Messages
19
- from fabricatio.parser import Capture, GenericCapture, JsonCapture, PythonCapture
20
- from fabricatio.toolboxes import arithmetic_toolbox, basic_toolboxes, fs_toolbox
21
- from fabricatio.workflows.articles import WriteOutlineWorkFlow
22
-
23
- __all__ = [
24
- "MAGIKA",
25
- "TEMPLATE_MANAGER",
26
- "Action",
27
- "ArticleEssence",
28
- "BibManager",
29
- "Capture",
30
- "DumpFinalizedOutput",
31
- "Event",
32
- "ExtractArticleEssence",
33
- "GenerateArticleProposal",
34
- "GenerateOutline",
35
- "GenericCapture",
36
- "JsonCapture",
37
- "Message",
38
- "Messages",
39
- "PythonCapture",
40
- "Role",
41
- "Task",
42
- "ToolBox",
43
- "WorkFlow",
44
- "WriteOutlineWorkFlow",
45
- "arithmetic_toolbox",
46
- "basic_toolboxes",
47
- "env",
48
- "fs_toolbox",
49
- "logger",
50
- "safe_json_read",
51
- "safe_text_read",
52
- ]
53
-
54
-
55
- if find_spec("pymilvus"):
56
- from fabricatio.actions.rag import InjectToDB
57
- from fabricatio.capabilities.rag import RAG
58
- from fabricatio.workflows.rag import StoreArticle
59
-
60
- __all__ += ["RAG", "InjectToDB", "StoreArticle"]
@@ -1,15 +0,0 @@
1
- """Store article essence in the database."""
2
-
3
- from fabricatio.actions.article import GenerateArticleProposal, GenerateOutline
4
- from fabricatio.actions.output import DumpFinalizedOutput
5
- from fabricatio.models.action import WorkFlow
6
-
7
- WriteOutlineWorkFlow = WorkFlow(
8
- name="Generate Article Outline",
9
- description="Generate an outline for an article. dump the outline to the given path. in typst format.",
10
- steps=(
11
- GenerateArticleProposal,
12
- GenerateOutline(output_key="to_dump"),
13
- DumpFinalizedOutput(output_key="task_output"),
14
- ),
15
- )
@@ -1,73 +0,0 @@
1
- use biblatex::{Bibliography, ChunksExt};
2
- use nucleo_matcher::pattern::{AtomKind, CaseMatching, Normalization, Pattern};
3
- use nucleo_matcher::{Config, Matcher, Utf32Str};
4
- use pyo3::exceptions::PyRuntimeError;
5
- use pyo3::prelude::*;
6
- use rayon::prelude::*;
7
-
8
- #[pyclass]
9
- pub struct BibManager {
10
- source:Bibliography,
11
- }
12
-
13
-
14
- #[pymethods]
15
- impl BibManager {
16
- /// Create a new BibManager instance.
17
- #[new]
18
- fn new(path: String) -> PyResult<Self> {
19
- let bib = std::fs::read_to_string(path)
20
- .map_err(|e| PyErr::new::<PyRuntimeError, _>(e.to_string()))?;
21
-
22
- let source = Bibliography::parse(&bib)
23
- .map_err(|e| PyErr::new::<PyRuntimeError, _>(e.to_string()))?;
24
-
25
- Ok(BibManager { source })
26
- }
27
-
28
- /// find the cite key of an article with given title
29
- fn get_cite_key(&self, title: String) -> Option<String> {
30
- let title_lower = title.to_lowercase();
31
-
32
- self.source.iter().par_bridge()
33
- .find_map_any(|entry| {
34
- let entry_title = entry.title()
35
- .map_err(|e| PyErr::new::<PyRuntimeError, _>(format!("{}", e)))
36
- .ok()?
37
- .to_biblatex_string(false)
38
- .to_lowercase();
39
-
40
- (entry_title == title_lower).then(|| entry.key.clone())
41
- })
42
- }
43
-
44
- /// Find the corresponding cite key of an article with given query string using fuzzy matcher
45
- fn get_cite_key_fuzzy(&self, query: String) -> Option<String> {
46
- let mut matcher = Matcher::new(Config::DEFAULT);
47
- let pattern = Pattern::new(
48
- query.as_str(),
49
- CaseMatching::Ignore,
50
- Normalization::Smart,
51
- AtomKind::Substring,
52
- );
53
-
54
- self.source.iter()
55
- .map(|entry| {
56
- let mut buf = vec![];
57
- let text = entry.to_biblatex_string();
58
- (pattern.score(Utf32Str::new(text.as_str(), &mut buf), &mut matcher), entry)
59
- })
60
- .par_bridge()
61
- // Use filter_map's more concise form with pattern matching
62
- .filter_map(|(maybe_score, entry)| maybe_score.map(|score| (score, entry)))
63
- .max_by_key(|(score, _)| *score)
64
- .map(|(_, entry)| entry.key.clone())
65
- }
66
-
67
- }
68
-
69
-
70
- pub(crate) fn register(_: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
71
- m.add_class::<BibManager>()?;
72
- Ok(())
73
- }
Binary file
File without changes