fabricatio 0.2.1.dev4__tar.gz → 0.2.2__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.1.dev4 → fabricatio-0.2.2}/PKG-INFO +1 -1
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/examples/make_a_rating/rating.py +26 -1
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/pyproject.toml +1 -1
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/capabilities/rating.py +79 -1
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/config.py +3 -0
- fabricatio-0.2.2/templates/built-in/draft_rating_weights_klee.hbs +23 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/extract_criteria_from_reasons.hbs +1 -1
- fabricatio-0.2.2/templates.tar.gz +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/uv.lock +1 -1
- fabricatio-0.2.1.dev4/templates.tar.gz +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/.github/workflows/build-package.yaml +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/.github/workflows/ruff.yaml +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/.github/workflows/tests.yaml +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/.gitignore +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/.python-version +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/Cargo.lock +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/Cargo.toml +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/LICENSE +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/Makefile +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/README.md +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/examples/llm_usages/llm_usage.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/examples/make_diary/commits.json +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/examples/make_diary/diary.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/examples/minor/hello_fabricatio.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/examples/propose_task/propose.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/examples/simple_chat/chat.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/examples/task_handle/handle_task.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/__init__.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/_rust.pyi +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/_rust_instances.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/actions/__init__.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/actions/communication.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/actions/transmission.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/capabilities/task.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/core.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/decorators.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/fs/__init__.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/fs/curd.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/fs/readers.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/journal.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/models/action.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/models/events.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/models/generic.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/models/kwargs_types.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/models/role.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/models/task.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/models/tool.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/models/usages.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/models/utils.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/parser.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/py.typed +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/toolboxes/__init__.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/toolboxes/arithmetic.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/toolboxes/fs.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/python/fabricatio/toolboxes/task.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/src/hash.rs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/src/lib.rs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/src/templates.rs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/claude-xml.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/clean-up-code.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/dependencies.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/document-the-code.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/draft_rating_criteria.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/draft_rating_manual.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/draft_tool_usage_code.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/extract_reasons_from_examples.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/fix-bugs.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/improve-performance.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/make_choice.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/make_judgment.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/propose_task.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/rate_fine_grind.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/refactor.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/task_briefing.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/web-ctf-solver.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/write-git-commit.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/write-github-pull-request.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/write-github-readme.hbs +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/tests/test_config.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/tests/test_models/test_action.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/tests/test_models/test_advanced.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/tests/test_models/test_generic.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/tests/test_models/test_role.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/tests/test_models/test_task.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/tests/test_models/test_tool.py +0 -0
- {fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/tests/test_models/test_usages.py +0 -0
@@ -58,12 +58,26 @@ class MakeCriteria(Action):
|
|
58
58
|
name: str = "make criteria"
|
59
59
|
output_key: str = "criteria"
|
60
60
|
|
61
|
-
async def _execute(self,
|
61
|
+
async def _execute(self, rate_topic: str, to_rate: List[str], **cxt: Unpack) -> Set[str]:
|
62
62
|
criteria = await self.draft_rating_criteria_from_examples(rate_topic, to_rate)
|
63
63
|
logger.info(f"Criteria: \n{criteria}")
|
64
64
|
return set(criteria)
|
65
65
|
|
66
66
|
|
67
|
+
class MakeCompositeScore(Action):
|
68
|
+
"""Make a composite score."""
|
69
|
+
|
70
|
+
name: str = "make composite score"
|
71
|
+
|
72
|
+
output_key: str = "task_output"
|
73
|
+
|
74
|
+
async def _execute(self, rate_topic: str, to_rate: List[str], **cxt: Unpack) -> List[float]:
|
75
|
+
return await self.composite_score(
|
76
|
+
rate_topic,
|
77
|
+
to_rate,
|
78
|
+
)
|
79
|
+
|
80
|
+
|
67
81
|
async def main() -> None:
|
68
82
|
"""Main function."""
|
69
83
|
role = Role(
|
@@ -85,6 +99,13 @@ async def main() -> None:
|
|
85
99
|
"rate_topic": "if the food is 'good'",
|
86
100
|
},
|
87
101
|
),
|
102
|
+
Event.instantiate_from("make_composite_score").push_wildcard().push("pending"): WorkFlow(
|
103
|
+
name="Make composite score",
|
104
|
+
steps=(WhatToRate, MakeCompositeScore),
|
105
|
+
extra_init_context={
|
106
|
+
"rate_topic": "if the food is 'good'",
|
107
|
+
},
|
108
|
+
),
|
88
109
|
},
|
89
110
|
)
|
90
111
|
task = await role.propose(
|
@@ -98,6 +119,10 @@ async def main() -> None:
|
|
98
119
|
|
99
120
|
logger.success(f"Generated Criteria: \n{generated_criteria}")
|
100
121
|
|
122
|
+
composite_score = await task.move_to("make_composite_score").delegate()
|
123
|
+
|
124
|
+
logger.success(f"Composite Score: \n{composite_score}")
|
125
|
+
|
101
126
|
|
102
127
|
if __name__ == "__main__":
|
103
128
|
asyncio.run(main())
|
@@ -12,7 +12,7 @@ from fabricatio.models.generic import WithBriefing
|
|
12
12
|
from fabricatio.models.kwargs_types import GenerateKwargs, ValidateKwargs
|
13
13
|
from fabricatio.models.usages import LLMUsage
|
14
14
|
from fabricatio.parser import JsonCapture
|
15
|
-
from more_itertools import flatten
|
15
|
+
from more_itertools import flatten, windowed
|
16
16
|
from pydantic import NonNegativeInt, PositiveInt
|
17
17
|
|
18
18
|
|
@@ -275,3 +275,81 @@ class GiveRating(WithBriefing, LLMUsage):
|
|
275
275
|
validator=_criteria_validator,
|
276
276
|
**kwargs,
|
277
277
|
)
|
278
|
+
|
279
|
+
async def drafting_rating_weights_klee(
|
280
|
+
self,
|
281
|
+
topic: str,
|
282
|
+
criteria: Set[str],
|
283
|
+
**kwargs: Unpack[ValidateKwargs],
|
284
|
+
) -> Dict[str, float]:
|
285
|
+
"""Drafts rating weights for a given topic and criteria using the Klee method.
|
286
|
+
|
287
|
+
Args:
|
288
|
+
topic (str): The topic for the rating weights.
|
289
|
+
criteria (Set[str]): A set of criteria for the rating weights.
|
290
|
+
**kwargs (Unpack[ValidateKwargs]): Additional keyword arguments for the LLM usage.
|
291
|
+
|
292
|
+
Returns:
|
293
|
+
Dict[str, float]: A dictionary representing the drafted rating weights for each criterion.
|
294
|
+
"""
|
295
|
+
if len(criteria) < 2: # noqa: PLR2004
|
296
|
+
raise ValueError("At least two criteria are required to draft rating weights")
|
297
|
+
|
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
|
+
criteria = list(criteria) # freeze the order
|
304
|
+
windows = windowed(criteria, 2)
|
305
|
+
|
306
|
+
# get the importance multiplier indicating how important is second criterion compared to the first one
|
307
|
+
relative_weights = await self.aask_validate_batch(
|
308
|
+
questions=[
|
309
|
+
template_manager.render_template(
|
310
|
+
configs.templates.draft_rating_weights_klee_template,
|
311
|
+
{
|
312
|
+
"topic": topic,
|
313
|
+
"first": pair[0],
|
314
|
+
"second": pair[1],
|
315
|
+
},
|
316
|
+
)
|
317
|
+
for pair in windows
|
318
|
+
],
|
319
|
+
validator=_validator,
|
320
|
+
**GenerateKwargs(system_message=f"# your personal briefing: \n{self.briefing}", **kwargs),
|
321
|
+
)
|
322
|
+
weights = [1]
|
323
|
+
for rw in relative_weights:
|
324
|
+
weights.append(weights[-1] * rw)
|
325
|
+
total = sum(weights)
|
326
|
+
return dict(zip(criteria, [w / total for w in weights], strict=True))
|
327
|
+
|
328
|
+
async def composite_score(
|
329
|
+
self,
|
330
|
+
topic: str,
|
331
|
+
to_rate: List[str],
|
332
|
+
reasons_count: PositiveInt = 2,
|
333
|
+
criteria_count: PositiveInt = 5,
|
334
|
+
**kwargs: Unpack[ValidateKwargs],
|
335
|
+
) -> List[float]:
|
336
|
+
"""Calculates the composite scores for a list of items based on a given topic and criteria.
|
337
|
+
|
338
|
+
Args:
|
339
|
+
topic (str): The topic for the rating.
|
340
|
+
to_rate (List[str]): A list of strings to be rated.
|
341
|
+
reasons_count (PositiveInt, optional): The number of reasons to extract from each pair of examples. Defaults to 2.
|
342
|
+
criteria_count (PositiveInt, optional): The number of criteria to draft. Defaults to 5.
|
343
|
+
**kwargs (Unpack[ValidateKwargs]): Additional keyword arguments for the LLM usage.
|
344
|
+
|
345
|
+
Returns:
|
346
|
+
List[float]: A list of composite scores for the items.
|
347
|
+
"""
|
348
|
+
criteria = await self.draft_rating_criteria_from_examples(
|
349
|
+
topic, to_rate, reasons_count, criteria_count, **kwargs
|
350
|
+
)
|
351
|
+
weights = await self.drafting_rating_weights_klee(topic, criteria, **kwargs)
|
352
|
+
logger.info(f"Criteria: {criteria}\nWeights: {weights}")
|
353
|
+
ratings_seq = await self.rate(to_rate, topic, criteria, **kwargs)
|
354
|
+
|
355
|
+
return [sum(ratings[c] * weights[c] for c in criteria) for ratings in ratings_seq]
|
@@ -172,6 +172,9 @@ class TemplateConfig(BaseModel):
|
|
172
172
|
extract_criteria_from_reasons_template: str = Field(default="extract_criteria_from_reasons")
|
173
173
|
"""The name of the extract criteria from reasons template which will be used to extract criteria from reasons."""
|
174
174
|
|
175
|
+
draft_rating_weights_klee_template: str = Field(default="draft_rating_weights_klee")
|
176
|
+
"""The name of the draft rating weights klee template which will be used to draft rating weights with Klee method."""
|
177
|
+
|
175
178
|
|
176
179
|
class MagikaConfig(BaseModel):
|
177
180
|
"""Magika configuration class."""
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Task:
|
2
|
+
Please compare the following criteria for the topic "{{topic}}":
|
3
|
+
|
4
|
+
First Criterion: {{first}}
|
5
|
+
Second Criterion: {{second}}
|
6
|
+
|
7
|
+
How much more important is the `{{second}}` compared to the `{{first}}` within the topic of `{{topic}}`? Provide a Positive floating-point number where 1.0 means they are equally important, values greater than 1.0 mean the `{{second}}` is more important, and values less than 1.0 mean the `{{first}}` is more important.
|
8
|
+
Your response SHALL be a Positive floating-point number within a JSON codeblock.
|
9
|
+
# Examples:
|
10
|
+
|
11
|
+
Topic: "Best icecream"
|
12
|
+
First Criterion: "Taste"
|
13
|
+
Second Criterion: "Texture"
|
14
|
+
|
15
|
+
----- Start of response example -----
|
16
|
+
```json
|
17
|
+
1.5
|
18
|
+
```
|
19
|
+
----- End of response example -----
|
20
|
+
|
21
|
+
# Warning:
|
22
|
+
- Your response must be a POSITIVE floating-point number within a JSON codeblock.
|
23
|
+
- No explanation or additional information is needed, only the POSITIVE floating-point number.
|
{fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/extract_criteria_from_reasons.hbs
RENAMED
@@ -21,4 +21,4 @@ Extract 4 criteria from the given reasons list
|
|
21
21
|
|
22
22
|
# Warning:
|
23
23
|
- The output must be formatted as a JSON array with exactly {{criteria_count}} strings, each representing a distinct criterion. Follow the structure shown in the response example closely. Responses not matching this format will fail validation.
|
24
|
-
|
24
|
+
- The criteria extracted should be relevant and distinct, ranking DESCENDING in terms of importance or frequency in the given reasons list.
|
Binary file
|
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
|
{fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/binary-exploitation-ctf-solver.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
|
{fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/extract_reasons_from_examples.hbs
RENAMED
File without changes
|
{fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/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
|
{fabricatio-0.2.1.dev4 → fabricatio-0.2.2}/templates/built-in/reverse-engineering-ctf-solver.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
|
File without changes
|