fabricatio 0.2.4.dev0__tar.gz → 0.2.4.dev1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/PKG-INFO +1 -1
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/examples/extract_article/extract.py +7 -4
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/pyproject.toml +1 -1
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/__init__.py +2 -0
- fabricatio-0.2.4.dev1/python/fabricatio/actions/article.py +44 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/capabilities/rating.py +12 -36
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/models/action.py +2 -3
- fabricatio-0.2.4.dev0/python/fabricatio/actions/article.py → fabricatio-0.2.4.dev1/python/fabricatio/models/extra.py +27 -58
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/models/generic.py +36 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/models/usages.py +15 -23
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/parser.py +6 -10
- fabricatio-0.2.4.dev1/templates.tar.gz +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/tests/test_models/test_action.py +2 -2
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/tests/test_models/test_task.py +2 -2
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/uv.lock +1 -3
- fabricatio-0.2.4.dev0/templates.tar.gz +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/.github/workflows/build-package.yaml +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/.github/workflows/ruff.yaml +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/.github/workflows/tests.yaml +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/.gitignore +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/.python-version +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/Cargo.lock +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/Cargo.toml +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/LICENSE +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/Makefile +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/README.md +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/examples/llm_usages/llm_usage.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/examples/make_a_rating/rating.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/examples/make_diary/commits.json +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/examples/make_diary/diary.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/examples/minor/hello_fabricatio.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/examples/propose_task/propose.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/examples/simple_chat/chat.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/examples/simple_rag/simple_rag.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/examples/task_handle/handle_task.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/_rust.pyi +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/_rust_instances.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/actions/__init__.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/capabilities/propose.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/capabilities/rag.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/capabilities/task.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/config.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/core.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/decorators.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/fs/__init__.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/fs/curd.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/fs/readers.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/journal.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/models/events.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/models/kwargs_types.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/models/role.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/models/task.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/models/tool.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/models/utils.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/py.typed +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/toolboxes/__init__.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/toolboxes/arithmetic.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/toolboxes/fs.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/python/fabricatio/toolboxes/task.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/src/hash.rs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/src/lib.rs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/src/templates.rs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/claude-xml.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/clean-up-code.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/create_json_obj.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/dependencies.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/document-the-code.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/draft_rating_criteria.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/draft_rating_manual.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/draft_rating_weights_klee.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/draft_tool_usage_code.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/extract_criteria_from_reasons.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/extract_reasons_from_examples.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/fix-bugs.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/improve-performance.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/liststr.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/make_choice.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/make_judgment.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/rate_fine_grind.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/refactor.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/retrieved_display.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/task_briefing.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/web-ctf-solver.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/write-git-commit.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/write-github-pull-request.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/write-github-readme.hbs +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/tests/test_config.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/tests/test_models/test_advanced.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/tests/test_models/test_generic.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/tests/test_models/test_role.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/tests/test_models/test_tool.py +0 -0
- {fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/tests/test_models/test_usages.py +0 -0
@@ -1,8 +1,9 @@
|
|
1
1
|
"""Example of proposing a task to a role."""
|
2
2
|
|
3
3
|
import asyncio
|
4
|
+
from typing import List
|
4
5
|
|
5
|
-
from fabricatio import Event, ExtractArticleEssence, Role, WorkFlow, logger
|
6
|
+
from fabricatio import ArticleEssence, Event, ExtractArticleEssence, Role, Task, WorkFlow, logger
|
6
7
|
|
7
8
|
|
8
9
|
async def main() -> None:
|
@@ -17,9 +18,11 @@ async def main() -> None:
|
|
17
18
|
)
|
18
19
|
},
|
19
20
|
)
|
20
|
-
task = await role.propose_task(
|
21
|
-
|
22
|
-
|
21
|
+
task: Task[List[ArticleEssence]] = await role.propose_task(
|
22
|
+
"Extract the essence of the article from the file at './7.md'"
|
23
|
+
)
|
24
|
+
ess = (await task.delegate("article")).pop()
|
25
|
+
logger.success(f"Essence:\n{ess.display()}")
|
23
26
|
|
24
27
|
|
25
28
|
if __name__ == "__main__":
|
@@ -9,6 +9,7 @@ from fabricatio.fs import magika
|
|
9
9
|
from fabricatio.journal import logger
|
10
10
|
from fabricatio.models.action import Action, WorkFlow
|
11
11
|
from fabricatio.models.events import Event
|
12
|
+
from fabricatio.models.extra import ArticleEssence
|
12
13
|
from fabricatio.models.role import Role
|
13
14
|
from fabricatio.models.task import Task
|
14
15
|
from fabricatio.models.tool import ToolBox
|
@@ -18,6 +19,7 @@ from fabricatio.toolboxes import arithmetic_toolbox, basic_toolboxes, fs_toolbox
|
|
18
19
|
|
19
20
|
__all__ = [
|
20
21
|
"Action",
|
22
|
+
"ArticleEssence",
|
21
23
|
"Capture",
|
22
24
|
"CodeBlockCapture",
|
23
25
|
"Event",
|
@@ -0,0 +1,44 @@
|
|
1
|
+
"""Actions for transmitting tasks to targets."""
|
2
|
+
|
3
|
+
from os import PathLike
|
4
|
+
from pathlib import Path
|
5
|
+
from typing import Callable, List
|
6
|
+
|
7
|
+
from fabricatio.journal import logger
|
8
|
+
from fabricatio.models.action import Action
|
9
|
+
from fabricatio.models.extra import ArticleEssence
|
10
|
+
from fabricatio.models.task import Task
|
11
|
+
|
12
|
+
|
13
|
+
class ExtractArticleEssence(Action):
|
14
|
+
"""Extract the essence of article(s)."""
|
15
|
+
|
16
|
+
name: str = "extract article essence"
|
17
|
+
"""The name of the action."""
|
18
|
+
description: str = "Extract the essence of an article. output as json"
|
19
|
+
"""The description of the action."""
|
20
|
+
|
21
|
+
output_key: str = "article_essence"
|
22
|
+
"""The key of the output data."""
|
23
|
+
|
24
|
+
async def _execute[P: PathLike | str](
|
25
|
+
self,
|
26
|
+
task_input: Task,
|
27
|
+
reader: Callable[[P], str] = lambda p: Path(p).read_text(encoding="utf-8"),
|
28
|
+
**_,
|
29
|
+
) -> List[ArticleEssence]:
|
30
|
+
if not await self.ajudge(
|
31
|
+
f"= Task\n{task_input.briefing}\n\n\n= Role\n{self.briefing}",
|
32
|
+
affirm_case="The task does not violate the role, and could be approved since the file dependencies are specified.",
|
33
|
+
deny_case="The task does violate the role, and could not be approved.",
|
34
|
+
):
|
35
|
+
logger.info(err := "Task not approved.")
|
36
|
+
raise RuntimeError(err)
|
37
|
+
|
38
|
+
# trim the references
|
39
|
+
contents = ["References".join(c.split("References")[:-1]) for c in map(reader, task_input.dependencies)]
|
40
|
+
return await self.propose(
|
41
|
+
ArticleEssence,
|
42
|
+
contents,
|
43
|
+
system_message=f"# your personal briefing: \n{self.briefing}",
|
44
|
+
)
|
@@ -131,8 +131,7 @@ class GiveRating(WithBriefing, LLMUsage):
|
|
131
131
|
|
132
132
|
def _validator(response: str) -> Dict[str, str] | None:
|
133
133
|
if (
|
134
|
-
(json_data := JsonCapture.
|
135
|
-
and isinstance(json_data, dict)
|
134
|
+
(json_data := JsonCapture.validate_with(response, target_type=dict, elements_type=str)) is not None
|
136
135
|
and json_data.keys() == criteria
|
137
136
|
and all(isinstance(v, str) for v in json_data.values())
|
138
137
|
):
|
@@ -173,11 +172,10 @@ class GiveRating(WithBriefing, LLMUsage):
|
|
173
172
|
|
174
173
|
def _validator(response: str) -> Set[str] | None:
|
175
174
|
if (
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
):
|
175
|
+
json_data := JsonCapture.validate_with(
|
176
|
+
response, target_type=list, elements_type=str, length=criteria_count
|
177
|
+
)
|
178
|
+
) is not None:
|
181
179
|
return set(json_data)
|
182
180
|
return None
|
183
181
|
|
@@ -219,27 +217,6 @@ class GiveRating(WithBriefing, LLMUsage):
|
|
219
217
|
Returns:
|
220
218
|
Set[str]: A set of drafted rating criteria.
|
221
219
|
"""
|
222
|
-
|
223
|
-
def _reasons_validator(response: str) -> List[str] | None:
|
224
|
-
if (
|
225
|
-
(json_data := JsonCapture.convert_with(response, orjson.loads)) is not None
|
226
|
-
and isinstance(json_data, list)
|
227
|
-
and all(isinstance(v, str) for v in json_data)
|
228
|
-
and len(json_data) == reasons_count
|
229
|
-
):
|
230
|
-
return json_data
|
231
|
-
return None
|
232
|
-
|
233
|
-
def _criteria_validator(response: str) -> Set[str] | None:
|
234
|
-
if (
|
235
|
-
(json_data := JsonCapture.convert_with(response, orjson.loads)) is not None
|
236
|
-
and isinstance(json_data, list)
|
237
|
-
and all(isinstance(v, str) for v in json_data)
|
238
|
-
and len(json_data) == criteria_count
|
239
|
-
):
|
240
|
-
return set(json_data)
|
241
|
-
return None
|
242
|
-
|
243
220
|
kwargs = GenerateKwargs(system_message=f"# your personal briefing: \n{self.briefing}", **kwargs)
|
244
221
|
# extract reasons from the comparison of ordered pairs of extracted from examples
|
245
222
|
reasons = flatten(
|
@@ -256,7 +233,9 @@ class GiveRating(WithBriefing, LLMUsage):
|
|
256
233
|
)
|
257
234
|
for pair in (permutations(examples, 2))
|
258
235
|
],
|
259
|
-
validator=
|
236
|
+
validator=lambda resp: JsonCapture.validate_with(
|
237
|
+
resp, target_type=list, elements_type=str, length=reasons_count
|
238
|
+
),
|
260
239
|
**kwargs,
|
261
240
|
)
|
262
241
|
)
|
@@ -272,7 +251,9 @@ class GiveRating(WithBriefing, LLMUsage):
|
|
272
251
|
},
|
273
252
|
)
|
274
253
|
),
|
275
|
-
validator=
|
254
|
+
validator=lambda resp: set(out)
|
255
|
+
if (out := JsonCapture.validate_with(resp, target_type=list, elements_type=str, length=criteria_count))
|
256
|
+
else None,
|
276
257
|
**kwargs,
|
277
258
|
)
|
278
259
|
|
@@ -295,11 +276,6 @@ class GiveRating(WithBriefing, LLMUsage):
|
|
295
276
|
if len(criteria) < 2: # noqa: PLR2004
|
296
277
|
raise ValueError("At least two criteria are required to draft rating weights")
|
297
278
|
|
298
|
-
def _validator(resp: str) -> float | None:
|
299
|
-
if (cap := JsonCapture.convert_with(resp, orjson.loads)) is not None and isinstance(cap, float):
|
300
|
-
return cap
|
301
|
-
return None
|
302
|
-
|
303
279
|
criteria = list(criteria) # freeze the order
|
304
280
|
windows = windowed(criteria, 2)
|
305
281
|
|
@@ -316,7 +292,7 @@ class GiveRating(WithBriefing, LLMUsage):
|
|
316
292
|
)
|
317
293
|
for pair in windows
|
318
294
|
],
|
319
|
-
validator=
|
295
|
+
validator=lambda resp: JsonCapture.validate_with(resp, target_type=float),
|
320
296
|
**GenerateKwargs(system_message=f"# your personal briefing: \n{self.briefing}", **kwargs),
|
321
297
|
)
|
322
298
|
weights = [1]
|
@@ -92,9 +92,8 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
|
|
92
92
|
Returns:
|
93
93
|
Self: The instance of the workflow with the injected personality.
|
94
94
|
"""
|
95
|
-
for a in self._instances:
|
96
|
-
|
97
|
-
a.personality = personality
|
95
|
+
for a in filter(lambda action: not action.personality, self._instances):
|
96
|
+
a.personality = personality
|
98
97
|
return self
|
99
98
|
|
100
99
|
async def serve(self, task: Task) -> None:
|
@@ -1,16 +1,9 @@
|
|
1
|
-
"""
|
1
|
+
"""Extra models for built-in actions."""
|
2
2
|
|
3
|
-
from
|
4
|
-
from pathlib import Path
|
5
|
-
from typing import Callable, List
|
3
|
+
from typing import List
|
6
4
|
|
7
|
-
from
|
8
|
-
from pydantic
|
9
|
-
|
10
|
-
from fabricatio.journal import logger
|
11
|
-
from fabricatio.models.action import Action
|
12
|
-
from fabricatio.models.generic import ProposedAble
|
13
|
-
from fabricatio.models.task import Task
|
5
|
+
from fabricatio.models.generic import Display, PrepareVectorization, ProposedAble
|
6
|
+
from pydantic import BaseModel, ConfigDict, Field
|
14
7
|
|
15
8
|
|
16
9
|
class Equation(BaseModel):
|
@@ -36,8 +29,28 @@ class Figure(BaseModel):
|
|
36
29
|
figure_caption: str = Field(...)
|
37
30
|
"""The caption accompanying the figure, summarizing its main points and academic value."""
|
38
31
|
|
32
|
+
figure_path: str = Field(...)
|
33
|
+
"""The file path to the figure"""
|
34
|
+
|
35
|
+
|
36
|
+
class Highlightings(BaseModel):
|
37
|
+
"""Structured representation of highlighted elements in an academic paper (including equations, algorithms, figures, and tables)."""
|
38
|
+
|
39
|
+
# Academic Achievements Showcase
|
40
|
+
highlighted_equations: List[Equation] = Field(default_factory=list)
|
41
|
+
"""Core mathematical equations that represent breakthroughs in the field, accompanied by explanations of their physical or conceptual significance."""
|
42
|
+
|
43
|
+
highlighted_algorithms: List[str] = Field(default_factory=list)
|
44
|
+
"""Pseudocode for key algorithms, annotated to highlight innovative components."""
|
45
|
+
|
46
|
+
highlighted_figures: List[Figure] = Field(default_factory=list)
|
47
|
+
"""Critical diagrams or illustrations, each accompanied by a caption explaining their academic importance."""
|
48
|
+
|
49
|
+
highlighted_tables: List[str] = Field(default_factory=list)
|
50
|
+
"""Important data tables, annotated to indicate statistical significance or other notable findings."""
|
39
51
|
|
40
|
-
|
52
|
+
|
53
|
+
class ArticleEssence(ProposedAble, Display, PrepareVectorization):
|
41
54
|
"""Structured representation of the core elements of an academic paper(providing a comprehensive digital profile of the paper's essential information)."""
|
42
55
|
|
43
56
|
# Basic Metadata
|
@@ -66,19 +79,6 @@ class ArticleEssence(ProposedAble):
|
|
66
79
|
technical_novelty: List[str] = Field(default_factory=list)
|
67
80
|
"""Specific technical innovations introduced by the research, listed as individual points."""
|
68
81
|
|
69
|
-
# Academic Achievements Showcase
|
70
|
-
highlighted_equations: List[Equation] = Field(default_factory=list)
|
71
|
-
"""Core mathematical equations that represent breakthroughs in the field, accompanied by explanations of their physical or conceptual significance."""
|
72
|
-
|
73
|
-
highlighted_algorithms: List[str] = Field(default_factory=list)
|
74
|
-
"""Pseudocode for key algorithms, annotated to highlight innovative components."""
|
75
|
-
|
76
|
-
highlighted_figures: List[Figure] = Field(default_factory=list)
|
77
|
-
"""Critical diagrams or illustrations, each accompanied by a caption explaining their academic importance."""
|
78
|
-
|
79
|
-
highlighted_tables: List[str] = Field(default_factory=list)
|
80
|
-
"""Important data tables, annotated to indicate statistical significance or other notable findings."""
|
81
|
-
|
82
82
|
# Academic Discussion Dimensions
|
83
83
|
research_problem: str = Field("")
|
84
84
|
"""A clearly defined research question or problem addressed by the study."""
|
@@ -92,36 +92,5 @@ class ArticleEssence(ProposedAble):
|
|
92
92
|
impact_analysis: str = Field("")
|
93
93
|
"""An assessment of the paper's potential influence on the development of the field."""
|
94
94
|
|
95
|
-
|
96
|
-
|
97
|
-
"""Extract the essence of article(s)."""
|
98
|
-
|
99
|
-
name: str = "extract article essence"
|
100
|
-
"""The name of the action."""
|
101
|
-
description: str = "Extract the essence of an article. output as json"
|
102
|
-
"""The description of the action."""
|
103
|
-
|
104
|
-
output_key: str = "article_essence"
|
105
|
-
"""The key of the output data."""
|
106
|
-
|
107
|
-
async def _execute[P: PathLike | str](
|
108
|
-
self,
|
109
|
-
task_input: Task,
|
110
|
-
reader: Callable[[P], str] = lambda p: Path(p).read_text(encoding="utf-8"),
|
111
|
-
**_,
|
112
|
-
) -> List[ArticleEssence]:
|
113
|
-
if not await self.ajudge(
|
114
|
-
f"= Task\n{task_input.briefing}\n\n\n= Role\n{self.briefing}",
|
115
|
-
affirm_case="The task does not violate the role, and could be approved since the file dependencies are specified.",
|
116
|
-
deny_case="The task does violate the role, and could not be approved.",
|
117
|
-
):
|
118
|
-
logger.info(err := "Task not approved.")
|
119
|
-
raise RuntimeError(err)
|
120
|
-
|
121
|
-
# trim the references
|
122
|
-
contents = ["References".join(c.split("References")[:-1]) for c in map(reader, task_input.dependencies)]
|
123
|
-
return await self.propose(
|
124
|
-
ArticleEssence,
|
125
|
-
contents,
|
126
|
-
system_message=f"# your personal briefing: \n{self.briefing}",
|
127
|
-
)
|
95
|
+
def _prepare_vectorization_inner(self) -> str:
|
96
|
+
return self.model_dump_json()
|
@@ -1,5 +1,6 @@
|
|
1
1
|
"""This module defines generic classes for models in the Fabricatio library."""
|
2
2
|
|
3
|
+
from abc import abstractmethod
|
3
4
|
from pathlib import Path
|
4
5
|
from typing import Callable, Iterable, List, Optional, Self, Union, final
|
5
6
|
|
@@ -8,6 +9,7 @@ from fabricatio._rust import blake3_hash
|
|
8
9
|
from fabricatio._rust_instances import template_manager
|
9
10
|
from fabricatio.config import configs
|
10
11
|
from fabricatio.fs.readers import magika, safe_text_read
|
12
|
+
from fabricatio.journal import logger
|
11
13
|
from fabricatio.parser import JsonCapture
|
12
14
|
from pydantic import (
|
13
15
|
BaseModel,
|
@@ -27,6 +29,18 @@ class Base(BaseModel):
|
|
27
29
|
model_config = ConfigDict(use_attribute_docstrings=True)
|
28
30
|
|
29
31
|
|
32
|
+
class Display(Base):
|
33
|
+
"""Class that provides a method to display the model in a formatted JSON string."""
|
34
|
+
|
35
|
+
def display(self) -> str:
|
36
|
+
"""Display the model in a formatted JSON string.
|
37
|
+
|
38
|
+
Returns:
|
39
|
+
str: The formatted JSON string of the model.
|
40
|
+
"""
|
41
|
+
return self.model_dump_json(indent=1)
|
42
|
+
|
43
|
+
|
30
44
|
class Named(Base):
|
31
45
|
"""Class that includes a name attribute."""
|
32
46
|
|
@@ -199,6 +213,28 @@ class WithDependency(Base):
|
|
199
213
|
)
|
200
214
|
|
201
215
|
|
216
|
+
class PrepareVectorization(Base):
|
217
|
+
"""Class that prepares the vectorization of the model."""
|
218
|
+
|
219
|
+
@abstractmethod
|
220
|
+
def _prepare_vectorization_inner(self) -> str:
|
221
|
+
"""Prepare the vectorization of the model."""
|
222
|
+
|
223
|
+
def prepare_vectorization(self, max_length: Optional[int] = None) -> str:
|
224
|
+
"""Prepare the vectorization of the model.
|
225
|
+
|
226
|
+
Returns:
|
227
|
+
str: The prepared vectorization of the model.
|
228
|
+
"""
|
229
|
+
max_length = max_length or configs.embedding.max_sequence_length
|
230
|
+
chunk = self._prepare_vectorization_inner()
|
231
|
+
if len(chunk) > max_length:
|
232
|
+
logger.error(err := f"Chunk exceeds maximum sequence length {max_length}.")
|
233
|
+
raise ValueError(err)
|
234
|
+
|
235
|
+
return chunk
|
236
|
+
|
237
|
+
|
202
238
|
class ScopedConfig(Base):
|
203
239
|
"""Class that manages a scoped configuration."""
|
204
240
|
|
@@ -5,7 +5,6 @@ from typing import Callable, Dict, Iterable, List, Optional, Self, Set, Type, Un
|
|
5
5
|
|
6
6
|
import asyncstdlib
|
7
7
|
import litellm
|
8
|
-
import orjson
|
9
8
|
from fabricatio._rust_instances import template_manager
|
10
9
|
from fabricatio.config import configs
|
11
10
|
from fabricatio.journal import logger
|
@@ -23,6 +22,7 @@ from litellm.types.utils import (
|
|
23
22
|
StreamingChoices,
|
24
23
|
)
|
25
24
|
from litellm.utils import CustomStreamWrapper
|
25
|
+
from more_itertools import duplicates_everseen
|
26
26
|
from pydantic import Field, NonNegativeInt, PositiveInt
|
27
27
|
|
28
28
|
|
@@ -212,11 +212,10 @@ class LLMUsage(ScopedConfig):
|
|
212
212
|
**kwargs,
|
213
213
|
)
|
214
214
|
) and (validated := validator(response)):
|
215
|
-
logger.debug(f"Successfully validated the response at {i}th attempt.
|
215
|
+
logger.debug(f"Successfully validated the response at {i}th attempt.")
|
216
216
|
return validated
|
217
|
-
|
218
|
-
|
219
|
-
raise ValueError("Failed to validate the response.")
|
217
|
+
logger.error(err := f"Failed to validate the response after {max_validations} attempts.")
|
218
|
+
raise ValueError(err)
|
220
219
|
|
221
220
|
async def aask_validate_batch[T](
|
222
221
|
self,
|
@@ -255,7 +254,7 @@ class LLMUsage(ScopedConfig):
|
|
255
254
|
configs.templates.liststr_template,
|
256
255
|
{"requirement": requirement, "k": k},
|
257
256
|
),
|
258
|
-
lambda resp: JsonCapture.validate_with(resp,
|
257
|
+
lambda resp: JsonCapture.validate_with(resp, target_type=list, elements_type=str, length=k),
|
259
258
|
**kwargs,
|
260
259
|
)
|
261
260
|
|
@@ -282,6 +281,9 @@ class LLMUsage(ScopedConfig):
|
|
282
281
|
- Ensures response compliance through JSON parsing and format validation.
|
283
282
|
- Relies on `aask_validate` to implement retry mechanisms with validation.
|
284
283
|
"""
|
284
|
+
if dup := duplicates_everseen(choices, key=lambda x: x.name):
|
285
|
+
logger.error(err := f"Redundant choices: {dup}")
|
286
|
+
raise ValueError(err)
|
285
287
|
prompt = template_manager.render_template(
|
286
288
|
configs.templates.make_choice_template,
|
287
289
|
{
|
@@ -291,19 +293,16 @@ class LLMUsage(ScopedConfig):
|
|
291
293
|
},
|
292
294
|
)
|
293
295
|
names = {c.name for c in choices}
|
296
|
+
|
294
297
|
logger.debug(f"Start choosing between {names} with prompt: \n{prompt}")
|
295
298
|
|
296
299
|
def _validate(response: str) -> List[T] | None:
|
297
|
-
ret = JsonCapture.
|
298
|
-
|
299
|
-
if not isinstance(ret, List) or (0 < k != len(ret)):
|
300
|
-
logger.error(f"Incorrect Type or length of response: \n{ret}")
|
301
|
-
return None
|
302
|
-
if any(n not in names for n in ret):
|
303
|
-
logger.error(f"Invalid choice in response: \n{ret}")
|
300
|
+
ret = JsonCapture.validate_with(response, target_type=List, elements_type=str, length=k)
|
301
|
+
if ret is None or set(ret) - names:
|
304
302
|
return None
|
305
|
-
|
306
|
-
|
303
|
+
return [
|
304
|
+
next(candidate for candidate in choices if candidate.name == candidate_name) for candidate_name in ret
|
305
|
+
]
|
307
306
|
|
308
307
|
return await self.aask_validate(
|
309
308
|
question=prompt,
|
@@ -357,19 +356,12 @@ class LLMUsage(ScopedConfig):
|
|
357
356
|
Returns:
|
358
357
|
bool: The judgment result (True or False) based on the AI's response.
|
359
358
|
"""
|
360
|
-
|
361
|
-
def _validate(response: str) -> bool | None:
|
362
|
-
ret = JsonCapture.convert_with(response, orjson.loads)
|
363
|
-
if not isinstance(ret, bool):
|
364
|
-
return None
|
365
|
-
return ret
|
366
|
-
|
367
359
|
return await self.aask_validate(
|
368
360
|
question=template_manager.render_template(
|
369
361
|
configs.templates.make_judgment_template,
|
370
362
|
{"prompt": prompt, "affirm_case": affirm_case, "deny_case": deny_case},
|
371
363
|
),
|
372
|
-
validator=
|
364
|
+
validator=lambda resp: JsonCapture.validate_with(resp, target_type=bool),
|
373
365
|
**kwargs,
|
374
366
|
)
|
375
367
|
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
from typing import Any, Callable, Optional, Self, Tuple, Type
|
4
4
|
|
5
|
+
import orjson
|
5
6
|
import regex
|
6
7
|
from pydantic import BaseModel, ConfigDict, Field, PositiveInt, PrivateAttr, ValidationError
|
7
8
|
from regex import Pattern, compile
|
@@ -27,11 +28,7 @@ class Capture(BaseModel):
|
|
27
28
|
_compiled: Pattern = PrivateAttr()
|
28
29
|
|
29
30
|
def model_post_init(self, __context: Any) -> None:
|
30
|
-
"""Initialize the compiled
|
31
|
-
|
32
|
-
Args:
|
33
|
-
__context (Any): The context in which the model is initialized.
|
34
|
-
"""
|
31
|
+
"""Initialize the compiled pattern."""
|
35
32
|
self._compiled = compile(self.pattern, self.flags)
|
36
33
|
|
37
34
|
def capture(self, text: str) -> Tuple[str, ...] | str | None:
|
@@ -69,7 +66,6 @@ class Capture(BaseModel):
|
|
69
66
|
if (cap := self.capture(text)) is None:
|
70
67
|
return None
|
71
68
|
try:
|
72
|
-
logger.debug(f"Trying to convert: \n{cap}")
|
73
69
|
return convertor(cap)
|
74
70
|
except (ValueError, SyntaxError, ValidationError) as e:
|
75
71
|
logger.error(f"Failed to convert text using {convertor.__name__} to convert.\nerror: {e}\n {cap}")
|
@@ -78,19 +74,19 @@ class Capture(BaseModel):
|
|
78
74
|
def validate_with[K, T, E](
|
79
75
|
self,
|
80
76
|
text: str,
|
81
|
-
deserializer: Callable[[Tuple[str, ...]], K] | Callable[[str], K],
|
82
77
|
target_type: Type[T],
|
83
78
|
elements_type: Optional[Type[E]] = None,
|
84
79
|
length: Optional[int] = None,
|
80
|
+
deserializer: Callable[[Tuple[str, ...]], K] | Callable[[str], K] = orjson.loads,
|
85
81
|
) -> T | None:
|
86
82
|
"""Validate the given text using the pattern.
|
87
83
|
|
88
84
|
Args:
|
89
85
|
text (str): The text to search the pattern in.
|
90
|
-
|
91
|
-
|
92
|
-
elements_type (Optional[Type[E]]): The expected type of the elements in the output.
|
86
|
+
target_type (Type[T]): The expected type of the output, dict or list.
|
87
|
+
elements_type (Optional[Type[E]]): The expected type of the elements in the output dict keys or list elements.
|
93
88
|
length (Optional[int]): The expected length of the output, bool(length)==False means no length validation.
|
89
|
+
deserializer (Callable[[Tuple[str, ...]], K] | Callable[[str], K]): The function to deserialize the captured text.
|
94
90
|
|
95
91
|
Returns:
|
96
92
|
T | None: The validated text if the pattern is found and the output is of the expected type, otherwise None.
|
Binary file
|
@@ -61,13 +61,13 @@ async def test_action_act_with_output_key():
|
|
61
61
|
|
62
62
|
|
63
63
|
def test_action_briefing_without_personality(basic_action):
|
64
|
-
briefing = basic_action.briefing
|
64
|
+
briefing = basic_action.briefing
|
65
65
|
assert "personality" not in briefing.lower()
|
66
66
|
|
67
67
|
|
68
68
|
def test_action_briefing_with_personality():
|
69
69
|
action = DemoAction(personality="Helper")
|
70
|
-
briefing = action.briefing
|
70
|
+
briefing = action.briefing
|
71
71
|
assert "personality" in briefing.lower()
|
72
72
|
assert "Helper" in briefing
|
73
73
|
|
@@ -27,8 +27,8 @@ async def test_task_status_changes(basic_task):
|
|
27
27
|
|
28
28
|
@pytest.mark.asyncio
|
29
29
|
async def test_task_publishing(basic_task):
|
30
|
-
|
31
|
-
assert basic_task.
|
30
|
+
basic_task.publish()
|
31
|
+
assert basic_task.is_pending()
|
32
32
|
|
33
33
|
|
34
34
|
@pytest.mark.asyncio
|
@@ -1,5 +1,4 @@
|
|
1
1
|
version = 1
|
2
|
-
revision = 1
|
3
2
|
requires-python = "==3.12.*"
|
4
3
|
|
5
4
|
[[package]]
|
@@ -216,7 +215,7 @@ wheels = [
|
|
216
215
|
|
217
216
|
[[package]]
|
218
217
|
name = "fabricatio"
|
219
|
-
version = "0.2.4.
|
218
|
+
version = "0.2.4.dev1"
|
220
219
|
source = { editable = "." }
|
221
220
|
dependencies = [
|
222
221
|
{ name = "appdirs" },
|
@@ -278,7 +277,6 @@ requires-dist = [
|
|
278
277
|
{ name = "regex", specifier = ">=2024.11.6" },
|
279
278
|
{ name = "rich", specifier = ">=13.9.4" },
|
280
279
|
]
|
281
|
-
provides-extras = ["rag", "full"]
|
282
280
|
|
283
281
|
[package.metadata.requires-dev]
|
284
282
|
dev = [
|
Binary file
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/cryptography-ctf-solver.hbs
RENAMED
File without changes
|
File without changes
|
File without changes
|
{fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/draft_rating_criteria.hbs
RENAMED
File without changes
|
File without changes
|
{fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/draft_rating_weights_klee.hbs
RENAMED
File without changes
|
{fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/draft_tool_usage_code.hbs
RENAMED
File without changes
|
{fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/extract_criteria_from_reasons.hbs
RENAMED
File without changes
|
{fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/extract_reasons_from_examples.hbs
RENAMED
File without changes
|
{fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/find-security-vulnerabilities.hbs
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{fabricatio-0.2.4.dev0 → fabricatio-0.2.4.dev1}/templates/built-in/write-github-pull-request.hbs
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|