ai-prompter 0.2.1__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.
- {ai_prompter-0.2.1 → ai_prompter-0.2.2}/PKG-INFO +1 -1
- {ai_prompter-0.2.1 → ai_prompter-0.2.2}/notebooks/prompter_usage.ipynb +13 -13
- {ai_prompter-0.2.1 → ai_prompter-0.2.2}/pyproject.toml +1 -1
- {ai_prompter-0.2.1 → ai_prompter-0.2.2}/src/ai_prompter/__init__.py +20 -8
- {ai_prompter-0.2.1 → ai_prompter-0.2.2}/tests/test_prompter.py +6 -1
- {ai_prompter-0.2.1 → ai_prompter-0.2.2}/uv.lock +1 -1
- {ai_prompter-0.2.1 → ai_prompter-0.2.2}/.env.sample +0 -0
- {ai_prompter-0.2.1 → ai_prompter-0.2.2}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
- {ai_prompter-0.2.1 → ai_prompter-0.2.2}/.github/workflows/publish.yml +0 -0
- {ai_prompter-0.2.1 → ai_prompter-0.2.2}/.gitignore +0 -0
- {ai_prompter-0.2.1 → ai_prompter-0.2.2}/.python-version +0 -0
- {ai_prompter-0.2.1 → ai_prompter-0.2.2}/LICENSE +0 -0
- {ai_prompter-0.2.1 → ai_prompter-0.2.2}/Makefile +0 -0
- {ai_prompter-0.2.1 → ai_prompter-0.2.2}/README.md +0 -0
- {ai_prompter-0.2.1 → ai_prompter-0.2.2}/notebooks/prompts/article.jinja +0 -0
- {ai_prompter-0.2.1 → ai_prompter-0.2.2}/notebooks/prompts/inner.jinja +0 -0
- {ai_prompter-0.2.1 → ai_prompter-0.2.2}/notebooks/prompts/outer.jinja +0 -0
- {ai_prompter-0.2.1 → ai_prompter-0.2.2}/src/ai_prompter/py.typed +0 -0
- {ai_prompter-0.2.1 → ai_prompter-0.2.2}/tests/prompts/greet.jinja +0 -0
@@ -16,7 +16,7 @@
|
|
16
16
|
},
|
17
17
|
{
|
18
18
|
"cell_type": "code",
|
19
|
-
"execution_count":
|
19
|
+
"execution_count": 6,
|
20
20
|
"metadata": {},
|
21
21
|
"outputs": [],
|
22
22
|
"source": [
|
@@ -36,7 +36,7 @@
|
|
36
36
|
},
|
37
37
|
{
|
38
38
|
"cell_type": "code",
|
39
|
-
"execution_count":
|
39
|
+
"execution_count": 7,
|
40
40
|
"metadata": {},
|
41
41
|
"outputs": [
|
42
42
|
{
|
@@ -45,7 +45,7 @@
|
|
45
45
|
"'Write an article about AI.'"
|
46
46
|
]
|
47
47
|
},
|
48
|
-
"execution_count":
|
48
|
+
"execution_count": 7,
|
49
49
|
"metadata": {},
|
50
50
|
"output_type": "execute_result"
|
51
51
|
}
|
@@ -71,7 +71,7 @@
|
|
71
71
|
},
|
72
72
|
{
|
73
73
|
"cell_type": "code",
|
74
|
-
"execution_count":
|
74
|
+
"execution_count": 8,
|
75
75
|
"metadata": {},
|
76
76
|
"outputs": [
|
77
77
|
{
|
@@ -80,7 +80,7 @@
|
|
80
80
|
"'Write an article about AI.'"
|
81
81
|
]
|
82
82
|
},
|
83
|
-
"execution_count":
|
83
|
+
"execution_count": 8,
|
84
84
|
"metadata": {},
|
85
85
|
"output_type": "execute_result"
|
86
86
|
}
|
@@ -103,7 +103,7 @@
|
|
103
103
|
},
|
104
104
|
{
|
105
105
|
"cell_type": "code",
|
106
|
-
"execution_count":
|
106
|
+
"execution_count": 9,
|
107
107
|
"metadata": {},
|
108
108
|
"outputs": [
|
109
109
|
{
|
@@ -112,7 +112,7 @@
|
|
112
112
|
"'This is the outer file \\n\\nThis is the inner file\\n\\nValue: a\\n\\n\\n You selected A\\n\\n\\nThis is the end of the outer file'"
|
113
113
|
]
|
114
114
|
},
|
115
|
-
"execution_count":
|
115
|
+
"execution_count": 9,
|
116
116
|
"metadata": {},
|
117
117
|
"output_type": "execute_result"
|
118
118
|
}
|
@@ -136,7 +136,7 @@
|
|
136
136
|
},
|
137
137
|
{
|
138
138
|
"cell_type": "code",
|
139
|
-
"execution_count":
|
139
|
+
"execution_count": 10,
|
140
140
|
"metadata": {},
|
141
141
|
"outputs": [
|
142
142
|
{
|
@@ -145,7 +145,7 @@
|
|
145
145
|
"ChatPromptTemplate(input_variables=['topic'], input_types={}, partial_variables={}, messages=[HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['topic'], input_types={}, partial_variables={}, template='Write an article about {{topic}}.', template_format='jinja2'), additional_kwargs={})])"
|
146
146
|
]
|
147
147
|
},
|
148
|
-
"execution_count":
|
148
|
+
"execution_count": 10,
|
149
149
|
"metadata": {},
|
150
150
|
"output_type": "execute_result"
|
151
151
|
}
|
@@ -162,7 +162,7 @@
|
|
162
162
|
},
|
163
163
|
{
|
164
164
|
"cell_type": "code",
|
165
|
-
"execution_count":
|
165
|
+
"execution_count": 11,
|
166
166
|
"metadata": {},
|
167
167
|
"outputs": [
|
168
168
|
{
|
@@ -171,7 +171,7 @@
|
|
171
171
|
"ChatPromptTemplate(input_variables=['type'], input_types={}, partial_variables={}, messages=[HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['type'], input_types={}, partial_variables={}, template=\"This is the outer file \\n\\nThis is the inner file\\n\\nValue: {{ type }}\\n\\n{% if type == 'a' %}\\n You selected A\\n{% else %}\\n You didn't select A\\n{% endif %}\\n\\n\\nThis is the end of the outer file\\n\", template_format='jinja2'), additional_kwargs={})])"
|
172
172
|
]
|
173
173
|
},
|
174
|
-
"execution_count":
|
174
|
+
"execution_count": 11,
|
175
175
|
"metadata": {},
|
176
176
|
"output_type": "execute_result"
|
177
177
|
}
|
@@ -184,7 +184,7 @@
|
|
184
184
|
},
|
185
185
|
{
|
186
186
|
"cell_type": "code",
|
187
|
-
"execution_count":
|
187
|
+
"execution_count": 12,
|
188
188
|
"metadata": {},
|
189
189
|
"outputs": [
|
190
190
|
{
|
@@ -193,7 +193,7 @@
|
|
193
193
|
"ChatPromptValue(messages=[HumanMessage(content='This is the outer file \\n\\nThis is the inner file\\n\\nValue: a\\n\\n\\n You selected A\\n\\n\\n\\nThis is the end of the outer file', additional_kwargs={}, response_metadata={})])"
|
194
194
|
]
|
195
195
|
},
|
196
|
-
"execution_count":
|
196
|
+
"execution_count": 12,
|
197
197
|
"metadata": {},
|
198
198
|
"output_type": "execute_result"
|
199
199
|
}
|
@@ -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
|
8
|
+
from typing import Any, Dict, Optional, Union, Callable
|
9
9
|
|
10
10
|
from jinja2 import Environment, FileSystemLoader, Template
|
11
11
|
from pydantic import BaseModel
|
@@ -39,24 +39,36 @@ class Prompter:
|
|
39
39
|
|
40
40
|
def __init__(
|
41
41
|
self,
|
42
|
-
prompt_template:
|
43
|
-
model:
|
44
|
-
|
45
|
-
prompt_dir:
|
42
|
+
prompt_template: str | None = None,
|
43
|
+
model: str | Any | None = None,
|
44
|
+
prompt_variation: str = "default",
|
45
|
+
prompt_dir: str | None = None,
|
46
|
+
template_text: str | None = None,
|
47
|
+
parser: Callable[[str], dict[str, Any]] | None = None,
|
48
|
+
*args,
|
49
|
+
**kwargs,
|
46
50
|
) -> None:
|
47
51
|
"""Initialize the Prompter with a template name, model, and optional custom directory.
|
48
52
|
|
49
53
|
Args:
|
50
54
|
prompt_template (str, optional): The name of the prompt template (without .jinja extension).
|
51
55
|
model (Union[str, Any], optional): The model to use for generation.
|
52
|
-
|
56
|
+
prompt_variation (str, optional): The variation of the prompt template.
|
53
57
|
prompt_dir (str, optional): Custom directory to search for templates.
|
58
|
+
template_text (str, optional): The raw text of the template.
|
59
|
+
parser (Callable[[str], dict[str, Any]], optional): The parser to use for generation.
|
54
60
|
"""
|
61
|
+
if template_text is not None and prompt_template is not None:
|
62
|
+
raise ValueError(
|
63
|
+
"Cannot provide both template_text and prompt_template. Choose one or the other."
|
64
|
+
)
|
55
65
|
self.prompt_template = prompt_template
|
56
|
-
self.
|
66
|
+
self.prompt_variation = prompt_variation
|
67
|
+
self.prompt_dir = prompt_dir
|
57
68
|
self.template_text = template_text
|
69
|
+
self.parser = parser
|
70
|
+
self.template: Template | None = None
|
58
71
|
self.model = model or os.getenv("OPENAI_MODEL", "gpt-4-turbo")
|
59
|
-
self.prompt_dir = prompt_dir
|
60
72
|
self._setup_template(template_text, prompt_dir)
|
61
73
|
|
62
74
|
def _setup_template(
|
@@ -17,10 +17,15 @@ def test_raw_text_template():
|
|
17
17
|
|
18
18
|
|
19
19
|
def test_missing_both_raises():
|
20
|
-
with pytest.raises(ValueError):
|
20
|
+
with pytest.raises(ValueError, match="Either prompt_template or template_text must be provided"):
|
21
21
|
Prompter()
|
22
22
|
|
23
23
|
|
24
|
+
def test_both_parameters_raises():
|
25
|
+
with pytest.raises(ValueError, match="Cannot provide both"):
|
26
|
+
Prompter(template_text="Hello", prompt_template="template")
|
27
|
+
|
28
|
+
|
24
29
|
def test_base_model_data():
|
25
30
|
class DataModel(BaseModel):
|
26
31
|
foo: str
|
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
|