fabricatio 0.2.3.dev1__tar.gz → 0.2.3.dev2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/PKG-INFO +1 -1
  2. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/pyproject.toml +1 -1
  3. fabricatio-0.2.3.dev2/python/fabricatio/capabilities/rag.py +179 -0
  4. fabricatio-0.2.3.dev2/templates.tar.gz +0 -0
  5. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/uv.lock +1 -1
  6. fabricatio-0.2.3.dev1/python/fabricatio/capabilities/rag.py +0 -46
  7. fabricatio-0.2.3.dev1/templates.tar.gz +0 -0
  8. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/.github/workflows/build-package.yaml +0 -0
  9. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/.github/workflows/ruff.yaml +0 -0
  10. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/.github/workflows/tests.yaml +0 -0
  11. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/.gitignore +0 -0
  12. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/.python-version +0 -0
  13. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/Cargo.lock +0 -0
  14. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/Cargo.toml +0 -0
  15. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/LICENSE +0 -0
  16. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/Makefile +0 -0
  17. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/README.md +0 -0
  18. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/examples/llm_usages/llm_usage.py +0 -0
  19. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/examples/make_a_rating/rating.py +0 -0
  20. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/examples/make_diary/commits.json +0 -0
  21. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/examples/make_diary/diary.py +0 -0
  22. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/examples/minor/hello_fabricatio.py +0 -0
  23. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/examples/propose_task/propose.py +0 -0
  24. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/examples/simple_chat/chat.py +0 -0
  25. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/examples/task_handle/handle_task.py +0 -0
  26. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/__init__.py +0 -0
  27. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/_rust.pyi +0 -0
  28. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/_rust_instances.py +0 -0
  29. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/actions/__init__.py +0 -0
  30. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/actions/communication.py +0 -0
  31. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/actions/transmission.py +0 -0
  32. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/capabilities/rating.py +0 -0
  33. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/capabilities/task.py +0 -0
  34. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/config.py +0 -0
  35. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/core.py +0 -0
  36. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/decorators.py +0 -0
  37. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/fs/__init__.py +0 -0
  38. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/fs/curd.py +0 -0
  39. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/fs/readers.py +0 -0
  40. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/journal.py +0 -0
  41. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/models/action.py +0 -0
  42. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/models/events.py +0 -0
  43. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/models/generic.py +0 -0
  44. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/models/kwargs_types.py +0 -0
  45. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/models/role.py +0 -0
  46. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/models/task.py +0 -0
  47. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/models/tool.py +0 -0
  48. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/models/usages.py +0 -0
  49. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/models/utils.py +0 -0
  50. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/parser.py +0 -0
  51. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/py.typed +0 -0
  52. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/toolboxes/__init__.py +0 -0
  53. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/toolboxes/arithmetic.py +0 -0
  54. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/toolboxes/fs.py +0 -0
  55. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/python/fabricatio/toolboxes/task.py +0 -0
  56. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/src/hash.rs +0 -0
  57. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/src/lib.rs +0 -0
  58. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/src/templates.rs +0 -0
  59. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
  60. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/claude-xml.hbs +0 -0
  61. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/clean-up-code.hbs +0 -0
  62. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
  63. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/dependencies.hbs +0 -0
  64. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/document-the-code.hbs +0 -0
  65. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/draft_rating_criteria.hbs +0 -0
  66. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/draft_rating_manual.hbs +0 -0
  67. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/draft_rating_weights_klee.hbs +0 -0
  68. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/draft_tool_usage_code.hbs +0 -0
  69. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/extract_criteria_from_reasons.hbs +0 -0
  70. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/extract_reasons_from_examples.hbs +0 -0
  71. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
  72. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/fix-bugs.hbs +0 -0
  73. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/improve-performance.hbs +0 -0
  74. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/make_choice.hbs +0 -0
  75. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/make_judgment.hbs +0 -0
  76. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/propose_task.hbs +0 -0
  77. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/rate_fine_grind.hbs +0 -0
  78. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/refactor.hbs +0 -0
  79. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
  80. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/task_briefing.hbs +0 -0
  81. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/web-ctf-solver.hbs +0 -0
  82. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/write-git-commit.hbs +0 -0
  83. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/write-github-pull-request.hbs +0 -0
  84. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/templates/built-in/write-github-readme.hbs +0 -0
  85. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/tests/test_config.py +0 -0
  86. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/tests/test_models/test_action.py +0 -0
  87. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/tests/test_models/test_advanced.py +0 -0
  88. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/tests/test_models/test_generic.py +0 -0
  89. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/tests/test_models/test_role.py +0 -0
  90. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/tests/test_models/test_task.py +0 -0
  91. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/tests/test_models/test_tool.py +0 -0
  92. {fabricatio-0.2.3.dev1 → fabricatio-0.2.3.dev2}/tests/test_models/test_usages.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fabricatio
3
- Version: 0.2.3.dev1
3
+ Version: 0.2.3.dev2
4
4
  Classifier: License :: OSI Approved :: MIT License
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "fabricatio"
3
- version = "0.2.3-dev1"
3
+ version = "0.2.3-dev2"
4
4
  description = "A LLM multi-agent framework."
5
5
  readme = "README.md"
6
6
  license = { file = "LICENSE" }
@@ -0,0 +1,179 @@
1
+ """A module for the RAG (Retrieval Augmented Generation) model."""
2
+
3
+ from operator import itemgetter
4
+ from os import PathLike
5
+ from pathlib import Path
6
+ from typing import Any, Callable, Dict, List, Optional, Self, Union
7
+
8
+ from fabricatio.config import configs
9
+ from fabricatio.models.usages import LLMUsage
10
+ from fabricatio.models.utils import MilvusData
11
+ from more_itertools.recipes import flatten
12
+
13
+ try:
14
+ from pymilvus import MilvusClient
15
+ except ImportError as e:
16
+ raise RuntimeError("pymilvus is not installed. Have you installed `fabricatio[rag]` instead of `fabricatio`") from e
17
+ from pydantic import PrivateAttr
18
+
19
+
20
+ class Rag(LLMUsage):
21
+ """A class representing the RAG (Retrieval Augmented Generation) model."""
22
+
23
+ _client: MilvusClient = PrivateAttr(
24
+ default=MilvusClient(
25
+ uri=configs.rag.milvus_uri.unicode_string(),
26
+ token=configs.rag.milvus_token.get_secret_value(),
27
+ timeout=configs.rag.milvus_timeout,
28
+ ),
29
+ )
30
+ _target_collection: Optional[str] = PrivateAttr(default=None)
31
+
32
+ @property
33
+ def client(self) -> MilvusClient:
34
+ """The Milvus client."""
35
+ return self._client
36
+
37
+ def view(self, collection_name: str, create: bool = False) -> Self:
38
+ """View the specified collection.
39
+
40
+ Args:
41
+ collection_name (str): The name of the collection.
42
+ create (bool): Whether to create the collection if it does not exist.
43
+ """
44
+ if create and self._client.has_collection(collection_name):
45
+ self._client.create_collection(collection_name)
46
+
47
+ self._target_collection = collection_name
48
+ return self
49
+
50
+ def quit_view(self) -> Self:
51
+ """Quit the current view.
52
+
53
+ Returns:
54
+ Self: The current instance, allowing for method chaining.
55
+ """
56
+ self._target_collection = None
57
+ return self
58
+
59
+ @property
60
+ def viewing_collection(self) -> Optional[str]:
61
+ """Get the name of the collection being viewed.
62
+
63
+ Returns:
64
+ Optional[str]: The name of the collection being viewed.
65
+ """
66
+ return self._target_collection
67
+
68
+ @property
69
+ def safe_viewing_collection(self) -> str:
70
+ """Get the name of the collection being viewed, raise an error if not viewing any collection.
71
+
72
+ Returns:
73
+ str: The name of the collection being viewed.
74
+ """
75
+ if self._target_collection is None:
76
+ raise RuntimeError("No collection is being viewed. Have you called `self.view()`?")
77
+ return self._target_collection
78
+
79
+ def add_document[D: Union[Dict[str, Any], MilvusData]](
80
+ self, data: D | List[D], collection_name: Optional[str] = None
81
+ ) -> Self:
82
+ """Adds a document to the specified collection.
83
+
84
+ Args:
85
+ data (Union[Dict[str, Any], MilvusData] | List[Union[Dict[str, Any], MilvusData]]): The data to be added to the collection.
86
+ collection_name (Optional[str]): The name of the collection. If not provided, the currently viewed collection is used.
87
+
88
+ Returns:
89
+ Self: The current instance, allowing for method chaining.
90
+ """
91
+ if isinstance(data, MilvusData):
92
+ data = data.prepare_insertion()
93
+ if isinstance(data, list):
94
+ data = [d.prepare_insertion() if isinstance(d, MilvusData) else d for d in data]
95
+ self._client.insert(collection_name or self.safe_viewing_collection, data)
96
+ return self
97
+
98
+ def consume(
99
+ self, source: PathLike, reader: Callable[[PathLike], MilvusData], collection_name: Optional[str] = None
100
+ ) -> Self:
101
+ """Consume a file and add its content to the collection.
102
+
103
+ Args:
104
+ source (PathLike): The path to the file to be consumed.
105
+ reader (Callable[[PathLike], MilvusData]): The reader function to read the file.
106
+ collection_name (Optional[str]): The name of the collection. If not provided, the currently viewed collection is used.
107
+
108
+ Returns:
109
+ Self: The current instance, allowing for method chaining.
110
+ """
111
+ data = reader(Path(source))
112
+ self.add_document(data, collection_name or self.safe_viewing_collection)
113
+ return self
114
+
115
+ async def afetch_document(
116
+ self,
117
+ vecs: List[List[float]],
118
+ desired_fields: List[str] | str,
119
+ collection_name: Optional[str] = None,
120
+ result_per_query: int = 10,
121
+ ) -> List[Dict[str, Any]] | List[Any]:
122
+ """Fetch data from the collection.
123
+
124
+ Args:
125
+ vecs (List[List[float]]): The vectors to search for.
126
+ desired_fields (List[str] | str): The fields to retrieve.
127
+ collection_name (Optional[str]): The name of the collection. If not provided, the currently viewed collection is used.
128
+ result_per_query (int): The number of results to return per query.
129
+
130
+ Returns:
131
+ List[Dict[str, Any]] | List[Any]: The retrieved data.
132
+ """
133
+ # Step 1: Search for vectors
134
+ search_results = self._client.search(
135
+ collection_name or self.safe_viewing_collection,
136
+ vecs,
137
+ output_fields=desired_fields if isinstance(desired_fields, list) else [desired_fields],
138
+ limit=result_per_query,
139
+ )
140
+
141
+ # Step 2: Flatten the search results
142
+ flattened_results = flatten(search_results)
143
+
144
+ # Step 3: Sort by distance (descending)
145
+ sorted_results = sorted(flattened_results, key=itemgetter("distance"), reverse=True)
146
+
147
+ # Step 4: Extract the entities
148
+ resp = [result["entity"] for result in sorted_results]
149
+
150
+ if isinstance(desired_fields, list):
151
+ return resp
152
+ return [r.get(desired_fields) for r in resp]
153
+
154
+ async def aretrieve(
155
+ self,
156
+ query: List[str] | str,
157
+ collection_name: Optional[str] = None,
158
+ result_per_query: int = 10,
159
+ final_limit: int = 20,
160
+ ) -> List[str]:
161
+ """Retrieve data from the collection.
162
+
163
+ Args:
164
+ query (List[str] | str): The query to be used for retrieval.
165
+ collection_name (Optional[str]): The name of the collection. If not provided, the currently viewed collection is used.
166
+ result_per_query (int): The number of results to be returned per query.
167
+ final_limit (int): The final limit on the number of results to return.
168
+
169
+ Returns:
170
+ List[str]: A list of strings containing the retrieved data.
171
+ """
172
+ if isinstance(query, str):
173
+ query = [query]
174
+ return await self.afetch_document(
175
+ vecs=(await self.vectorize(query)),
176
+ desired_fields="text",
177
+ collection_name=collection_name,
178
+ result_per_query=result_per_query,
179
+ )[:final_limit]
Binary file
@@ -216,7 +216,7 @@ wheels = [
216
216
 
217
217
  [[package]]
218
218
  name = "fabricatio"
219
- version = "0.2.3.dev1"
219
+ version = "0.2.3.dev2"
220
220
  source = { editable = "." }
221
221
  dependencies = [
222
222
  { name = "appdirs" },
@@ -1,46 +0,0 @@
1
- """A module for the RAG (Retrieval Augmented Generation) model."""
2
-
3
- from typing import Any, Dict, List, Optional, Self, Union
4
-
5
- from fabricatio.config import configs
6
- from fabricatio.models.utils import MilvusData
7
-
8
- try:
9
- from pymilvus import MilvusClient
10
- except ImportError as e:
11
- raise RuntimeError("pymilvus is not installed. Have you installed `fabricatio[rag]` instead of `fabricatio`") from e
12
- from pydantic import BaseModel, ConfigDict, PrivateAttr
13
-
14
-
15
- class Rag(BaseModel):
16
- """A class representing the RAG (Retrieval Augmented Generation) model."""
17
-
18
- model_config = ConfigDict(use_attribute_docstrings=True)
19
-
20
- _client: MilvusClient = PrivateAttr(
21
- default=MilvusClient(
22
- uri=configs.rag.milvus_uri.unicode_string(),
23
- token=configs.rag.milvus_token.get_secret_value(),
24
- timeout=configs.rag.milvus_timeout,
25
- ),
26
- )
27
- _target_collection: Optional[str] = PrivateAttr(default=None)
28
-
29
- @property
30
- def client(self) -> MilvusClient:
31
- """The Milvus client."""
32
- return self._client
33
-
34
- def add_document[D: Union[Dict[str, Any] | MilvusData]](self, collection_name: str, data: D | List[D]) -> Self:
35
- """Adds a document to the specified collection.
36
-
37
- Args:
38
- collection_name (str): The name of the collection.
39
- data (dict): The data to be added to the collection.
40
- """
41
- if isinstance(data, MilvusData):
42
- data = data.prepare_insertion()
43
- if isinstance(data, list):
44
- data = [d.prepare_insertion() if isinstance(d, MilvusData) else d for d in data]
45
- self.client.insert(collection_name, data)
46
- return self
Binary file
File without changes