ai-prompter 0.2.2__py3-none-any.whl → 0.2.3__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.
ai_prompter/__init__.py CHANGED
@@ -5,7 +5,7 @@ A prompt management module using Jinja to generate complex prompts with simple t
5
5
  import os
6
6
  from dataclasses import dataclass
7
7
  from datetime import datetime
8
- from typing import Any, Dict, Optional, Union, Callable
8
+ from typing import Any, Dict, List, Optional, Union, Callable
9
9
 
10
10
  from jinja2 import Environment, FileSystemLoader, Template
11
11
  from pydantic import BaseModel
@@ -36,6 +36,8 @@ class Prompter:
36
36
  template: Optional[Union[str, Template]] = None
37
37
  template_text: Optional[str] = None
38
38
  parser: Optional[Any] = None
39
+ text_templates: Optional[Dict[str, str]] = None
40
+ prompt_folders: Optional[List[str]] = None
39
41
 
40
42
  def __init__(
41
43
  self,
@@ -69,6 +71,8 @@ class Prompter:
69
71
  self.parser = parser
70
72
  self.template: Template | None = None
71
73
  self.model = model or os.getenv("OPENAI_MODEL", "gpt-4-turbo")
74
+ self.text_templates = {}
75
+ self.prompt_folders = []
72
76
  self._setup_template(template_text, prompt_dir)
73
77
 
74
78
  def _setup_template(
@@ -100,9 +104,11 @@ class Prompter:
100
104
  prompt_dirs.append(prompt_path_default)
101
105
  env = Environment(loader=FileSystemLoader(prompt_dirs))
102
106
  self.template = env.get_template(f"{self.prompt_template}.jinja")
107
+ self.prompt_folders = prompt_dirs
103
108
  else:
104
109
  self.template_text = template_text
105
110
  self.template = Template(template_text)
111
+ self.text_templates[self.prompt_template] = template_text
106
112
 
107
113
  def to_langchain(self):
108
114
  # Support for both text-based and file-based templates with LangChain
@@ -187,6 +193,28 @@ class Prompter:
187
193
  "Either prompt_template with a valid template or template_text must be provided for LangChain conversion"
188
194
  )
189
195
 
196
+ def template_location(self, template_name: str) -> str:
197
+ """
198
+ Returns the location of the template used for the given template name.
199
+ If the template is a text template (not a file), returns 'text'.
200
+ If the template is not found, returns 'not found'.
201
+
202
+ Args:
203
+ template_name (str): The name of the template to check.
204
+
205
+ Returns:
206
+ str: The file path of the template, or 'text' if it's a text template, or 'not found' if the template doesn't exist.
207
+ """
208
+ if template_name in self.text_templates:
209
+ return 'text'
210
+
211
+ for folder in self.prompt_folders:
212
+ template_file = os.path.join(folder, f"{template_name}.jinja")
213
+ if os.path.exists(template_file):
214
+ return template_file
215
+
216
+ return 'not found'
217
+
190
218
  @classmethod
191
219
  def from_text(
192
220
  cls, text: str, model: Optional[Union[str, Any]] = None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ai-prompter
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: A prompt management library using Jinja2 templates to build complex prompts easily.
5
5
  Author-email: LUIS NOVO <lfnovo@gmail.com>
6
6
  License: MIT
@@ -0,0 +1,6 @@
1
+ ai_prompter/__init__.py,sha256=l5PTvboNK5uUSVoAJbNuntFc3iUlVCmGsThA8Qy3WI4,11894
2
+ ai_prompter/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
3
+ ai_prompter-0.2.3.dist-info/METADATA,sha256=o2E-K4xbBm69yJOxg6OFeqiIPUQFmwcXtDusefavdWA,6950
4
+ ai_prompter-0.2.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
+ ai_prompter-0.2.3.dist-info/licenses/LICENSE,sha256=cS0_fa_8BoP0PvVG8D19pn_HDJrG96hd4PyEm9nkRo8,1066
6
+ ai_prompter-0.2.3.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- ai_prompter/__init__.py,sha256=p3AyJ9R3C3c8BL2DdMxwYFEv0UMcH-Bz_d6nQ-YjKKA,10744
2
- ai_prompter/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
3
- ai_prompter-0.2.2.dist-info/METADATA,sha256=wKeWaoaiYixNYEAjEmkhZYp8FfO68hwjtfjApHgtvIQ,6950
4
- ai_prompter-0.2.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
5
- ai_prompter-0.2.2.dist-info/licenses/LICENSE,sha256=cS0_fa_8BoP0PvVG8D19pn_HDJrG96hd4PyEm9nkRo8,1066
6
- ai_prompter-0.2.2.dist-info/RECORD,,