fabricatio 0.2.0.dev16__tar.gz → 0.2.0.dev18__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.0.dev16 → fabricatio-0.2.0.dev18}/PKG-INFO +6 -1
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/pyproject.toml +9 -6
- fabricatio-0.2.0.dev18/python/fabricatio/models/advanced.py +119 -0
- fabricatio-0.2.0.dev18/python/fabricatio/models/kwargs_types.py +26 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/models/tool.py +1 -1
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/models/usages.py +17 -25
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/parser.py +1 -1
- fabricatio-0.2.0.dev18/templates/built-in/draft_tool_usage_code.hbs +52 -0
- fabricatio-0.2.0.dev18/templates.tar.gz +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/uv.lock +17 -15
- fabricatio-0.2.0.dev16/python/fabricatio/models/advanced.py +0 -96
- fabricatio-0.2.0.dev16/templates.tar.gz +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/.github/workflows/build-package.yaml +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/.github/workflows/ruff.yaml +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/.github/workflows/tests.yaml +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/.gitignore +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/.python-version +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/Cargo.lock +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/Cargo.toml +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/LICENSE +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/Makefile +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/README.md +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/examples/llm_usages/llm_usage.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/examples/minor/hello_fabricatio.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/examples/propose_task/propose.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/examples/simple_chat/chat.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/__init__.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/_rust.pyi +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/_rust_instances.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/actions/__init__.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/actions/communication.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/actions/transmission.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/config.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/core.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/decorators.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/fs/__init__.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/fs/curd.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/fs/readers.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/journal.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/models/action.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/models/events.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/models/generic.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/models/role.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/models/task.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/models/utils.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/py.typed +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/toolboxes/__init__.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/toolboxes/arithmetic.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/toolboxes/fs.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/toolboxes/task.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/src/lib.rs +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/src/templates.rs +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/templates/built-in/claude-xml.hbs +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/templates/built-in/clean-up-code.hbs +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/templates/built-in/document-the-code.hbs +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/templates/built-in/fix-bugs.hbs +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/templates/built-in/improve-performance.hbs +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/templates/built-in/make_choice.hbs +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/templates/built-in/make_judgment.hbs +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/templates/built-in/propose_task.hbs +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/templates/built-in/refactor.hbs +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/templates/built-in/web-ctf-solver.hbs +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/templates/built-in/write-git-commit.hbs +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/templates/built-in/write-github-pull-request.hbs +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/templates/built-in/write-github-readme.hbs +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/tests/test_config.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/tests/test_models/test_action.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/tests/test_models/test_advanced.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/tests/test_models/test_generic.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/tests/test_models/test_role.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/tests/test_models/test_task.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/tests/test_models/test_tool.py +0 -0
- {fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/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.0.
|
3
|
+
Version: 0.2.0.dev18
|
4
4
|
Classifier: License :: OSI Approved :: MIT License
|
5
5
|
Classifier: Programming Language :: Rust
|
6
6
|
Classifier: Programming Language :: Python :: 3.12
|
@@ -22,6 +22,11 @@ Requires-Dist: pymitter>=1.0.0
|
|
22
22
|
Requires-Dist: questionary>=2.1.0
|
23
23
|
Requires-Dist: regex>=2024.11.6
|
24
24
|
Requires-Dist: rich>=13.9.4
|
25
|
+
Requires-Dist: faiss-cpu>=1.10.0 ; extra == 'rag'
|
26
|
+
Requires-Dist: pymilvus>=2.5.4 ; extra == 'rag'
|
27
|
+
Requires-Dist: fabricatio[rag] ; extra == 'full'
|
28
|
+
Provides-Extra: rag
|
29
|
+
Provides-Extra: full
|
25
30
|
License-File: LICENSE
|
26
31
|
Summary: A LLM multi-agent framework.
|
27
32
|
Keywords: ai,agents,multi-agent,llm,pyo3
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[project]
|
2
2
|
name = "fabricatio"
|
3
|
-
version = "0.2.0-dev.
|
3
|
+
version = "0.2.0-dev.18"
|
4
4
|
description = "A LLM multi-agent framework."
|
5
5
|
readme = "README.md"
|
6
6
|
license = { file = "LICENSE" }
|
@@ -47,6 +47,8 @@ dependencies = [
|
|
47
47
|
Homepage = "https://github.com/Whth/fabricatio"
|
48
48
|
Repository = "https://github.com/Whth/fabricatio"
|
49
49
|
Issues = "https://github.com/Whth/fabricatio/issues"
|
50
|
+
|
51
|
+
|
50
52
|
[build-system]
|
51
53
|
requires = ["maturin>=1.0,<2.0"]
|
52
54
|
build-backend = "maturin"
|
@@ -59,6 +61,9 @@ data = "extra"
|
|
59
61
|
dev = [
|
60
62
|
"maturin>=1.8.2",
|
61
63
|
"maturin-import-hook>=0.2.0",
|
64
|
+
"ruff>=0.9.4",
|
65
|
+
"uv>=0.5.29",
|
66
|
+
"viztracer>=1.0.2",
|
62
67
|
"pytest>=8.3.4",
|
63
68
|
"pytest-asyncio>=0.25.3",
|
64
69
|
"pytest-cov>=6.0.0",
|
@@ -67,10 +72,9 @@ dev = [
|
|
67
72
|
"pytest-mock>=3.14.0",
|
68
73
|
"pytest-rerunfailures>=15.0",
|
69
74
|
"pytest-xdist>=3.6.1",
|
70
|
-
"ruff>=0.9.4",
|
71
|
-
"uv>=0.5.29",
|
72
|
-
"viztracer>=1.0.2",
|
73
75
|
]
|
76
|
+
|
77
|
+
[project.optional-dependencies]
|
74
78
|
rag = [
|
75
79
|
"faiss-cpu>=1.10.0",
|
76
80
|
"pymilvus>=2.5.4",
|
@@ -80,7 +84,6 @@ full = [
|
|
80
84
|
"fabricatio[rag]",
|
81
85
|
]
|
82
86
|
|
83
|
-
|
84
87
|
[tool.ruff]
|
85
88
|
include = ["pyproject.toml", "python/fabricatio/*.py","python/fabricatio/*.pyi", "examples/*.py"]
|
86
89
|
line-length = 120
|
@@ -136,7 +139,7 @@ testpaths = [
|
|
136
139
|
]
|
137
140
|
|
138
141
|
[tool.uv.sources]
|
139
|
-
code2prompt = { git = "https://github.com/mufeedvh/code2prompt" }
|
142
|
+
code2prompt = { git = "https://github.com/mufeedvh/code2prompt", rev = "d157ee84827458bd6816142e213886487d28bd3d" }
|
140
143
|
|
141
144
|
[[tool.uv.index]]
|
142
145
|
url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"
|
@@ -0,0 +1,119 @@
|
|
1
|
+
"""A module for advanced models and functionalities."""
|
2
|
+
|
3
|
+
from types import CodeType
|
4
|
+
from typing import List, Optional, Tuple, Unpack
|
5
|
+
|
6
|
+
import orjson
|
7
|
+
from fabricatio._rust_instances import template_manager
|
8
|
+
from fabricatio.config import configs
|
9
|
+
from fabricatio.models.generic import WithBriefing
|
10
|
+
from fabricatio.models.kwargs_types import LLMKwargs
|
11
|
+
from fabricatio.models.task import Task
|
12
|
+
from fabricatio.models.tool import Tool, ToolExecutor
|
13
|
+
from fabricatio.models.usages import LLMUsage, ToolBoxUsage
|
14
|
+
from fabricatio.parser import JsonCapture, PythonCapture
|
15
|
+
from loguru import logger
|
16
|
+
from pydantic import PositiveInt, ValidationError
|
17
|
+
|
18
|
+
|
19
|
+
class ProposeTask(LLMUsage, WithBriefing):
|
20
|
+
"""A class that proposes a task based on a prompt."""
|
21
|
+
|
22
|
+
async def propose(
|
23
|
+
self,
|
24
|
+
prompt: str,
|
25
|
+
max_validations: PositiveInt = 2,
|
26
|
+
**kwargs: Unpack[LLMKwargs],
|
27
|
+
) -> Task:
|
28
|
+
"""Asynchronously proposes a task based on a given prompt and parameters.
|
29
|
+
|
30
|
+
Parameters:
|
31
|
+
prompt: The prompt text for proposing a task, which is a string that must be provided.
|
32
|
+
max_validations: The maximum number of validations allowed, default is 2.
|
33
|
+
**kwargs: The keyword arguments for the LLM (Large Language Model) usage.
|
34
|
+
|
35
|
+
Returns:
|
36
|
+
A Task object based on the proposal result.
|
37
|
+
"""
|
38
|
+
if not prompt:
|
39
|
+
err = f"{self.name}: Prompt must be provided."
|
40
|
+
logger.error(err)
|
41
|
+
raise ValueError(err)
|
42
|
+
|
43
|
+
def _validate_json(response: str) -> None | Task:
|
44
|
+
try:
|
45
|
+
cap = JsonCapture.capture(response)
|
46
|
+
logger.debug(f"Response: \n{response}")
|
47
|
+
logger.info(f"Captured JSON: \n{cap}")
|
48
|
+
return Task.model_validate_json(cap)
|
49
|
+
except ValidationError as e:
|
50
|
+
logger.error(f"Failed to parse task from JSON: {e}")
|
51
|
+
return None
|
52
|
+
|
53
|
+
template_data = {"prompt": prompt, "json_example": Task.json_example()}
|
54
|
+
return await self.aask_validate(
|
55
|
+
question=template_manager.render_template("propose_task", template_data),
|
56
|
+
validator=_validate_json,
|
57
|
+
system_message=f"# your personal briefing: \n{self.briefing}",
|
58
|
+
max_validations=max_validations,
|
59
|
+
**kwargs,
|
60
|
+
)
|
61
|
+
|
62
|
+
|
63
|
+
class HandleTask(WithBriefing, ToolBoxUsage):
|
64
|
+
"""A class that handles a task based on a task object."""
|
65
|
+
|
66
|
+
async def draft_tool_usage_code(
|
67
|
+
self,
|
68
|
+
task: Task,
|
69
|
+
tools: List[Tool],
|
70
|
+
**kwargs: Unpack[LLMKwargs],
|
71
|
+
) -> Tuple[CodeType, List[str]]:
|
72
|
+
"""Asynchronously drafts the tool usage code for a task based on a given task object and tools."""
|
73
|
+
logger.info(f"Drafting tool usage code for task: {task.briefing}")
|
74
|
+
|
75
|
+
if not tools:
|
76
|
+
err = f"{self.name}: Tools must be provided to draft the tool usage code."
|
77
|
+
logger.error(err)
|
78
|
+
raise ValueError(err)
|
79
|
+
|
80
|
+
def _validator(response: str) -> Tuple[CodeType, List[str]] | None:
|
81
|
+
if (source := PythonCapture.convert_with(response, lambda resp: compile(resp, "<string>", "exec"))) and (
|
82
|
+
to_extract := JsonCapture.convert_with(response, orjson.loads)
|
83
|
+
):
|
84
|
+
return source, to_extract
|
85
|
+
return None
|
86
|
+
|
87
|
+
return await self.aask_validate(
|
88
|
+
question=template_manager.render_template(
|
89
|
+
"draft_tool_usage_code",
|
90
|
+
{
|
91
|
+
"tool_module_name": configs.toolbox.tool_module_name,
|
92
|
+
"task": task.briefing,
|
93
|
+
"tools": [tool.briefing for tool in tools],
|
94
|
+
},
|
95
|
+
),
|
96
|
+
validator=_validator,
|
97
|
+
system_message=f"# your personal briefing: \n{self.briefing}",
|
98
|
+
**kwargs,
|
99
|
+
)
|
100
|
+
|
101
|
+
async def handle_fin_grind(
|
102
|
+
self,
|
103
|
+
task: Task,
|
104
|
+
**kwargs: Unpack[LLMKwargs],
|
105
|
+
) -> Optional[Tuple]:
|
106
|
+
"""Asynchronously handles a task based on a given task object and parameters."""
|
107
|
+
logger.info(f"Handling task: {task.briefing}")
|
108
|
+
|
109
|
+
tools = await self.gather_tools(task)
|
110
|
+
logger.info(f"{self.name} have gathered {len(tools)} tools gathered")
|
111
|
+
|
112
|
+
if tools:
|
113
|
+
executor = ToolExecutor(execute_sequence=tools)
|
114
|
+
code, to_extract = await self.draft_tool_usage_code(task, tools, **kwargs)
|
115
|
+
cxt = await executor.execute(code)
|
116
|
+
if to_extract:
|
117
|
+
return tuple(cxt.get(k) for k in to_extract)
|
118
|
+
|
119
|
+
return None
|
@@ -0,0 +1,26 @@
|
|
1
|
+
"""This module contains the types for the keyword arguments of the methods in the models module."""
|
2
|
+
|
3
|
+
from typing import List, NotRequired, TypedDict
|
4
|
+
|
5
|
+
from pydantic import NonNegativeFloat, NonNegativeInt, PositiveInt
|
6
|
+
|
7
|
+
|
8
|
+
class LLMKwargs(TypedDict):
|
9
|
+
"""A type representing the keyword arguments for the LLM (Large Language Model) usage."""
|
10
|
+
|
11
|
+
model: NotRequired[str]
|
12
|
+
temperature: NotRequired[NonNegativeFloat]
|
13
|
+
stop: NotRequired[str | List[str]]
|
14
|
+
top_p: NotRequired[NonNegativeFloat]
|
15
|
+
max_tokens: NotRequired[PositiveInt]
|
16
|
+
stream: NotRequired[bool]
|
17
|
+
timeout: NotRequired[PositiveInt]
|
18
|
+
max_retries: NotRequired[PositiveInt]
|
19
|
+
|
20
|
+
|
21
|
+
class ChooseKwargs(LLMKwargs):
|
22
|
+
"""A type representing the keyword arguments for the choose method."""
|
23
|
+
|
24
|
+
max_validations: NotRequired[PositiveInt]
|
25
|
+
system_message: NotRequired[str]
|
26
|
+
k: NotRequired[NonNegativeInt]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"""This module contains classes that manage the usage of language models and tools in tasks."""
|
2
2
|
|
3
|
-
from typing import Callable, Dict, Iterable, List,
|
3
|
+
from typing import Callable, Dict, Iterable, List, Optional, Self, Set, Union, Unpack
|
4
4
|
|
5
5
|
import litellm
|
6
6
|
import orjson
|
@@ -8,6 +8,7 @@ from fabricatio._rust_instances import template_manager
|
|
8
8
|
from fabricatio.config import configs
|
9
9
|
from fabricatio.journal import logger
|
10
10
|
from fabricatio.models.generic import Base, WithBriefing
|
11
|
+
from fabricatio.models.kwargs_types import ChooseKwargs, LLMKwargs
|
11
12
|
from fabricatio.models.task import Task
|
12
13
|
from fabricatio.models.tool import Tool, ToolBox
|
13
14
|
from fabricatio.models.utils import Messages
|
@@ -16,19 +17,6 @@ from litellm.types.utils import Choices, ModelResponse, StreamingChoices
|
|
16
17
|
from pydantic import Field, HttpUrl, NonNegativeFloat, NonNegativeInt, PositiveInt, SecretStr
|
17
18
|
|
18
19
|
|
19
|
-
class LLMKwargs(TypedDict):
|
20
|
-
"""A type representing the keyword arguments for the LLM (Large Language Model) usage."""
|
21
|
-
|
22
|
-
model: NotRequired[str]
|
23
|
-
temperature: NotRequired[NonNegativeFloat]
|
24
|
-
stop: NotRequired[str | List[str]]
|
25
|
-
top_p: NotRequired[NonNegativeFloat]
|
26
|
-
max_tokens: NotRequired[PositiveInt]
|
27
|
-
stream: NotRequired[bool]
|
28
|
-
timeout: NotRequired[PositiveInt]
|
29
|
-
max_retries: NotRequired[PositiveInt]
|
30
|
-
|
31
|
-
|
32
20
|
class LLMUsage(Base):
|
33
21
|
"""Class that manages LLM (Large Language Model) usage parameters and methods."""
|
34
22
|
|
@@ -319,14 +307,6 @@ class LLMUsage(Base):
|
|
319
307
|
setattr(other, attr_name, attr)
|
320
308
|
|
321
309
|
|
322
|
-
class ChooseKwargs(LLMKwargs):
|
323
|
-
"""A type representing the keyword arguments for the choose method."""
|
324
|
-
|
325
|
-
max_validations: NotRequired[PositiveInt]
|
326
|
-
system_message: NotRequired[str]
|
327
|
-
k: NotRequired[NonNegativeInt]
|
328
|
-
|
329
|
-
|
330
310
|
class ToolBoxUsage(LLMUsage):
|
331
311
|
"""A class representing the usage of tools in a task."""
|
332
312
|
|
@@ -362,7 +342,7 @@ class ToolBoxUsage(LLMUsage):
|
|
362
342
|
logger.warning("No toolboxes available.")
|
363
343
|
return []
|
364
344
|
return await self.achoose(
|
365
|
-
instruction=task.briefing,
|
345
|
+
instruction=task.briefing, # TODO write a template to build a more robust instruction
|
366
346
|
choices=list(self.toolboxes),
|
367
347
|
k=k,
|
368
348
|
max_validations=max_validations,
|
@@ -396,7 +376,7 @@ class ToolBoxUsage(LLMUsage):
|
|
396
376
|
logger.warning(f"No tools available in toolbox {toolbox.name}.")
|
397
377
|
return []
|
398
378
|
return await self.achoose(
|
399
|
-
instruction=task.briefing,
|
379
|
+
instruction=task.briefing, # TODO write a template to build a more robust instruction
|
400
380
|
choices=toolbox.tools,
|
401
381
|
k=k,
|
402
382
|
max_validations=max_validations,
|
@@ -404,7 +384,7 @@ class ToolBoxUsage(LLMUsage):
|
|
404
384
|
**kwargs,
|
405
385
|
)
|
406
386
|
|
407
|
-
async def
|
387
|
+
async def gather_tools_fine_grind(
|
408
388
|
self,
|
409
389
|
task: Task,
|
410
390
|
box_choose_kwargs: Optional[ChooseKwargs] = None,
|
@@ -431,6 +411,18 @@ class ToolBoxUsage(LLMUsage):
|
|
431
411
|
chosen_tools.extend(await self.choose_tools(task, toolbox, **tool_choose_kwargs))
|
432
412
|
return chosen_tools
|
433
413
|
|
414
|
+
async def gather_tools(self, task: Task, **kwargs: Unpack[ChooseKwargs]) -> List[Tool]:
|
415
|
+
"""Asynchronously gathers tools based on the provided task.
|
416
|
+
|
417
|
+
Args:
|
418
|
+
task (Task): The task for which to gather tools.
|
419
|
+
**kwargs (Unpack[ChooseKwargs]): Keyword arguments for choosing tools, such as `system_message`, `k`, `max_validations`, `model`, `temperature`, `stop`, `top_p`, `max_tokens`, `stream`, `timeout`, and `max_retries`.
|
420
|
+
|
421
|
+
Returns:
|
422
|
+
List[Tool]: A list of tools gathered based on the provided task.
|
423
|
+
"""
|
424
|
+
return await self.gather_tools_fine_grind(task, kwargs, kwargs)
|
425
|
+
|
434
426
|
def supply_tools_from[S: "ToolBoxUsage"](self, others: Union[S, Iterable[S]]) -> Self:
|
435
427
|
"""Supplies tools from other ToolUsage instances to this instance.
|
436
428
|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
You are a developer tasked with writing Python code to use specific tools for a given task. Below is the task briefing and the briefings of the tools available.
|
2
|
+
|
3
|
+
**Task Briefing:**
|
4
|
+
{{ task }}
|
5
|
+
|
6
|
+
**Available Tools:**
|
7
|
+
{{#each tools }}
|
8
|
+
{{ this }}
|
9
|
+
|
10
|
+
{{/each }}
|
11
|
+
|
12
|
+
Please draft the Python code that uses these tools to accomplish the task. Ensure that the code is well-documented and follows best practices. The code should be executable and should include any necessary imports.
|
13
|
+
Further, to ensure I can retrieve the execute result, you need to specify variable names that represent the output of your code. These variables should be named with JSON serializable values.
|
14
|
+
|
15
|
+
|
16
|
+
**Response Format:**
|
17
|
+
1. Provide the Python code as a codeblock.
|
18
|
+
2. Ensure the code can be compiled and executed without errors.
|
19
|
+
|
20
|
+
|
21
|
+
**Example Response:**
|
22
|
+
|
23
|
+
----
|
24
|
+
|
25
|
+
```python
|
26
|
+
from {{tool_module_name}} import ({{#each tool_class_names }}
|
27
|
+
{{this}},
|
28
|
+
{{/each }})
|
29
|
+
|
30
|
+
# Your code here
|
31
|
+
|
32
|
+
output1 = # Your output here
|
33
|
+
output2 = # Your output here
|
34
|
+
another_output = # Your output here
|
35
|
+
|
36
|
+
|
37
|
+
```
|
38
|
+
|
39
|
+
```json
|
40
|
+
[
|
41
|
+
"output1",
|
42
|
+
"output2",
|
43
|
+
"another_output"
|
44
|
+
]
|
45
|
+
```
|
46
|
+
|
47
|
+
----
|
48
|
+
|
49
|
+
**Warning:**
|
50
|
+
|
51
|
+
- No extra explanation is needed. Only the python code and the JSON array is required.
|
52
|
+
- Do not include any imports that are not necessary for the code to run.
|
Binary file
|
@@ -179,7 +179,7 @@ wheels = [
|
|
179
179
|
[[package]]
|
180
180
|
name = "code2prompt"
|
181
181
|
version = "2.0.0"
|
182
|
-
source = { git = "https://github.com/mufeedvh/code2prompt#
|
182
|
+
source = { git = "https://github.com/mufeedvh/code2prompt?rev=d157ee84827458bd6816142e213886487d28bd3d#d157ee84827458bd6816142e213886487d28bd3d" }
|
183
183
|
|
184
184
|
[[package]]
|
185
185
|
name = "colorama"
|
@@ -260,7 +260,7 @@ wheels = [
|
|
260
260
|
|
261
261
|
[[package]]
|
262
262
|
name = "fabricatio"
|
263
|
-
version = "0.2.0.
|
263
|
+
version = "0.2.0.dev18"
|
264
264
|
source = { editable = "." }
|
265
265
|
dependencies = [
|
266
266
|
{ name = "appdirs" },
|
@@ -279,6 +279,16 @@ dependencies = [
|
|
279
279
|
{ name = "rich" },
|
280
280
|
]
|
281
281
|
|
282
|
+
[package.optional-dependencies]
|
283
|
+
full = [
|
284
|
+
{ name = "faiss-cpu" },
|
285
|
+
{ name = "pymilvus" },
|
286
|
+
]
|
287
|
+
rag = [
|
288
|
+
{ name = "faiss-cpu" },
|
289
|
+
{ name = "pymilvus" },
|
290
|
+
]
|
291
|
+
|
282
292
|
[package.dev-dependencies]
|
283
293
|
dev = [
|
284
294
|
{ name = "maturin" },
|
@@ -295,19 +305,14 @@ dev = [
|
|
295
305
|
{ name = "uv" },
|
296
306
|
{ name = "viztracer" },
|
297
307
|
]
|
298
|
-
full = [
|
299
|
-
{ name = "fabricatio" },
|
300
|
-
]
|
301
|
-
rag = [
|
302
|
-
{ name = "faiss-cpu" },
|
303
|
-
{ name = "pymilvus" },
|
304
|
-
]
|
305
308
|
|
306
309
|
[package.metadata]
|
307
310
|
requires-dist = [
|
308
311
|
{ name = "appdirs", specifier = ">=1.4.4" },
|
309
312
|
{ name = "asyncio", specifier = ">=3.4.3" },
|
310
|
-
{ name = "code2prompt", git = "https://github.com/mufeedvh/code2prompt" },
|
313
|
+
{ name = "code2prompt", git = "https://github.com/mufeedvh/code2prompt?rev=d157ee84827458bd6816142e213886487d28bd3d" },
|
314
|
+
{ name = "fabricatio", extras = ["rag"], marker = "extra == 'full'" },
|
315
|
+
{ name = "faiss-cpu", marker = "extra == 'rag'", specifier = ">=1.10.0" },
|
311
316
|
{ name = "gitpython", specifier = ">=3.1.44" },
|
312
317
|
{ name = "litellm", specifier = ">=1.60.0" },
|
313
318
|
{ name = "loguru", specifier = ">=0.7.3" },
|
@@ -315,11 +320,13 @@ requires-dist = [
|
|
315
320
|
{ name = "orjson", specifier = ">=3.10.15" },
|
316
321
|
{ name = "pydantic", specifier = ">=2.10.6" },
|
317
322
|
{ name = "pydantic-settings", specifier = ">=2.7.1" },
|
323
|
+
{ name = "pymilvus", marker = "extra == 'rag'", specifier = ">=2.5.4" },
|
318
324
|
{ name = "pymitter", specifier = ">=1.0.0" },
|
319
325
|
{ name = "questionary", specifier = ">=2.1.0" },
|
320
326
|
{ name = "regex", specifier = ">=2024.11.6" },
|
321
327
|
{ name = "rich", specifier = ">=13.9.4" },
|
322
328
|
]
|
329
|
+
provides-extras = ["rag", "full"]
|
323
330
|
|
324
331
|
[package.metadata.requires-dev]
|
325
332
|
dev = [
|
@@ -337,11 +344,6 @@ dev = [
|
|
337
344
|
{ name = "uv", specifier = ">=0.5.29" },
|
338
345
|
{ name = "viztracer", specifier = ">=1.0.2" },
|
339
346
|
]
|
340
|
-
full = [{ name = "fabricatio", extras = ["rag"] }]
|
341
|
-
rag = [
|
342
|
-
{ name = "faiss-cpu", specifier = ">=1.10.0" },
|
343
|
-
{ name = "pymilvus", specifier = ">=2.5.4" },
|
344
|
-
]
|
345
347
|
|
346
348
|
[[package]]
|
347
349
|
name = "faiss-cpu"
|
@@ -1,96 +0,0 @@
|
|
1
|
-
"""A module for advanced models and functionalities."""
|
2
|
-
|
3
|
-
from typing import List
|
4
|
-
|
5
|
-
from fabricatio._rust_instances import template_manager
|
6
|
-
from fabricatio.models.generic import WithBriefing
|
7
|
-
from fabricatio.models.task import Task
|
8
|
-
from fabricatio.models.usages import LLMUsage, ToolBoxUsage
|
9
|
-
from fabricatio.parser import JsonCapture
|
10
|
-
from loguru import logger
|
11
|
-
from pydantic import NonNegativeFloat, PositiveInt, ValidationError
|
12
|
-
|
13
|
-
|
14
|
-
class ProposeTask(LLMUsage, WithBriefing):
|
15
|
-
"""A class that proposes a task based on a prompt."""
|
16
|
-
|
17
|
-
async def propose(
|
18
|
-
self,
|
19
|
-
prompt: str,
|
20
|
-
max_validations: PositiveInt = 2,
|
21
|
-
model: str | None = None,
|
22
|
-
temperature: NonNegativeFloat | None = None,
|
23
|
-
stop: str | List[str] | None = None,
|
24
|
-
top_p: NonNegativeFloat | None = None,
|
25
|
-
max_tokens: PositiveInt | None = None,
|
26
|
-
stream: bool | None = None,
|
27
|
-
timeout: PositiveInt | None = None,
|
28
|
-
max_retries: PositiveInt | None = None,
|
29
|
-
) -> Task:
|
30
|
-
"""Asynchronously proposes a task based on a given prompt and parameters.
|
31
|
-
|
32
|
-
Parameters:
|
33
|
-
prompt: The prompt text for proposing a task, which is a string that must be provided.
|
34
|
-
max_validations: The maximum number of validations allowed, default is 2.
|
35
|
-
model: The model to be used, default is None.
|
36
|
-
temperature: The sampling temperature, default is None.
|
37
|
-
stop: The stop sequence(s) for generation, default is None.
|
38
|
-
top_p: The nucleus sampling parameter, default is None.
|
39
|
-
max_tokens: The maximum number of tokens to be generated, default is None.
|
40
|
-
stream: Whether to stream the output, default is None.
|
41
|
-
timeout: The timeout for the operation, default is None.
|
42
|
-
max_retries: The maximum number of retries for the operation, default is None.
|
43
|
-
|
44
|
-
Returns:
|
45
|
-
A Task object based on the proposal result.
|
46
|
-
"""
|
47
|
-
if not prompt:
|
48
|
-
err = f"{self.name}: Prompt must be provided."
|
49
|
-
logger.error(err)
|
50
|
-
raise ValueError(err)
|
51
|
-
|
52
|
-
def _validate_json(response: str) -> None | Task:
|
53
|
-
try:
|
54
|
-
cap = JsonCapture.capture(response)
|
55
|
-
logger.debug(f"Response: \n{response}")
|
56
|
-
logger.info(f"Captured JSON: \n{cap}")
|
57
|
-
return Task.model_validate_json(cap)
|
58
|
-
except ValidationError as e:
|
59
|
-
logger.error(f"Failed to parse task from JSON: {e}")
|
60
|
-
return None
|
61
|
-
|
62
|
-
template_data = {"prompt": prompt, "json_example": Task.json_example()}
|
63
|
-
return await self.aask_validate(
|
64
|
-
question=template_manager.render_template("propose_task", template_data),
|
65
|
-
validator=_validate_json,
|
66
|
-
system_message=f"# your personal briefing: \n{self.briefing}",
|
67
|
-
max_validations=max_validations,
|
68
|
-
model=model,
|
69
|
-
temperature=temperature,
|
70
|
-
stop=stop,
|
71
|
-
top_p=top_p,
|
72
|
-
max_tokens=max_tokens,
|
73
|
-
stream=stream,
|
74
|
-
timeout=timeout,
|
75
|
-
max_retries=max_retries,
|
76
|
-
)
|
77
|
-
|
78
|
-
|
79
|
-
class HandleTask(WithBriefing, ToolBoxUsage):
|
80
|
-
"""A class that handles a task based on a task object."""
|
81
|
-
|
82
|
-
async def handle[T](
|
83
|
-
self,
|
84
|
-
task: Task[T],
|
85
|
-
max_validations: PositiveInt = 2,
|
86
|
-
model: str | None = None,
|
87
|
-
temperature: NonNegativeFloat | None = None,
|
88
|
-
stop: str | List[str] | None = None,
|
89
|
-
top_p: NonNegativeFloat | None = None,
|
90
|
-
max_tokens: PositiveInt | None = None,
|
91
|
-
stream: bool | None = None,
|
92
|
-
timeout: PositiveInt | None = None,
|
93
|
-
max_retries: PositiveInt | None = None,
|
94
|
-
) -> T:
|
95
|
-
"""Asynchronously handles a task based on a given task object and parameters."""
|
96
|
-
# TODO: Implement the handle method
|
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
|
{fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/python/fabricatio/actions/communication.py
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
|
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.0.dev16 → fabricatio-0.2.0.dev18}/templates/built-in/cryptography-ctf-solver.hbs
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/templates/built-in/improve-performance.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
|
{fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/templates/built-in/write-github-pull-request.hbs
RENAMED
File without changes
|
{fabricatio-0.2.0.dev16 → fabricatio-0.2.0.dev18}/templates/built-in/write-github-readme.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
|