fabricatio 0.2.6.dev2__tar.gz → 0.2.6.dev3__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.6.dev2 → fabricatio-0.2.6.dev3}/Makefile +5 -5
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/PKG-INFO +1 -1
- fabricatio-0.2.6.dev3/examples/correct/correct_loop.py +30 -0
- fabricatio-0.2.6.dev3/examples/search_bibtex/.gitignore +1 -0
- fabricatio-0.2.6.dev3/examples/search_bibtex/search.py +12 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/pyproject.toml +2 -2
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/_rust.pyi +15 -1
- fabricatio-0.2.6.dev3/src/bib_tools.rs +88 -0
- fabricatio-0.2.6.dev3/templates.tar.gz +0 -0
- fabricatio-0.2.6.dev3/uv.lock +1547 -0
- fabricatio-0.2.6.dev2/src/bib_tools.rs +0 -73
- fabricatio-0.2.6.dev2/templates.tar.gz +0 -0
- fabricatio-0.2.6.dev2/uv.lock +0 -1549
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/.github/workflows/build-package.yaml +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/.github/workflows/ruff.yaml +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/.github/workflows/tests.yaml +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/.gitignore +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/.python-version +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/Cargo.lock +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/Cargo.toml +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/LICENSE +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/README.md +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/examples/correct/correct.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/examples/extract_and_review/.gitignore +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/examples/extract_and_review/extract_and_review.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/examples/extract_article/extract.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/examples/llm_usages/llm_usage.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/examples/make_a_rating/rating.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/examples/make_diary/commits.json +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/examples/make_diary/diary.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/examples/minor/hello_fabricatio.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/examples/minor/write_a_poem.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/examples/propose_task/propose.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/examples/reviewer/review.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/examples/simple_chat/chat.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/examples/simple_rag/simple_rag.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/examples/task_handle/handle_task.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/examples/write_outline/.gitignore +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/examples/write_outline/write_outline.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/__init__.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/_rust_instances.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/actions/article.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/actions/output.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/actions/rag.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/capabilities/correct.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/capabilities/propose.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/capabilities/rag.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/capabilities/rating.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/capabilities/review.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/capabilities/task.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/config.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/core.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/decorators.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/fs/__init__.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/fs/curd.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/fs/readers.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/journal.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/models/action.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/models/events.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/models/extra.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/models/generic.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/models/kwargs_types.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/models/role.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/models/task.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/models/tool.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/models/usages.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/models/utils.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/parser.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/py.typed +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/toolboxes/__init__.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/toolboxes/arithmetic.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/toolboxes/fs.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/workflows/articles.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/python/fabricatio/workflows/rag.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/src/hash.rs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/src/hbs_helpers.rs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/src/lib.rs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/src/templates.rs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/binary-exploitation-ctf-solver.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/claude-xml.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/clean-up-code.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/correct.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/create_json_obj.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/cryptography-ctf-solver.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/dependencies.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/document-the-code.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/draft_rating_criteria.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/draft_rating_manual.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/draft_rating_weights_klee.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/draft_tool_usage_code.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/extract_criteria_from_reasons.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/extract_reasons_from_examples.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/find-security-vulnerabilities.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/fix-bugs.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/generic_string.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/improve-performance.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/liststr.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/make_choice.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/make_judgment.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/pathstr.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/rate_fine_grind.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/refactor.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/refined_query.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/retrieved_display.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/reverse-engineering-ctf-solver.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/review_string.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/task_briefing.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/web-ctf-solver.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/write-git-commit.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/write-github-pull-request.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/templates/built-in/write-github-readme.hbs +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/tests/test_config.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/tests/test_models/test_action.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/tests/test_models/test_advanced.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/tests/test_models/test_generic.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/tests/test_models/test_role.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/tests/test_models/test_task.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/tests/test_models/test_tool.py +0 -0
- {fabricatio-0.2.6.dev2 → fabricatio-0.2.6.dev3}/tests/test_models/test_usages.py +0 -0
@@ -12,16 +12,16 @@ tools:
|
|
12
12
|
rm $(DATA)/scripts/*.dwarf || true
|
13
13
|
|
14
14
|
dev: tools
|
15
|
-
uvx
|
15
|
+
uvx --project . maturin develop --uv -r
|
16
16
|
|
17
17
|
bdist:clean tools
|
18
|
-
uvx
|
19
|
-
uvx
|
18
|
+
uvx --project . maturin sdist -o $(DIST)
|
19
|
+
uvx --project . maturin build -r -o $(DIST)
|
20
20
|
|
21
21
|
clean:
|
22
22
|
rm -rf $(DIST) $(DATA)
|
23
23
|
|
24
24
|
publish:tools
|
25
|
-
uvx
|
26
|
-
uvx
|
25
|
+
uvx --project . maturin publish --skip-existing
|
26
|
+
uvx --project . maturin upload --skip-existing $(DIST)/*
|
27
27
|
.PHONY: tools
|
@@ -0,0 +1,30 @@
|
|
1
|
+
"""Example of review usage."""
|
2
|
+
|
3
|
+
import asyncio
|
4
|
+
|
5
|
+
from fabricatio import Role, logger
|
6
|
+
from questionary import confirm
|
7
|
+
from rich import print as r_print
|
8
|
+
|
9
|
+
|
10
|
+
async def main() -> None:
|
11
|
+
"""Main function."""
|
12
|
+
role = Role(
|
13
|
+
name="Reviewer",
|
14
|
+
description="A role that reviews the code.",
|
15
|
+
)
|
16
|
+
|
17
|
+
code = await role.aask(
|
18
|
+
"write a cli app using rust with clap which can generate a basic manifest of a standard rust project, output code only,no extra explanation, you should using derive mode of clap."
|
19
|
+
)
|
20
|
+
|
21
|
+
logger.success(f"Code: \n{code}")
|
22
|
+
|
23
|
+
while await confirm("Do you want to review the code?").ask_async():
|
24
|
+
code = await role.correct_string(code, topic="If the cli app is of good design", supervisor_check=False)
|
25
|
+
r_print(code)
|
26
|
+
logger.success(f"Corrected: \n{code}")
|
27
|
+
|
28
|
+
|
29
|
+
if __name__ == "__main__":
|
30
|
+
asyncio.run(main())
|
@@ -0,0 +1 @@
|
|
1
|
+
*.bib
|
@@ -0,0 +1,12 @@
|
|
1
|
+
from fabricatio import BibManager
|
2
|
+
|
3
|
+
b = BibManager("Exported Items.bib")
|
4
|
+
print(b.get_cite_key("Fault Diagnosis of Wind Turbines"))
|
5
|
+
print(
|
6
|
+
b.get_cite_key_fuzzy(
|
7
|
+
"Fault Diagnosis of Wind Turbines"
|
8
|
+
)
|
9
|
+
)
|
10
|
+
|
11
|
+
print(b.list_titles())
|
12
|
+
print(b.list_titles(True))
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[project]
|
2
2
|
name = "fabricatio"
|
3
|
-
version = "0.2.6-
|
3
|
+
version = "0.2.6-dev3"
|
4
4
|
description = "A LLM multi-agent framework."
|
5
5
|
readme = "README.md"
|
6
6
|
license = { file = "LICENSE" }
|
@@ -85,7 +85,7 @@ full = [
|
|
85
85
|
]
|
86
86
|
|
87
87
|
[tool.ruff]
|
88
|
-
include = ["pyproject.toml", "python/fabricatio/*.py","python/fabricatio/*.pyi", "examples/*.py"]
|
88
|
+
include = ["pyproject.toml", "python/fabricatio/*.py", "python/fabricatio/*.pyi", "examples/*.py"]
|
89
89
|
line-length = 120
|
90
90
|
target-version = "py312"
|
91
91
|
[tool.ruff.format]
|
@@ -1,6 +1,7 @@
|
|
1
1
|
from pathlib import Path
|
2
2
|
from typing import Any, Dict, List, Optional
|
3
3
|
|
4
|
+
|
4
5
|
class TemplateManager:
|
5
6
|
"""Template rendering engine using Handlebars templates.
|
6
7
|
|
@@ -9,8 +10,9 @@ class TemplateManager:
|
|
9
10
|
|
10
11
|
See: https://crates.io/crates/handlebars
|
11
12
|
"""
|
13
|
+
|
12
14
|
def __init__(
|
13
|
-
|
15
|
+
self, template_dirs: List[Path], suffix: Optional[str] = None, active_loading: Optional[bool] = None
|
14
16
|
) -> None:
|
15
17
|
"""Initialize the template manager.
|
16
18
|
|
@@ -54,6 +56,7 @@ class TemplateManager:
|
|
54
56
|
RuntimeError: If template rendering fails
|
55
57
|
"""
|
56
58
|
|
59
|
+
|
57
60
|
def blake3_hash(content: bytes) -> str:
|
58
61
|
"""Calculate the BLAKE3 cryptographic hash of data.
|
59
62
|
|
@@ -64,6 +67,7 @@ def blake3_hash(content: bytes) -> str:
|
|
64
67
|
Hex-encoded BLAKE3 hash string
|
65
68
|
"""
|
66
69
|
|
70
|
+
|
67
71
|
class BibManager:
|
68
72
|
"""BibTeX bibliography manager for parsing and querying citation data."""
|
69
73
|
|
@@ -100,3 +104,13 @@ class BibManager:
|
|
100
104
|
Uses nucleo_matcher for high-quality fuzzy text searching
|
101
105
|
See: https://crates.io/crates/nucleo-matcher
|
102
106
|
"""
|
107
|
+
|
108
|
+
def list_titles(self, is_verbatim: Optional[bool] = False) -> List[str]:
|
109
|
+
"""List all titles in the bibliography.
|
110
|
+
|
111
|
+
Args:
|
112
|
+
is_verbatim: Whether to return verbatim titles (without formatting)
|
113
|
+
|
114
|
+
Returns:
|
115
|
+
List of all titles in the bibliography
|
116
|
+
"""
|
@@ -0,0 +1,88 @@
|
|
1
|
+
use biblatex::{Bibliography, ChunksExt};
|
2
|
+
use nucleo_matcher::pattern::{AtomKind, CaseMatching, Normalization, Pattern};
|
3
|
+
use nucleo_matcher::{Config, Matcher, Utf32Str};
|
4
|
+
use pyo3::exceptions::PyRuntimeError;
|
5
|
+
use pyo3::prelude::*;
|
6
|
+
use rayon::prelude::*;
|
7
|
+
|
8
|
+
#[pyclass]
|
9
|
+
pub struct BibManager {
|
10
|
+
source: Bibliography,
|
11
|
+
}
|
12
|
+
|
13
|
+
|
14
|
+
#[pymethods]
|
15
|
+
impl BibManager {
|
16
|
+
/// Create a new BibManager instance.
|
17
|
+
#[new]
|
18
|
+
fn new(path: String) -> PyResult<Self> {
|
19
|
+
let bib = std::fs::read_to_string(path)
|
20
|
+
.map_err(|e| PyErr::new::<PyRuntimeError, _>(e.to_string()))?;
|
21
|
+
|
22
|
+
let source = Bibliography::parse(&bib)
|
23
|
+
.map_err(|e| PyErr::new::<PyRuntimeError, _>(e.to_string()))?;
|
24
|
+
|
25
|
+
Ok(BibManager { source })
|
26
|
+
}
|
27
|
+
|
28
|
+
/// find the cite key of an article with given title
|
29
|
+
fn get_cite_key(&self, title: String) -> Option<String> {
|
30
|
+
let title_lower = title.to_lowercase();
|
31
|
+
|
32
|
+
self.source.iter().par_bridge()
|
33
|
+
.find_map_any(|entry| {
|
34
|
+
let entry_title = entry.title()
|
35
|
+
.map_err(|e| PyErr::new::<PyRuntimeError, _>(format!("{}", e)))
|
36
|
+
.ok()?
|
37
|
+
.to_biblatex_string(false)
|
38
|
+
.replace("{", "")
|
39
|
+
.replace("}", "")
|
40
|
+
.to_lowercase();
|
41
|
+
|
42
|
+
(entry_title == title_lower).then(|| entry.key.clone())
|
43
|
+
})
|
44
|
+
}
|
45
|
+
|
46
|
+
/// Find the corresponding cite key of an article with given query string using fuzzy matcher
|
47
|
+
fn get_cite_key_fuzzy(&self, query: String) -> Option<String> {
|
48
|
+
let mut matcher = Matcher::new(Config::DEFAULT);
|
49
|
+
let pattern = Pattern::new(
|
50
|
+
query.as_str(),
|
51
|
+
CaseMatching::Ignore,
|
52
|
+
Normalization::Smart,
|
53
|
+
AtomKind::Substring,
|
54
|
+
);
|
55
|
+
|
56
|
+
|
57
|
+
self.source.iter()
|
58
|
+
.map(|entry| {
|
59
|
+
let mut buf = vec![];
|
60
|
+
let text = entry.to_biblatex_string().replace("{", "")
|
61
|
+
.replace("}", "");
|
62
|
+
(pattern.score(Utf32Str::new(text.as_str(), &mut buf), &mut matcher), entry)
|
63
|
+
})
|
64
|
+
.par_bridge()
|
65
|
+
// Use filter_map's more concise form with pattern matching
|
66
|
+
.filter_map(|(maybe_score, entry)| maybe_score.map(|score| (score, entry)))
|
67
|
+
.max_by_key(|(score, _)| *score)
|
68
|
+
.map(|(_, entry)| entry.key.clone())
|
69
|
+
}
|
70
|
+
#[pyo3(signature = (is_verbatim=false))]
|
71
|
+
fn list_titles(&self, is_verbatim: bool) -> Vec<String> {
|
72
|
+
self.source.iter().map(|entry| {
|
73
|
+
entry.title()
|
74
|
+
.map_err(|e| PyErr::new::<PyRuntimeError, _>(format!("{}", e)))
|
75
|
+
.ok()
|
76
|
+
.unwrap()
|
77
|
+
.to_biblatex_string(is_verbatim)
|
78
|
+
.replace("{", "")
|
79
|
+
.replace("}", "")
|
80
|
+
}).collect::<Vec<_>>()
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
|
85
|
+
pub(crate) fn register(_: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
|
86
|
+
m.add_class::<BibManager>()?;
|
87
|
+
Ok(())
|
88
|
+
}
|
Binary file
|