textprompts 0.0.2__tar.gz → 0.0.3__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.
- {textprompts-0.0.2 → textprompts-0.0.3}/PKG-INFO +14 -4
- {textprompts-0.0.2 → textprompts-0.0.3}/README.md +13 -3
- {textprompts-0.0.2 → textprompts-0.0.3}/pyproject.toml +4 -1
- {textprompts-0.0.2 → textprompts-0.0.3}/src/textprompts/_parser.py +13 -3
- {textprompts-0.0.2 → textprompts-0.0.3}/src/textprompts/config.py +8 -1
- {textprompts-0.0.2 → textprompts-0.0.3}/src/textprompts/models.py +18 -0
- {textprompts-0.0.2 → textprompts-0.0.3}/src/textprompts/__init__.py +0 -0
- {textprompts-0.0.2 → textprompts-0.0.3}/src/textprompts/__main__.py +0 -0
- {textprompts-0.0.2 → textprompts-0.0.3}/src/textprompts/cli.py +0 -0
- {textprompts-0.0.2 → textprompts-0.0.3}/src/textprompts/errors.py +0 -0
- {textprompts-0.0.2 → textprompts-0.0.3}/src/textprompts/loaders.py +0 -0
- {textprompts-0.0.2 → textprompts-0.0.3}/src/textprompts/placeholder_utils.py +0 -0
- {textprompts-0.0.2 → textprompts-0.0.3}/src/textprompts/prompt_string.py +0 -0
- {textprompts-0.0.2 → textprompts-0.0.3}/src/textprompts/py.typed +0 -0
- {textprompts-0.0.2 → textprompts-0.0.3}/src/textprompts/safe_string.py +0 -0
- {textprompts-0.0.2 → textprompts-0.0.3}/src/textprompts/savers.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: textprompts
|
3
|
-
Version: 0.0.
|
3
|
+
Version: 0.0.3
|
4
4
|
Summary: Minimal text-based prompt-loader with TOML front-matter
|
5
5
|
Keywords: prompts,toml,frontmatter,template
|
6
6
|
Author: Jan Siml
|
@@ -24,6 +24,13 @@ Description-Content-Type: text/markdown
|
|
24
24
|
|
25
25
|
# textprompts
|
26
26
|
|
27
|
+
[](https://pypi.org/project/textprompts/)
|
28
|
+
[](https://pypi.org/project/textprompts/)
|
29
|
+
[](https://github.com/svilupp/textprompts/actions)
|
30
|
+
[](https://codecov.io/gh/svilupp/textprompts)
|
31
|
+
[](https://github.com/svilupp/textprompts/blob/main/LICENSE)
|
32
|
+
|
33
|
+
|
27
34
|
> **So simple, it's not even worth vibing about coding yet it just makes so much sense.**
|
28
35
|
|
29
36
|
Are you tired of vendors trying to sell you fancy UIs for prompt management that just make your system more confusing and harder to debug? Isn't it nice to just have your prompts **next to your code**?
|
@@ -59,7 +66,6 @@ title = "Customer Greeting"
|
|
59
66
|
version = "1.0.0"
|
60
67
|
description = "Friendly greeting for customer support"
|
61
68
|
---
|
62
|
-
|
63
69
|
Hello {customer_name}!
|
64
70
|
|
65
71
|
Welcome to {company_name}. We're here to help you with {issue_type}.
|
@@ -74,6 +80,8 @@ import textprompts
|
|
74
80
|
|
75
81
|
# Just load it - works with or without metadata
|
76
82
|
prompt = textprompts.load_prompt("greeting.txt")
|
83
|
+
# Or simply
|
84
|
+
alt = textprompts.Prompt("greeting.txt")
|
77
85
|
|
78
86
|
# Use it safely - all placeholders must be provided
|
79
87
|
message = prompt.prompt.format(
|
@@ -220,7 +228,6 @@ title = "Product Search Tool"
|
|
220
228
|
version = "2.1.0"
|
221
229
|
description = "Search our product catalog"
|
222
230
|
---
|
223
|
-
|
224
231
|
{
|
225
232
|
"type": "function",
|
226
233
|
"function": {
|
@@ -306,7 +313,6 @@ description = "What this prompt does"
|
|
306
313
|
created = "2024-01-15"
|
307
314
|
tags = ["customer-support", "greeting"]
|
308
315
|
---
|
309
|
-
|
310
316
|
Your prompt content goes here.
|
311
317
|
|
312
318
|
Use {variables} for templating.
|
@@ -320,6 +326,10 @@ Choose the right level of strictness for your use case:
|
|
320
326
|
2. **ALLOW** - Load metadata if present, don't worry about completeness
|
321
327
|
3. **STRICT** - Require complete metadata (title, description, version) for production safety
|
322
328
|
|
329
|
+
You can also set the environment variable `TEXTPROMPTS_METADATA_MODE` to one of
|
330
|
+
`strict`, `allow`, or `ignore` before importing the library to configure the
|
331
|
+
default mode.
|
332
|
+
|
323
333
|
```python
|
324
334
|
# Set globally
|
325
335
|
textprompts.set_metadata("ignore") # Default: simple file loading
|
@@ -1,5 +1,12 @@
|
|
1
1
|
# textprompts
|
2
2
|
|
3
|
+
[](https://pypi.org/project/textprompts/)
|
4
|
+
[](https://pypi.org/project/textprompts/)
|
5
|
+
[](https://github.com/svilupp/textprompts/actions)
|
6
|
+
[](https://codecov.io/gh/svilupp/textprompts)
|
7
|
+
[](https://github.com/svilupp/textprompts/blob/main/LICENSE)
|
8
|
+
|
9
|
+
|
3
10
|
> **So simple, it's not even worth vibing about coding yet it just makes so much sense.**
|
4
11
|
|
5
12
|
Are you tired of vendors trying to sell you fancy UIs for prompt management that just make your system more confusing and harder to debug? Isn't it nice to just have your prompts **next to your code**?
|
@@ -35,7 +42,6 @@ title = "Customer Greeting"
|
|
35
42
|
version = "1.0.0"
|
36
43
|
description = "Friendly greeting for customer support"
|
37
44
|
---
|
38
|
-
|
39
45
|
Hello {customer_name}!
|
40
46
|
|
41
47
|
Welcome to {company_name}. We're here to help you with {issue_type}.
|
@@ -50,6 +56,8 @@ import textprompts
|
|
50
56
|
|
51
57
|
# Just load it - works with or without metadata
|
52
58
|
prompt = textprompts.load_prompt("greeting.txt")
|
59
|
+
# Or simply
|
60
|
+
alt = textprompts.Prompt("greeting.txt")
|
53
61
|
|
54
62
|
# Use it safely - all placeholders must be provided
|
55
63
|
message = prompt.prompt.format(
|
@@ -196,7 +204,6 @@ title = "Product Search Tool"
|
|
196
204
|
version = "2.1.0"
|
197
205
|
description = "Search our product catalog"
|
198
206
|
---
|
199
|
-
|
200
207
|
{
|
201
208
|
"type": "function",
|
202
209
|
"function": {
|
@@ -282,7 +289,6 @@ description = "What this prompt does"
|
|
282
289
|
created = "2024-01-15"
|
283
290
|
tags = ["customer-support", "greeting"]
|
284
291
|
---
|
285
|
-
|
286
292
|
Your prompt content goes here.
|
287
293
|
|
288
294
|
Use {variables} for templating.
|
@@ -296,6 +302,10 @@ Choose the right level of strictness for your use case:
|
|
296
302
|
2. **ALLOW** - Load metadata if present, don't worry about completeness
|
297
303
|
3. **STRICT** - Require complete metadata (title, description, version) for production safety
|
298
304
|
|
305
|
+
You can also set the environment variable `TEXTPROMPTS_METADATA_MODE` to one of
|
306
|
+
`strict`, `allow`, or `ignore` before importing the library to configure the
|
307
|
+
default mode.
|
308
|
+
|
299
309
|
```python
|
300
310
|
# Set globally
|
301
311
|
textprompts.set_metadata("ignore") # Default: simple file loading
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[project]
|
2
2
|
name = "textprompts"
|
3
|
-
version = "0.0.
|
3
|
+
version = "0.0.3"
|
4
4
|
description = "Minimal text-based prompt-loader with TOML front-matter"
|
5
5
|
readme = "README.md"
|
6
6
|
license = "MIT"
|
@@ -38,6 +38,9 @@ dev = [
|
|
38
38
|
"ruff>=0.12.2",
|
39
39
|
"pre-commit>=3.0.0",
|
40
40
|
]
|
41
|
+
test = [
|
42
|
+
"pydantic-ai>=0.4.5",
|
43
|
+
]
|
41
44
|
|
42
45
|
[build-system]
|
43
46
|
requires = ["uv_build>=0.7.19,<0.8.0"]
|
@@ -71,8 +71,12 @@ def parse_file(path: Path, *, metadata_mode: MetadataMode) -> Prompt:
|
|
71
71
|
stacklevel=2,
|
72
72
|
)
|
73
73
|
ignore_meta = PromptMeta(title=path.stem)
|
74
|
-
return Prompt(
|
75
|
-
|
74
|
+
return Prompt.model_validate(
|
75
|
+
{
|
76
|
+
"path": path,
|
77
|
+
"meta": ignore_meta,
|
78
|
+
"prompt": PromptString(textwrap.dedent(raw)),
|
79
|
+
}
|
76
80
|
)
|
77
81
|
|
78
82
|
# For STRICT and ALLOW modes, try to parse front matter
|
@@ -149,4 +153,10 @@ def parse_file(path: Path, *, metadata_mode: MetadataMode) -> Prompt:
|
|
149
153
|
if meta.title is None:
|
150
154
|
meta.title = path.stem
|
151
155
|
|
152
|
-
return Prompt
|
156
|
+
return Prompt.model_validate(
|
157
|
+
{
|
158
|
+
"path": path,
|
159
|
+
"meta": meta,
|
160
|
+
"prompt": PromptString(textwrap.dedent(body)),
|
161
|
+
}
|
162
|
+
)
|
@@ -2,6 +2,7 @@
|
|
2
2
|
Global configuration for textprompts metadata handling.
|
3
3
|
"""
|
4
4
|
|
5
|
+
import os
|
5
6
|
from enum import Enum
|
6
7
|
from typing import Union
|
7
8
|
|
@@ -29,7 +30,13 @@ class MetadataMode(Enum):
|
|
29
30
|
|
30
31
|
|
31
32
|
# Global configuration variable
|
32
|
-
|
33
|
+
_env_mode = os.getenv("TEXTPROMPTS_METADATA_MODE")
|
34
|
+
try:
|
35
|
+
_METADATA_MODE: MetadataMode = (
|
36
|
+
MetadataMode(_env_mode.lower()) if _env_mode else MetadataMode.IGNORE
|
37
|
+
)
|
38
|
+
except ValueError:
|
39
|
+
_METADATA_MODE = MetadataMode.IGNORE
|
33
40
|
_WARN_ON_IGNORED_META: bool = True
|
34
41
|
|
35
42
|
|
@@ -4,6 +4,7 @@ from typing import Any, Union
|
|
4
4
|
|
5
5
|
from pydantic import BaseModel, Field, field_validator
|
6
6
|
|
7
|
+
from .config import MetadataMode
|
7
8
|
from .prompt_string import PromptString
|
8
9
|
|
9
10
|
|
@@ -20,6 +21,23 @@ class Prompt(BaseModel):
|
|
20
21
|
meta: Union[PromptMeta, None]
|
21
22
|
prompt: PromptString
|
22
23
|
|
24
|
+
def __init__(
|
25
|
+
self,
|
26
|
+
path: Union[str, Path],
|
27
|
+
meta: Union[PromptMeta, MetadataMode, str, None] = None,
|
28
|
+
prompt: Union[str, PromptString, None] = None,
|
29
|
+
) -> None:
|
30
|
+
"""Initialize Prompt from fields or load from file."""
|
31
|
+
if prompt is None:
|
32
|
+
from .loaders import load_prompt
|
33
|
+
|
34
|
+
loaded = load_prompt(path, meta=meta)
|
35
|
+
super().__init__(**loaded.model_dump())
|
36
|
+
else:
|
37
|
+
if isinstance(prompt, str):
|
38
|
+
prompt = PromptString(prompt)
|
39
|
+
super().__init__(path=Path(path), meta=meta, prompt=prompt)
|
40
|
+
|
23
41
|
@field_validator("prompt")
|
24
42
|
@classmethod
|
25
43
|
def prompt_not_empty(cls, v: str) -> PromptString:
|
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
|