fabricatio 0.2.4.dev2__cp312-cp312-win_amd64.whl → 0.2.5__cp312-cp312-win_amd64.whl

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 (39) hide show
  1. fabricatio/__init__.py +14 -5
  2. fabricatio/_rust.cp312-win_amd64.pyd +0 -0
  3. fabricatio/_rust.pyi +65 -16
  4. fabricatio/_rust_instances.py +2 -0
  5. fabricatio/actions/article.py +46 -14
  6. fabricatio/actions/output.py +21 -0
  7. fabricatio/actions/rag.py +1 -1
  8. fabricatio/capabilities/propose.py +14 -20
  9. fabricatio/capabilities/rag.py +85 -26
  10. fabricatio/capabilities/rating.py +59 -51
  11. fabricatio/capabilities/review.py +241 -0
  12. fabricatio/capabilities/task.py +7 -8
  13. fabricatio/config.py +36 -4
  14. fabricatio/fs/__init__.py +13 -1
  15. fabricatio/fs/curd.py +27 -8
  16. fabricatio/fs/readers.py +6 -3
  17. fabricatio/journal.py +1 -1
  18. fabricatio/models/action.py +6 -8
  19. fabricatio/models/events.py +6 -4
  20. fabricatio/models/extra.py +100 -25
  21. fabricatio/models/generic.py +56 -4
  22. fabricatio/models/kwargs_types.py +123 -35
  23. fabricatio/models/role.py +3 -3
  24. fabricatio/models/task.py +0 -14
  25. fabricatio/models/tool.py +7 -6
  26. fabricatio/models/usages.py +144 -101
  27. fabricatio/parser.py +26 -5
  28. fabricatio/toolboxes/__init__.py +1 -3
  29. fabricatio/toolboxes/fs.py +17 -1
  30. fabricatio/workflows/articles.py +10 -6
  31. fabricatio/workflows/rag.py +11 -0
  32. fabricatio-0.2.5.data/scripts/tdown.exe +0 -0
  33. {fabricatio-0.2.4.dev2.dist-info → fabricatio-0.2.5.dist-info}/METADATA +2 -1
  34. fabricatio-0.2.5.dist-info/RECORD +41 -0
  35. fabricatio/toolboxes/task.py +0 -6
  36. fabricatio-0.2.4.dev2.data/scripts/tdown.exe +0 -0
  37. fabricatio-0.2.4.dev2.dist-info/RECORD +0 -39
  38. {fabricatio-0.2.4.dev2.dist-info → fabricatio-0.2.5.dist-info}/WHEEL +0 -0
  39. {fabricatio-0.2.4.dev2.dist-info → fabricatio-0.2.5.dist-info}/licenses/LICENSE +0 -0
@@ -1,59 +1,147 @@
1
1
  """This module contains the types for the keyword arguments of the methods in the models module."""
2
2
 
3
- from typing import List, NotRequired, TypedDict
3
+ from typing import Any, TypedDict
4
4
 
5
- from pydantic import NonNegativeFloat, NonNegativeInt, PositiveInt
5
+ from litellm.caching.caching import CacheMode
6
+ from litellm.types.caching import CachingSupportedCallTypes
6
7
 
7
8
 
8
- class CollectionSimpleConfigKwargs(TypedDict):
9
- """A type representing the configuration for a collection."""
9
+ class CollectionSimpleConfigKwargs(TypedDict, total=False):
10
+ """Configuration parameters for a vector collection.
10
11
 
11
- dimension: NotRequired[int]
12
- timeout: NotRequired[float]
12
+ These arguments are typically used when configuring connections to vector databases.
13
+ """
13
14
 
15
+ dimension: int|None
16
+ timeout: float
14
17
 
15
- class FetchKwargs(TypedDict):
16
- """A type representing the keyword arguments for the fetch method."""
17
18
 
18
- similarity_threshold: NotRequired[float]
19
- result_per_query: NotRequired[int]
19
+ class FetchKwargs(TypedDict, total=False):
20
+ """Arguments for fetching data from vector collections.
20
21
 
22
+ Controls how data is retrieved from vector databases, including filtering
23
+ and result limiting parameters.
24
+ """
21
25
 
22
- class EmbeddingKwargs(TypedDict):
23
- """A type representing the keyword arguments for the embedding method."""
26
+ collection_name: str|None
27
+ similarity_threshold: float
28
+ result_per_query: int
24
29
 
25
- model: NotRequired[str]
26
- dimensions: NotRequired[int]
27
- timeout: NotRequired[PositiveInt]
28
- caching: NotRequired[bool]
29
30
 
31
+ class EmbeddingKwargs(TypedDict, total=False):
32
+ """Configuration parameters for text embedding operations.
30
33
 
31
- class LLMKwargs(TypedDict):
32
- """A type representing the keyword arguments for the LLM (Large Language Model) usage."""
34
+ These settings control the behavior of embedding models that convert text
35
+ to vector representations.
36
+ """
33
37
 
34
- model: NotRequired[str]
35
- temperature: NotRequired[NonNegativeFloat]
36
- stop: NotRequired[str | List[str]]
37
- top_p: NotRequired[NonNegativeFloat]
38
- max_tokens: NotRequired[PositiveInt]
39
- stream: NotRequired[bool]
40
- timeout: NotRequired[PositiveInt]
41
- max_retries: NotRequired[PositiveInt]
38
+ model: str
39
+ dimensions: int
40
+ timeout: int
41
+ caching: bool
42
42
 
43
43
 
44
- class ValidateKwargs(LLMKwargs):
45
- """A type representing the keyword arguments for the validate method."""
44
+ class LLMKwargs(TypedDict, total=False):
45
+ """Configuration parameters for language model inference.
46
46
 
47
- max_validations: NotRequired[PositiveInt]
47
+ These arguments control the behavior of large language model calls,
48
+ including generation parameters and caching options.
49
+ """
48
50
 
51
+ model: str
52
+ temperature: float
53
+ stop: str | list[str]
54
+ top_p: float
55
+ max_tokens: int
56
+ stream: bool
57
+ timeout: int
58
+ max_retries: int
59
+ no_cache: bool # if the req uses cache in this call
60
+ no_store: bool # If store the response of this call to cache
61
+ cache_ttl: int # how long the stored cache is alive, in seconds
62
+ s_maxage: int # max accepted age of cached response, in seconds
49
63
 
50
- class GenerateKwargs(ValidateKwargs):
51
- """A type representing the keyword arguments for the generate method."""
52
64
 
53
- system_message: NotRequired[str]
65
+ class GenerateKwargs(LLMKwargs, total=False):
66
+ """Arguments for content generation operations.
54
67
 
68
+ Extends LLMKwargs with additional parameters specific to generation tasks,
69
+ such as the number of generated items and the system message.
70
+ """
55
71
 
56
- class ChooseKwargs(GenerateKwargs):
57
- """A type representing the keyword arguments for the choose method."""
72
+ system_message: str
58
73
 
59
- k: NotRequired[NonNegativeInt]
74
+
75
+ class ValidateKwargs[T](GenerateKwargs, total=False):
76
+ """Arguments for content validation operations.
77
+
78
+ Extends LLMKwargs with additional parameters specific to validation tasks,
79
+ such as limiting the number of validation attempts.
80
+ """
81
+
82
+ default: T
83
+ max_validations: int
84
+
85
+
86
+ # noinspection PyTypedDict
87
+ class ReviewKwargs[T](ValidateKwargs[T], total=False):
88
+ """Arguments for content review operations.
89
+
90
+ Extends GenerateKwargs with parameters for evaluating content against
91
+ specific topics and review criteria.
92
+ """
93
+
94
+ topic: str
95
+ criteria: set[str]
96
+
97
+
98
+ # noinspection PyTypedDict
99
+ class ChooseKwargs[T](ValidateKwargs[T], total=False):
100
+ """Arguments for selection operations.
101
+
102
+ Extends GenerateKwargs with parameters for selecting among options,
103
+ such as the number of items to choose.
104
+ """
105
+
106
+ k: int
107
+
108
+
109
+ class CacheKwargs(TypedDict, total=False):
110
+ """Configuration parameters for the caching system.
111
+
112
+ These arguments control the behavior of various caching backends,
113
+ including in-memory, Redis, S3, and vector database caching options.
114
+ """
115
+
116
+ mode: CacheMode # when default_on cache is always on, when default_off cache is opt in
117
+ host: str
118
+ port: str
119
+ password: str
120
+ namespace: str
121
+ ttl: float
122
+ default_in_memory_ttl: float
123
+ default_in_redis_ttl: float
124
+ similarity_threshold: float
125
+ supported_call_types: list[CachingSupportedCallTypes]
126
+ # s3 Bucket, boto3 configuration
127
+ s3_bucket_name: str
128
+ s3_region_name: str
129
+ s3_api_version: str
130
+ s3_use_ssl: bool
131
+ s3_verify: bool | str
132
+ s3_endpoint_url: str
133
+ s3_aws_access_key_id: str
134
+ s3_aws_secret_access_key: str
135
+ s3_aws_session_token: str
136
+ s3_config: Any
137
+ s3_path: str
138
+ redis_semantic_cache_use_async: bool
139
+ redis_semantic_cache_embedding_model: str
140
+ redis_flush_size: int
141
+ redis_startup_nodes: list
142
+ disk_cache_dir: Any
143
+ qdrant_api_base: str
144
+ qdrant_api_key: str
145
+ qdrant_collection_name: str
146
+ qdrant_quantization_config: str
147
+ qdrant_semantic_cache_embedding_model: str
fabricatio/models/role.py CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  from typing import Any, Self, Set
4
4
 
5
- from fabricatio.capabilities.rating import GiveRating
5
+ from fabricatio.capabilities.review import Review
6
6
  from fabricatio.capabilities.task import HandleTask, ProposeTask
7
7
  from fabricatio.core import env
8
8
  from fabricatio.journal import logger
@@ -12,10 +12,10 @@ from fabricatio.models.tool import ToolBox
12
12
  from pydantic import Field
13
13
 
14
14
 
15
- class Role(ProposeTask, HandleTask, GiveRating):
15
+ class Role(ProposeTask, HandleTask, Review):
16
16
  """Class that represents a role with a registry of events and workflows."""
17
17
 
18
- registry: dict[Event | str, WorkFlow] = Field(...)
18
+ registry: dict[Event | str, WorkFlow] = Field(default_factory=dict)
19
19
  """ The registry of events and workflows."""
20
20
 
21
21
  toolboxes: Set[ToolBox] = Field(default_factory=set)
fabricatio/models/task.py CHANGED
@@ -83,20 +83,6 @@ class Task[T](WithBriefing, ProposedAble, WithDependency):
83
83
  self.namespace = self._namespace.segments
84
84
  return self
85
85
 
86
- @classmethod
87
- def simple_task(cls, name: str, goal: List[str], description: str) -> Self:
88
- """Create a simple task with a name, goal, and description.
89
-
90
- Args:
91
- name (str): The name of the task.
92
- goal (List[str]): The goal of the task.
93
- description (str): The description of the task.
94
-
95
- Returns:
96
- Task: A new instance of the `Task` class.
97
- """
98
- return cls(name=name, goals=goal, description=description)
99
-
100
86
  def update_task(self, goal: Optional[List[str] | str] = None, description: Optional[str] = None) -> Self:
101
87
  """Update the goal and description of the task.
102
88
 
fabricatio/models/tool.py CHANGED
@@ -4,10 +4,10 @@ from importlib.machinery import ModuleSpec
4
4
  from importlib.util import module_from_spec
5
5
  from inspect import iscoroutinefunction, signature
6
6
  from types import CodeType, ModuleType
7
- from typing import Any, Callable, Dict, List, Optional, Self, overload
7
+ from typing import Any, Callable, Dict, List, Optional, Self, cast, overload
8
8
 
9
9
  from fabricatio.config import configs
10
- from fabricatio.decorators import use_temp_module
10
+ from fabricatio.decorators import logging_execution_info, use_temp_module
11
11
  from fabricatio.journal import logger
12
12
  from fabricatio.models.generic import WithBriefing
13
13
  from pydantic import BaseModel, ConfigDict, Field
@@ -31,6 +31,7 @@ class Tool[**P, R](WithBriefing):
31
31
 
32
32
  if not self.name:
33
33
  raise RuntimeError("The tool must have a source function.")
34
+
34
35
  self.description = self.description or self.source.__doc__ or ""
35
36
  self.description = self.description.strip()
36
37
 
@@ -84,7 +85,7 @@ class ToolBox(WithBriefing):
84
85
  Returns:
85
86
  Self: The current instance of the toolbox.
86
87
  """
87
- self.tools.append(Tool(source=func))
88
+ self.collect_tool(logging_execution_info(func))
88
89
  return self
89
90
 
90
91
  @property
@@ -135,7 +136,7 @@ class ToolExecutor(BaseModel):
135
136
 
136
137
  def inject_tools[M: ModuleType](self, module: Optional[M] = None) -> M:
137
138
  """Inject the tools into the provided module or default."""
138
- module = module or module_from_spec(spec=ModuleSpec(name=configs.toolbox.tool_module_name, loader=None))
139
+ module = module or cast(M, module_from_spec(spec=ModuleSpec(name=configs.toolbox.tool_module_name, loader=None)))
139
140
  for tool in self.candidates:
140
141
  logger.debug(f"Injecting tool: {tool.name}")
141
142
  setattr(module, tool.name, tool.invoke)
@@ -143,7 +144,7 @@ class ToolExecutor(BaseModel):
143
144
 
144
145
  def inject_data[M: ModuleType](self, module: Optional[M] = None) -> M:
145
146
  """Inject the data into the provided module or default."""
146
- module = module or module_from_spec(spec=ModuleSpec(name=configs.toolbox.data_module_name, loader=None))
147
+ module = module or cast(M,module_from_spec(spec=ModuleSpec(name=configs.toolbox.data_module_name, loader=None)))
147
148
  for key, value in self.data.items():
148
149
  logger.debug(f"Injecting data: {key}")
149
150
  setattr(module, key, value)
@@ -183,6 +184,6 @@ class ToolExecutor(BaseModel):
183
184
  tools = []
184
185
  while tool_name := recipe.pop(0):
185
186
  for toolbox in toolboxes:
186
- tools.append(toolbox[tool_name])
187
+ tools.append(toolbox.get(tool_name))
187
188
 
188
189
  return cls(candidates=tools)