hamtaa-texttools 1.1.17__py3-none-any.whl → 1.1.18__py3-none-any.whl

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.
@@ -1,56 +0,0 @@
1
- from functools import lru_cache
2
- from pathlib import Path
3
- import yaml
4
-
5
-
6
- class PromptLoader:
7
- """
8
- Utility for loading and formatting YAML prompt templates.
9
-
10
- Responsibilities:
11
- - Load and parse YAML prompt definitions.
12
- - Select the right template (by mode, if applicable).
13
- - Inject variables (`{input}`, plus any extra kwargs) into the templates.
14
- """
15
-
16
- MAIN_TEMPLATE = "main_template"
17
- ANALYZE_TEMPLATE = "analyze_template"
18
-
19
- @staticmethod
20
- def _build_format_args(text: str, **extra_kwargs) -> dict[str, str]:
21
- # Base formatting args
22
- format_args = {"input": text}
23
- # Merge extras
24
- format_args.update(extra_kwargs)
25
- return format_args
26
-
27
- # Use lru_cache to load each file once
28
- @lru_cache(maxsize=32)
29
- def _load_templates(self, prompt_file: str, mode: str | None) -> dict[str, str]:
30
- """
31
- Loads prompt templates from YAML file with optional mode selection.
32
- """
33
- base_dir = Path(__file__).parent.parent.parent / Path("prompts")
34
- prompt_path = base_dir / prompt_file
35
- data = yaml.safe_load(prompt_path.read_text(encoding="utf-8"))
36
-
37
- return {
38
- self.MAIN_TEMPLATE: data[self.MAIN_TEMPLATE][mode]
39
- if mode
40
- else data[self.MAIN_TEMPLATE],
41
- self.ANALYZE_TEMPLATE: data.get(self.ANALYZE_TEMPLATE)[mode]
42
- if mode
43
- else data.get(self.ANALYZE_TEMPLATE),
44
- }
45
-
46
- def load(
47
- self, prompt_file: str, text: str, mode: str, **extra_kwargs
48
- ) -> dict[str, str]:
49
- template_configs = self._load_templates(prompt_file, mode)
50
- format_args = self._build_format_args(text, **extra_kwargs)
51
-
52
- # Inject variables inside each template
53
- for key in template_configs.keys():
54
- template_configs[key] = template_configs[key].format(**format_args)
55
-
56
- return template_configs
File without changes