fabricatio 0.2.6.dev4__tar.gz → 0.2.6.dev6__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 (122) hide show
  1. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/PKG-INFO +1 -1
  2. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/examples/extract_and_review/extract_and_review.py +5 -2
  3. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/examples/extract_article/extract.py +5 -2
  4. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/examples/make_diary/diary.py +1 -1
  5. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/pyproject.toml +1 -1
  6. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/actions/article.py +7 -4
  7. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/capabilities/rag.py +3 -3
  8. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/capabilities/task.py +2 -2
  9. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/config.py +21 -18
  10. fabricatio-0.2.6.dev6/python/fabricatio/models/action.py +218 -0
  11. fabricatio-0.2.6.dev6/python/fabricatio/models/extra.py +339 -0
  12. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/models/kwargs_types.py +1 -0
  13. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/models/role.py +30 -6
  14. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/models/usages.py +63 -31
  15. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/models/utils.py +21 -0
  16. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/parser.py +1 -0
  17. fabricatio-0.2.6.dev6/templates/built-in/co_validation.hbs +26 -0
  18. fabricatio-0.2.6.dev6/templates.tar.gz +0 -0
  19. fabricatio-0.2.6.dev6/uv.lock +1547 -0
  20. fabricatio-0.2.6.dev4/python/fabricatio/models/action.py +0 -158
  21. fabricatio-0.2.6.dev4/python/fabricatio/models/extra.py +0 -171
  22. fabricatio-0.2.6.dev4/templates.tar.gz +0 -0
  23. fabricatio-0.2.6.dev4/uv.lock +0 -1549
  24. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/.github/workflows/build-package.yaml +0 -0
  25. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/.github/workflows/ruff.yaml +0 -0
  26. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/.github/workflows/tests.yaml +0 -0
  27. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/.gitignore +0 -0
  28. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/.python-version +0 -0
  29. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/Cargo.lock +0 -0
  30. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/Cargo.toml +0 -0
  31. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/LICENSE +0 -0
  32. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/Makefile +0 -0
  33. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/README.md +0 -0
  34. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/examples/correct/correct.py +0 -0
  35. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/examples/correct/correct_loop.py +0 -0
  36. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/examples/extract_and_review/.gitignore +0 -0
  37. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/examples/llm_usages/llm_usage.py +0 -0
  38. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/examples/make_a_rating/rating.py +0 -0
  39. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/examples/make_diary/commits.json +0 -0
  40. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/examples/minor/hello_fabricatio.py +0 -0
  41. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/examples/minor/write_a_poem.py +0 -0
  42. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/examples/propose_task/propose.py +0 -0
  43. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/examples/reviewer/review.py +0 -0
  44. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/examples/search_bibtex/.gitignore +0 -0
  45. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/examples/search_bibtex/search.py +0 -0
  46. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/examples/simple_chat/chat.py +0 -0
  47. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/examples/simple_rag/simple_rag.py +0 -0
  48. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/examples/task_handle/handle_task.py +0 -0
  49. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/examples/write_outline/.gitignore +0 -0
  50. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/examples/write_outline/write_outline.py +0 -0
  51. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/examples/write_outline/write_outline_corrected.py +0 -0
  52. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/__init__.py +0 -0
  53. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/_rust.pyi +0 -0
  54. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/_rust_instances.py +0 -0
  55. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/actions/output.py +0 -0
  56. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/actions/rag.py +0 -0
  57. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/capabilities/correct.py +0 -0
  58. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/capabilities/propose.py +0 -0
  59. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/capabilities/rating.py +0 -0
  60. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/capabilities/review.py +0 -0
  61. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/core.py +0 -0
  62. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/decorators.py +0 -0
  63. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/fs/__init__.py +0 -0
  64. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/fs/curd.py +0 -0
  65. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/fs/readers.py +0 -0
  66. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/journal.py +0 -0
  67. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/models/events.py +0 -0
  68. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/models/generic.py +0 -0
  69. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/models/task.py +0 -0
  70. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/models/tool.py +0 -0
  71. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/py.typed +0 -0
  72. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/toolboxes/__init__.py +0 -0
  73. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/toolboxes/arithmetic.py +0 -0
  74. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/toolboxes/fs.py +0 -0
  75. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/workflows/articles.py +0 -0
  76. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/python/fabricatio/workflows/rag.py +0 -0
  77. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/src/bib_tools.rs +0 -0
  78. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/src/hash.rs +0 -0
  79. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/src/hbs_helpers.rs +0 -0
  80. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/src/lib.rs +0 -0
  81. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/src/templates.rs +0 -0
  82. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
  83. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/claude-xml.hbs +0 -0
  84. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/clean-up-code.hbs +0 -0
  85. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/correct.hbs +0 -0
  86. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/create_json_obj.hbs +0 -0
  87. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
  88. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/dependencies.hbs +0 -0
  89. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/document-the-code.hbs +0 -0
  90. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/draft_rating_criteria.hbs +0 -0
  91. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/draft_rating_manual.hbs +0 -0
  92. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/draft_rating_weights_klee.hbs +0 -0
  93. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/draft_tool_usage_code.hbs +0 -0
  94. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/extract_criteria_from_reasons.hbs +0 -0
  95. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/extract_reasons_from_examples.hbs +0 -0
  96. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
  97. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/fix-bugs.hbs +0 -0
  98. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/generic_string.hbs +0 -0
  99. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/improve-performance.hbs +0 -0
  100. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/liststr.hbs +0 -0
  101. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/make_choice.hbs +0 -0
  102. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/make_judgment.hbs +0 -0
  103. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/pathstr.hbs +0 -0
  104. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/rate_fine_grind.hbs +0 -0
  105. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/refactor.hbs +0 -0
  106. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/refined_query.hbs +0 -0
  107. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/retrieved_display.hbs +0 -0
  108. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
  109. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/review_string.hbs +0 -0
  110. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/task_briefing.hbs +0 -0
  111. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/web-ctf-solver.hbs +0 -0
  112. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/write-git-commit.hbs +0 -0
  113. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/write-github-pull-request.hbs +0 -0
  114. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/templates/built-in/write-github-readme.hbs +0 -0
  115. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/tests/test_config.py +0 -0
  116. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/tests/test_models/test_action.py +0 -0
  117. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/tests/test_models/test_advanced.py +0 -0
  118. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/tests/test_models/test_generic.py +0 -0
  119. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/tests/test_models/test_role.py +0 -0
  120. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/tests/test_models/test_task.py +0 -0
  121. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/tests/test_models/test_tool.py +0 -0
  122. {fabricatio-0.2.6.dev4 → fabricatio-0.2.6.dev6}/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.6.dev4
3
+ Version: 0.2.6.dev6
4
4
  Classifier: License :: OSI Approved :: MIT License
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -2,12 +2,15 @@
2
2
 
3
3
  import asyncio
4
4
  from pathlib import Path
5
- from typing import List
5
+ from typing import TYPE_CHECKING, List
6
6
 
7
- from fabricatio import ArticleEssence, Event, Role, Task, WorkFlow, logger
7
+ from fabricatio import Event, Role, Task, WorkFlow, logger
8
8
  from fabricatio.actions.article import ExtractArticleEssence
9
9
  from fabricatio.fs.curd import dump_text, gather_files
10
10
 
11
+ if TYPE_CHECKING:
12
+ from fabricatio.models.extra import ArticleEssence
13
+
11
14
 
12
15
  async def main() -> None:
13
16
  """Main function."""
@@ -1,11 +1,14 @@
1
1
  """Example of proposing a task to a role."""
2
2
 
3
3
  import asyncio
4
- from typing import List
4
+ from typing import TYPE_CHECKING, List
5
5
 
6
- from fabricatio import ArticleEssence, Event, Role, Task, WorkFlow, logger
6
+ from fabricatio import Event, Role, Task, WorkFlow, logger
7
7
  from fabricatio.actions.article import ExtractArticleEssence
8
8
 
9
+ if TYPE_CHECKING:
10
+ from fabricatio.models.extra import ArticleEssence
11
+
9
12
 
10
13
  async def main() -> None:
11
14
  """Main function."""
@@ -57,7 +57,7 @@ class DumpText(Action):
57
57
  ["dump the text contained in `text_to_dump` to a file", "only return the path of the written file"]
58
58
  )
59
59
 
60
- path = await self.handle_fin_grind(
60
+ path = await self.handle_fine_grind(
61
61
  task_input,
62
62
  {"text_to_dump": dump_text},
63
63
  )
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "fabricatio"
3
- version = "0.2.6-dev4"
3
+ version = "0.2.6-dev6"
4
4
  description = "A LLM multi-agent framework."
5
5
  readme = "README.md"
6
6
  license = { file = "LICENSE" }
@@ -93,10 +93,11 @@ class CorrectProposal(Action):
93
93
  f"{task_input.briefing}\nExtract the path of file, which contains the article briefing that I need to read."
94
94
  )
95
95
 
96
- rprint(article_proposal.display())
97
96
  ret = None
98
97
  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()
98
+ rprint(article_proposal.display())
99
+ while not (topic := await text("What is the topic of the proposal reviewing?").ask_async()):
100
+ ...
100
101
  ret = await self.correct_obj(
101
102
  article_proposal,
102
103
  safe_text_read(input_path),
@@ -115,11 +116,13 @@ class CorrectOutline(Action):
115
116
  self,
116
117
  article_outline: ArticleOutline,
117
118
  article_proposal: ArticleProposal,
119
+
118
120
  **_,
119
121
  ) -> Optional[str]:
120
- rprint(article_outline.finalized_dump())
121
122
  ret = None
122
123
  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
+ rprint(article_outline.finalized_dump())
125
+ while not (topic := await text("What is the topic of the outline reviewing?").ask_async()):
126
+ ...
124
127
  ret = await self.correct_obj(article_outline, article_proposal.display(), topic=topic)
125
128
  return ret or article_outline
@@ -21,7 +21,7 @@ from fabricatio.models.kwargs_types import (
21
21
  LLMKwargs,
22
22
  )
23
23
  from fabricatio.models.usages import EmbeddingUsage
24
- from fabricatio.models.utils import MilvusData
24
+ from fabricatio.models.utils import MilvusData, ok
25
25
  from more_itertools.recipes import flatten, unique
26
26
  from pydantic import Field, PrivateAttr
27
27
 
@@ -60,7 +60,7 @@ class RAG(EmbeddingUsage):
60
60
  ) -> Self:
61
61
  """Initialize the Milvus client."""
62
62
  self._client = create_client(
63
- uri=milvus_uri or (self.milvus_uri or configs.rag.milvus_uri).unicode_string(),
63
+ uri=milvus_uri or ok(self.milvus_uri or configs.rag.milvus_uri).unicode_string(),
64
64
  token=milvus_token
65
65
  or (token.get_secret_value() if (token := (self.milvus_token or configs.rag.milvus_token)) else ""),
66
66
  timeout=milvus_timeout or self.milvus_timeout,
@@ -315,7 +315,7 @@ class RAG(EmbeddingUsage):
315
315
  **kwargs,
316
316
  )
317
317
 
318
- async def arefined_query(self, question: List[str] | str, **kwargs: Unpack[ChooseKwargs]) -> List[str]:
318
+ async def arefined_query(self, question: List[str] | str, **kwargs: Unpack[ChooseKwargs]) -> Optional[List[str]]:
319
319
  """Refines the given question using a template.
320
320
 
321
321
  Args:
@@ -84,7 +84,7 @@ class HandleTask(WithBriefing, ToolBoxUsage):
84
84
  **self.prepend(cast(Dict[str, Any], kwargs)),
85
85
  )
86
86
 
87
- async def handle_fin_grind(
87
+ async def handle_fine_grind(
88
88
  self,
89
89
  task: Task,
90
90
  data: Dict[str, Any],
@@ -110,4 +110,4 @@ class HandleTask(WithBriefing, ToolBoxUsage):
110
110
 
111
111
  async def handle(self, task: Task, data: Dict[str, Any], **kwargs: Unpack[ValidateKwargs]) -> Optional[Tuple]:
112
112
  """Asynchronously handles a task based on a given task object and parameters."""
113
- return await self.handle_fin_grind(task, data, **kwargs)
113
+ return await self.handle_fine_grind(task, data, **kwargs)
@@ -48,37 +48,37 @@ class LLMConfig(BaseModel):
48
48
  """
49
49
 
50
50
  model_config = ConfigDict(use_attribute_docstrings=True)
51
- api_endpoint: HttpUrl = Field(default=HttpUrl("https://api.openai.com"))
51
+ api_endpoint: Optional[HttpUrl] = Field(default=HttpUrl("https://api.openai.com"))
52
52
  """OpenAI API Endpoint."""
53
53
 
54
- api_key: SecretStr = Field(default=SecretStr(""))
54
+ api_key: Optional[SecretStr] = Field(default=SecretStr("sk-setyourkey"))
55
55
  """OpenAI API key. Empty by default for security reasons, should be set before use."""
56
56
 
57
- timeout: PositiveInt = Field(default=300)
57
+ timeout: Optional[PositiveInt] = Field(default=300)
58
58
  """The timeout of the LLM model in seconds. Default is 300 seconds as per request."""
59
59
 
60
- max_retries: PositiveInt = Field(default=3)
60
+ max_retries: Optional[PositiveInt] = Field(default=3)
61
61
  """The maximum number of retries. Default is 3 retries."""
62
62
 
63
- model: str = Field(default="gpt-3.5-turbo")
63
+ model: Optional[str] = Field(default="gpt-3.5-turbo")
64
64
  """The LLM model name. Set to 'gpt-3.5-turbo' as per request."""
65
65
 
66
- temperature: NonNegativeFloat = Field(default=1.0)
66
+ temperature: Optional[NonNegativeFloat] = Field(default=1.0)
67
67
  """The temperature of the LLM model. Controls randomness in generation. Set to 1.0 as per request."""
68
68
 
69
- stop_sign: str | List[str] = Field(default_factory=lambda: ["\n\n\n", "User:"])
69
+ stop_sign: Optional[str | List[str]] = Field(default=None)
70
70
  """The stop sign of the LLM model. No default stop sign specified."""
71
71
 
72
- top_p: NonNegativeFloat = Field(default=0.35)
72
+ top_p: Optional[NonNegativeFloat] = Field(default=0.35)
73
73
  """The top p of the LLM model. Controls diversity via nucleus sampling. Set to 0.35 as per request."""
74
74
 
75
- generation_count: PositiveInt = Field(default=1)
75
+ generation_count: Optional[PositiveInt] = Field(default=1)
76
76
  """The number of generations to generate. Default is 1."""
77
77
 
78
- stream: bool = Field(default=False)
78
+ stream: Optional[bool] = Field(default=False)
79
79
  """Whether to stream the LLM model's response. Default is False."""
80
80
 
81
- max_tokens: PositiveInt = Field(default=8192)
81
+ max_tokens: Optional[PositiveInt] = Field(default=None)
82
82
  """The maximum number of tokens to generate. Set to 8192 as per request."""
83
83
 
84
84
  rpm: Optional[PositiveInt] = Field(default=100)
@@ -93,7 +93,7 @@ class EmbeddingConfig(BaseModel):
93
93
 
94
94
  model_config = ConfigDict(use_attribute_docstrings=True)
95
95
 
96
- model: str = Field(default="text-embedding-ada-002")
96
+ model: Optional[str] = Field(default="text-embedding-ada-002")
97
97
  """The embedding model name. """
98
98
 
99
99
  dimensions: Optional[PositiveInt] = Field(default=None)
@@ -102,10 +102,10 @@ class EmbeddingConfig(BaseModel):
102
102
  timeout: Optional[PositiveInt] = Field(default=None)
103
103
  """The timeout of the embedding model in seconds."""
104
104
 
105
- max_sequence_length: PositiveInt = Field(default=8192)
105
+ max_sequence_length: Optional[PositiveInt] = Field(default=8192)
106
106
  """The maximum sequence length of the embedding model. Default is 8192 as per request."""
107
107
 
108
- caching: bool = Field(default=False)
108
+ caching: Optional[bool] = Field(default=False)
109
109
  """Whether to cache the embedding. Default is False."""
110
110
 
111
111
  api_endpoint: Optional[HttpUrl] = None
@@ -148,13 +148,13 @@ class DebugConfig(BaseModel):
148
148
  log_level: Literal["DEBUG", "INFO", "SUCCESS", "WARNING", "ERROR", "CRITICAL"] = Field(default="INFO")
149
149
  """The log level of the application."""
150
150
 
151
- log_file: FilePath = Field(default=Path(rf"{ROAMING_DIR}\fabricatio.log"))
151
+ log_file: FilePath = Field(default=Path(rf"{ROAMING_DIR}\fabricatio.log"), frozen=True)
152
152
  """The log file of the application."""
153
153
 
154
- rotation: int = Field(default=1)
154
+ rotation: int = Field(default=1, frozen=True)
155
155
  """The rotation of the log file. in weeks."""
156
156
 
157
- retention: int = Field(default=2)
157
+ retention: int = Field(default=2, frozen=True)
158
158
  """The retention of the log file. in weeks."""
159
159
 
160
160
  streaming_visible: bool = Field(default=False)
@@ -232,6 +232,9 @@ class TemplateConfig(BaseModel):
232
232
  correct_template: str = Field(default="correct")
233
233
  """The name of the correct template which will be used to correct a string."""
234
234
 
235
+ co_validation_template: str = Field(default="co_validation")
236
+ """The name of the co-validation template which will be used to co-validate a string."""
237
+
235
238
 
236
239
  class MagikaConfig(BaseModel):
237
240
  """Magika configuration class."""
@@ -272,7 +275,7 @@ class RagConfig(BaseModel):
272
275
 
273
276
  model_config = ConfigDict(use_attribute_docstrings=True)
274
277
 
275
- milvus_uri: HttpUrl = Field(default=HttpUrl("http://localhost:19530"))
278
+ milvus_uri: Optional[HttpUrl] = Field(default=HttpUrl("http://localhost:19530"))
276
279
  """The URI of the Milvus server."""
277
280
  milvus_timeout: Optional[PositiveFloat] = Field(default=None)
278
281
  """The timeout of the Milvus server."""
@@ -0,0 +1,218 @@
1
+ """Module that contains the classes for actions and workflows.
2
+
3
+ This module defines the Action and WorkFlow classes, which are used for
4
+ creating and executing sequences of actions in a task-based context.
5
+ """
6
+
7
+ import traceback
8
+ from abc import abstractmethod
9
+ from asyncio import Queue, create_task
10
+ from typing import Any, Dict, Self, Tuple, Type, Union, final
11
+
12
+ from fabricatio.capabilities.correct import Correct
13
+ from fabricatio.capabilities.task import HandleTask, ProposeTask
14
+ from fabricatio.journal import logger
15
+ from fabricatio.models.generic import WithBriefing
16
+ from fabricatio.models.task import Task
17
+ from fabricatio.models.usages import ToolBoxUsage
18
+ from pydantic import Field, PrivateAttr
19
+
20
+
21
+ class Action(HandleTask, ProposeTask, Correct):
22
+ """Class that represents an action to be executed in a workflow.
23
+
24
+ Actions are the atomic units of work in a workflow. Each action performs
25
+ a specific operation and can modify the shared context data.
26
+ """
27
+
28
+ name: str = Field(default="")
29
+ """The name of the action."""
30
+
31
+ description: str = Field(default="")
32
+ """The description of the action."""
33
+
34
+ personality: str = Field(default="")
35
+ """The personality traits or context for the action executor."""
36
+
37
+ output_key: str = Field(default="")
38
+ """The key used to store this action's output in the context dictionary."""
39
+
40
+ @final
41
+ def model_post_init(self, __context: Any) -> None:
42
+ """Initialize the action by setting default name and description if not provided.
43
+
44
+ Args:
45
+ __context: The context to be used for initialization.
46
+ """
47
+ self.name = self.name or self.__class__.__name__
48
+ self.description = self.description or self.__class__.__doc__ or ""
49
+
50
+ @abstractmethod
51
+ async def _execute(self, **cxt) -> Any:
52
+ """Execute the action logic with the provided context arguments.
53
+
54
+ This method must be implemented by subclasses to define the actual behavior.
55
+
56
+ Args:
57
+ **cxt: The context dictionary containing input and output data.
58
+
59
+ Returns:
60
+ Any: The result of the action execution.
61
+ """
62
+ pass
63
+
64
+ @final
65
+ async def act(self, cxt: Dict[str, Any]) -> Dict[str, Any]:
66
+ """Perform the action and update the context with results.
67
+
68
+ Args:
69
+ cxt: The context dictionary containing input and output data.
70
+
71
+ Returns:
72
+ Dict[str, Any]: The updated context dictionary.
73
+ """
74
+ ret = await self._execute(**cxt)
75
+
76
+ if self.output_key:
77
+ logger.debug(f"Setting output: {self.output_key}")
78
+ cxt[self.output_key] = ret
79
+
80
+ return cxt
81
+
82
+ @property
83
+ def briefing(self) -> str:
84
+ """Return a formatted description of the action including personality context if available.
85
+
86
+ Returns:
87
+ str: Formatted briefing text with personality and action description.
88
+ """
89
+ if self.personality:
90
+ return f"## Your personality: \n{self.personality}\n# The action you are going to perform: \n{super().briefing}"
91
+ return f"# The action you are going to perform: \n{super().briefing}"
92
+
93
+
94
+ class WorkFlow(WithBriefing, ToolBoxUsage):
95
+ """Class that represents a sequence of actions to be executed for a task.
96
+
97
+ A workflow manages the execution of multiple actions in sequence, passing
98
+ a shared context between them and handling task lifecycle events.
99
+ """
100
+
101
+ _context: Queue[Dict[str, Any]] = PrivateAttr(default_factory=lambda: Queue(maxsize=1))
102
+ """Queue for storing the workflow execution context."""
103
+
104
+ _instances: Tuple[Action, ...] = PrivateAttr(default_factory=tuple)
105
+ """Instantiated action objects to be executed in this workflow."""
106
+
107
+ steps: Tuple[Union[Type[Action], Action], ...] = Field(...)
108
+ """The sequence of actions to be executed, can be action classes or instances."""
109
+
110
+ task_input_key: str = Field(default="task_input")
111
+ """Key used to store the input task in the context dictionary."""
112
+
113
+ task_output_key: str = Field(default="task_output")
114
+ """Key used to extract the final result from the context dictionary."""
115
+
116
+ extra_init_context: Dict[str, Any] = Field(default_factory=dict, frozen=True)
117
+ """Additional initial context values to be included at workflow start."""
118
+
119
+ def model_post_init(self, __context: Any) -> None:
120
+ """Initialize the workflow by instantiating any action classes.
121
+
122
+ Args:
123
+ __context: The context to be used for initialization.
124
+ """
125
+ # Convert any action classes to instances
126
+ self._instances = tuple(step if isinstance(step, Action) else step() for step in self.steps)
127
+
128
+ def inject_personality(self, personality: str) -> Self:
129
+ """Set the personality for all actions that don't have one defined.
130
+
131
+ Args:
132
+ personality: The personality text to inject.
133
+
134
+ Returns:
135
+ Self: The workflow instance for method chaining.
136
+ """
137
+ for action in filter(lambda a: not a.personality, self._instances):
138
+ action.personality = personality
139
+ return self
140
+
141
+ async def serve(self, task: Task) -> None:
142
+ """Execute the workflow to fulfill the given task.
143
+
144
+ This method manages the complete lifecycle of processing a task through
145
+ the workflow's sequence of actions.
146
+
147
+ Args:
148
+ task: The task to be processed.
149
+ """
150
+ await task.start()
151
+ await self._init_context(task)
152
+
153
+ current_action = None
154
+ try:
155
+ # Process each action in sequence
156
+ for step in self._instances:
157
+ current_action = step.name
158
+ logger.debug(f"Executing step: {current_action}")
159
+
160
+ # Get current context and execute action
161
+ context = await self._context.get()
162
+ act_task = create_task(step.act(context))
163
+
164
+ # Handle task cancellation
165
+ if task.is_cancelled():
166
+ act_task.cancel(f"Cancelled by task: {task.name}")
167
+ break
168
+
169
+ # Update context with modified values
170
+ modified_ctx = await act_task
171
+ await self._context.put(modified_ctx)
172
+
173
+ logger.info(f"Finished executing workflow: {self.name}")
174
+
175
+ # Get final context and extract result
176
+ final_ctx = await self._context.get()
177
+ result = final_ctx.get(self.task_output_key)
178
+
179
+ if self.task_output_key not in final_ctx:
180
+ logger.warning(
181
+ f"Task output key: {self.task_output_key} not found in the context, None will be returned. "
182
+ f"You can check if `Action.output_key` is set the same as `WorkFlow.task_output_key`."
183
+ )
184
+
185
+ await task.finish(result)
186
+
187
+ except RuntimeError as e:
188
+ logger.error(f"Error during task: {current_action} execution: {e}")
189
+ logger.error(traceback.format_exc())
190
+ await task.fail()
191
+
192
+ async def _init_context[T](self, task: Task[T]) -> None:
193
+ """Initialize the context dictionary for workflow execution.
194
+
195
+ Args:
196
+ task: The task being served by this workflow.
197
+ """
198
+ logger.debug(f"Initializing context for workflow: {self.name}")
199
+ initial_context = {self.task_input_key: task, **dict(self.extra_init_context)}
200
+ await self._context.put(initial_context)
201
+
202
+ def steps_fallback_to_self(self) -> Self:
203
+ """Configure all steps to use this workflow's configuration as fallback.
204
+
205
+ Returns:
206
+ Self: The workflow instance for method chaining.
207
+ """
208
+ self.hold_to(self._instances)
209
+ return self
210
+
211
+ def steps_supply_tools_from_self(self) -> Self:
212
+ """Provide this workflow's tools to all steps in the workflow.
213
+
214
+ Returns:
215
+ Self: The workflow instance for method chaining.
216
+ """
217
+ self.provide_tools_to(self._instances)
218
+ return self