open-prompt-format 0.2.0__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.
- open_prompt_format-0.2.0/LICENSE +21 -0
- open_prompt_format-0.2.0/PKG-INFO +107 -0
- open_prompt_format-0.2.0/README.md +62 -0
- open_prompt_format-0.2.0/pyproject.toml +35 -0
- open_prompt_format-0.2.0/setup.cfg +4 -0
- open_prompt_format-0.2.0/src/open_prompt_format.egg-info/PKG-INFO +107 -0
- open_prompt_format-0.2.0/src/open_prompt_format.egg-info/SOURCES.txt +39 -0
- open_prompt_format-0.2.0/src/open_prompt_format.egg-info/dependency_links.txt +1 -0
- open_prompt_format-0.2.0/src/open_prompt_format.egg-info/entry_points.txt +2 -0
- open_prompt_format-0.2.0/src/open_prompt_format.egg-info/requires.txt +4 -0
- open_prompt_format-0.2.0/src/open_prompt_format.egg-info/top_level.txt +1 -0
- open_prompt_format-0.2.0/src/opf/__init__.py +8 -0
- open_prompt_format-0.2.0/src/opf/adapters/__init__.py +10 -0
- open_prompt_format-0.2.0/src/opf/adapters/autogen.py +53 -0
- open_prompt_format-0.2.0/src/opf/adapters/base.py +98 -0
- open_prompt_format-0.2.0/src/opf/adapters/common.py +55 -0
- open_prompt_format-0.2.0/src/opf/adapters/crewai.py +67 -0
- open_prompt_format-0.2.0/src/opf/adapters/jinja.py +87 -0
- open_prompt_format-0.2.0/src/opf/adapters/langchain.py +77 -0
- open_prompt_format-0.2.0/src/opf/adapters/markdown.py +107 -0
- open_prompt_format-0.2.0/src/opf/adapters/openai.py +100 -0
- open_prompt_format-0.2.0/src/opf/check.py +101 -0
- open_prompt_format-0.2.0/src/opf/cli.py +268 -0
- open_prompt_format-0.2.0/src/opf/compatibility.py +40 -0
- open_prompt_format-0.2.0/src/opf/core.py +423 -0
- open_prompt_format-0.2.0/src/opf/diff.py +101 -0
- open_prompt_format-0.2.0/src/opf/discovery.py +166 -0
- open_prompt_format-0.2.0/src/opf/init.py +171 -0
- open_prompt_format-0.2.0/src/opf/migrate.py +151 -0
- open_prompt_format-0.2.0/src/opf/publish.py +165 -0
- open_prompt_format-0.2.0/src/opf/registry.py +503 -0
- open_prompt_format-0.2.0/src/opf/safety.py +46 -0
- open_prompt_format-0.2.0/tests/test_conformance.py +62 -0
- open_prompt_format-0.2.0/tests/test_eval_report.py +192 -0
- open_prompt_format-0.2.0/tests/test_feedback_forms.py +42 -0
- open_prompt_format-0.2.0/tests/test_init.py +79 -0
- open_prompt_format-0.2.0/tests/test_next_version.py +97 -0
- open_prompt_format-0.2.0/tests/test_promptfoo_config.py +34 -0
- open_prompt_format-0.2.0/tests/test_registry.py +193 -0
- open_prompt_format-0.2.0/tests/test_starter_template.py +42 -0
- open_prompt_format-0.2.0/tests/test_workflow.py +131 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Open Prompt Format contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: open-prompt-format
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Load and render Open Prompt Format files
|
|
5
|
+
License: MIT License
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2026 Open Prompt Format contributors
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
|
26
|
+
|
|
27
|
+
Project-URL: Repository, https://github.com/stovo-team/open-prompt-format
|
|
28
|
+
Keywords: prompt,llm,prompt-format,prompt-management
|
|
29
|
+
Classifier: Development Status :: 3 - Alpha
|
|
30
|
+
Classifier: Intended Audience :: Developers
|
|
31
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
32
|
+
Classifier: Programming Language :: Python :: 3
|
|
33
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
37
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
38
|
+
Requires-Python: >=3.10
|
|
39
|
+
Description-Content-Type: text/markdown
|
|
40
|
+
License-File: LICENSE
|
|
41
|
+
Requires-Dist: PyYAML>=6.0
|
|
42
|
+
Provides-Extra: jinja
|
|
43
|
+
Requires-Dist: Jinja2>=3.1; extra == "jinja"
|
|
44
|
+
Dynamic: license-file
|
|
45
|
+
|
|
46
|
+
# Open Prompt Format for Python
|
|
47
|
+
|
|
48
|
+
Load and render [OPF](../../README.md) prompt files from Python.
|
|
49
|
+
|
|
50
|
+
## Install
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
python -m pip install open-prompt-format
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
For the current source checkout, run `python -m pip install ./packages/python` from the repository root.
|
|
57
|
+
|
|
58
|
+
## Use
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from opf import load_by_id
|
|
62
|
+
|
|
63
|
+
prompt = load_by_id("support.reply", "prompts")
|
|
64
|
+
messages = prompt.render(customer_message="My order is late.")
|
|
65
|
+
print(prompt.source_digest)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`messages` is an ordered list of dictionaries with `role` and `content` strings. See the [syntax proposal](../../spec/SYNTAX.md) for file structure and validation rules.
|
|
69
|
+
|
|
70
|
+
## CLI
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
opf validate prompts/support.reply.md
|
|
74
|
+
opf validate-collection prompts
|
|
75
|
+
opf render prompts/support.reply.md --input customer_message="My order is late."
|
|
76
|
+
opf scan .
|
|
77
|
+
opf migrate inspect prompts/legacy.md --role system
|
|
78
|
+
opf migrate apply prompts/legacy.md --role system
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Migration inspection is read-only. Apply writes only generated paths that are absent or already identical. Supported adapter inputs are intentionally narrow; consult the [migration guide](../../examples/migration/README.md) for limits and compatibility findings.
|
|
82
|
+
|
|
83
|
+
Licensed under MIT; see [LICENSE](LICENSE).
|
|
84
|
+
|
|
85
|
+
## Git-backed registry
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from opf import Registry
|
|
89
|
+
|
|
90
|
+
registry = Registry.local("opf.yaml")
|
|
91
|
+
prepared = registry.get("support.reply", channel="production").render({"customer_message": "Hello"})
|
|
92
|
+
print(prepared.messages)
|
|
93
|
+
print(prepared.receipt)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The registry also supports `release`, `promote`, `verify`, `verify-all`, and `export` through the `opf` CLI. Run `opf verify-all --registry opf.yaml` in CI after fetching Git tags. `Registry.from_bundle("prompt.json")` loads an exported release without Git. Existing Markdown/Jinja projects can use the `jinja2` renderer with `pip install 'open-prompt-format[jinja]'`. The model is selected by the application and can be attached with `prepared.call_receipt(provider=..., model=...)`. See the [registry contract](../../spec/REGISTRY.md).
|
|
97
|
+
|
|
98
|
+
After `opf publish ID@VERSION --to langfuse`, `Registry.langfuse().get(ID, version=VERSION)` explicitly loads the verified remote bundle using Langfuse credentials from the environment.
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
## CLI onboarding and review
|
|
102
|
+
|
|
103
|
+
The Python distribution includes the `opf` CLI. `opf init . --id support.reply` creates a sample prompt, registry entry, and an OPF-owned guidance block in `AGENTS.md`. Add `--github` to also create a read-only GitHub Actions workflow that calls the published reusable OPF check workflow. It does not replace existing prompt files or content outside its markers; any conflicting target causes init to stop without partial writes. The generated workflow requires the matching OPF GitHub release and Python package to be published. `opf check .` validates discovered OPF prompts and registry references locally; `--format json` and `--strict` are available for CI.
|
|
104
|
+
|
|
105
|
+
Use `opf diff ID --base VERSION_OR_CHANNEL --target VERSION_OR_WORKING_TREE` to inspect source changes and shared prefix evidence. A stable prefix is only a cacheability candidate; it cannot establish a provider cache hit. Heuristic injection findings need human review and do not guarantee safety.
|
|
106
|
+
|
|
107
|
+
The reusable GitHub workflow has an optional paired Promptfoo job (`run-eval`, default false). It requires a protected `prompt-eval` environment with required reviewers and environment-scoped provider keys. It runs the same eval config against the PR base prompt and candidate prompt, writes a sanitized comparison to the workflow summary, skips forks, and deletes raw files. Each comparison makes two sets of provider calls and can cost money. `block-on-regression` also defaults false; ungraded rows are never counted as passes. Report states are `unchanged`, `regression`, `improved`, `changed`, `error`, and `ungraded`; provider/test/prompt matrix mismatches or missing base files abort comparison. Nondeterminism means a measured regression needs review, and a source diff by itself does not establish behavior quality. The included sample cases validate config wiring only; live model behavior is not verified by ordinary CI.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Open Prompt Format for Python
|
|
2
|
+
|
|
3
|
+
Load and render [OPF](../../README.md) prompt files from Python.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
python -m pip install open-prompt-format
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
For the current source checkout, run `python -m pip install ./packages/python` from the repository root.
|
|
12
|
+
|
|
13
|
+
## Use
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
from opf import load_by_id
|
|
17
|
+
|
|
18
|
+
prompt = load_by_id("support.reply", "prompts")
|
|
19
|
+
messages = prompt.render(customer_message="My order is late.")
|
|
20
|
+
print(prompt.source_digest)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`messages` is an ordered list of dictionaries with `role` and `content` strings. See the [syntax proposal](../../spec/SYNTAX.md) for file structure and validation rules.
|
|
24
|
+
|
|
25
|
+
## CLI
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
opf validate prompts/support.reply.md
|
|
29
|
+
opf validate-collection prompts
|
|
30
|
+
opf render prompts/support.reply.md --input customer_message="My order is late."
|
|
31
|
+
opf scan .
|
|
32
|
+
opf migrate inspect prompts/legacy.md --role system
|
|
33
|
+
opf migrate apply prompts/legacy.md --role system
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Migration inspection is read-only. Apply writes only generated paths that are absent or already identical. Supported adapter inputs are intentionally narrow; consult the [migration guide](../../examples/migration/README.md) for limits and compatibility findings.
|
|
37
|
+
|
|
38
|
+
Licensed under MIT; see [LICENSE](LICENSE).
|
|
39
|
+
|
|
40
|
+
## Git-backed registry
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from opf import Registry
|
|
44
|
+
|
|
45
|
+
registry = Registry.local("opf.yaml")
|
|
46
|
+
prepared = registry.get("support.reply", channel="production").render({"customer_message": "Hello"})
|
|
47
|
+
print(prepared.messages)
|
|
48
|
+
print(prepared.receipt)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The registry also supports `release`, `promote`, `verify`, `verify-all`, and `export` through the `opf` CLI. Run `opf verify-all --registry opf.yaml` in CI after fetching Git tags. `Registry.from_bundle("prompt.json")` loads an exported release without Git. Existing Markdown/Jinja projects can use the `jinja2` renderer with `pip install 'open-prompt-format[jinja]'`. The model is selected by the application and can be attached with `prepared.call_receipt(provider=..., model=...)`. See the [registry contract](../../spec/REGISTRY.md).
|
|
52
|
+
|
|
53
|
+
After `opf publish ID@VERSION --to langfuse`, `Registry.langfuse().get(ID, version=VERSION)` explicitly loads the verified remote bundle using Langfuse credentials from the environment.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
## CLI onboarding and review
|
|
57
|
+
|
|
58
|
+
The Python distribution includes the `opf` CLI. `opf init . --id support.reply` creates a sample prompt, registry entry, and an OPF-owned guidance block in `AGENTS.md`. Add `--github` to also create a read-only GitHub Actions workflow that calls the published reusable OPF check workflow. It does not replace existing prompt files or content outside its markers; any conflicting target causes init to stop without partial writes. The generated workflow requires the matching OPF GitHub release and Python package to be published. `opf check .` validates discovered OPF prompts and registry references locally; `--format json` and `--strict` are available for CI.
|
|
59
|
+
|
|
60
|
+
Use `opf diff ID --base VERSION_OR_CHANNEL --target VERSION_OR_WORKING_TREE` to inspect source changes and shared prefix evidence. A stable prefix is only a cacheability candidate; it cannot establish a provider cache hit. Heuristic injection findings need human review and do not guarantee safety.
|
|
61
|
+
|
|
62
|
+
The reusable GitHub workflow has an optional paired Promptfoo job (`run-eval`, default false). It requires a protected `prompt-eval` environment with required reviewers and environment-scoped provider keys. It runs the same eval config against the PR base prompt and candidate prompt, writes a sanitized comparison to the workflow summary, skips forks, and deletes raw files. Each comparison makes two sets of provider calls and can cost money. `block-on-regression` also defaults false; ungraded rows are never counted as passes. Report states are `unchanged`, `regression`, `improved`, `changed`, `error`, and `ungraded`; provider/test/prompt matrix mismatches or missing base files abort comparison. Nondeterminism means a measured regression needs review, and a source diff by itself does not establish behavior quality. The included sample cases validate config wiring only; live model behavior is not verified by ordinary CI.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "open-prompt-format"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Load and render Open Prompt Format files"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { file = "LICENSE" }
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
dependencies = ["PyYAML>=6.0"]
|
|
13
|
+
|
|
14
|
+
keywords = ["prompt", "llm", "prompt-format", "prompt-management"]
|
|
15
|
+
urls = { Repository = "https://github.com/stovo-team/open-prompt-format" }
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.optional-dependencies]
|
|
29
|
+
jinja = ["Jinja2>=3.1"]
|
|
30
|
+
|
|
31
|
+
[project.scripts]
|
|
32
|
+
opf = "opf.cli:main"
|
|
33
|
+
|
|
34
|
+
[tool.setuptools.packages.find]
|
|
35
|
+
where = ["src"]
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: open-prompt-format
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Load and render Open Prompt Format files
|
|
5
|
+
License: MIT License
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2026 Open Prompt Format contributors
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
|
26
|
+
|
|
27
|
+
Project-URL: Repository, https://github.com/stovo-team/open-prompt-format
|
|
28
|
+
Keywords: prompt,llm,prompt-format,prompt-management
|
|
29
|
+
Classifier: Development Status :: 3 - Alpha
|
|
30
|
+
Classifier: Intended Audience :: Developers
|
|
31
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
32
|
+
Classifier: Programming Language :: Python :: 3
|
|
33
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
37
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
38
|
+
Requires-Python: >=3.10
|
|
39
|
+
Description-Content-Type: text/markdown
|
|
40
|
+
License-File: LICENSE
|
|
41
|
+
Requires-Dist: PyYAML>=6.0
|
|
42
|
+
Provides-Extra: jinja
|
|
43
|
+
Requires-Dist: Jinja2>=3.1; extra == "jinja"
|
|
44
|
+
Dynamic: license-file
|
|
45
|
+
|
|
46
|
+
# Open Prompt Format for Python
|
|
47
|
+
|
|
48
|
+
Load and render [OPF](../../README.md) prompt files from Python.
|
|
49
|
+
|
|
50
|
+
## Install
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
python -m pip install open-prompt-format
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
For the current source checkout, run `python -m pip install ./packages/python` from the repository root.
|
|
57
|
+
|
|
58
|
+
## Use
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from opf import load_by_id
|
|
62
|
+
|
|
63
|
+
prompt = load_by_id("support.reply", "prompts")
|
|
64
|
+
messages = prompt.render(customer_message="My order is late.")
|
|
65
|
+
print(prompt.source_digest)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
`messages` is an ordered list of dictionaries with `role` and `content` strings. See the [syntax proposal](../../spec/SYNTAX.md) for file structure and validation rules.
|
|
69
|
+
|
|
70
|
+
## CLI
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
opf validate prompts/support.reply.md
|
|
74
|
+
opf validate-collection prompts
|
|
75
|
+
opf render prompts/support.reply.md --input customer_message="My order is late."
|
|
76
|
+
opf scan .
|
|
77
|
+
opf migrate inspect prompts/legacy.md --role system
|
|
78
|
+
opf migrate apply prompts/legacy.md --role system
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Migration inspection is read-only. Apply writes only generated paths that are absent or already identical. Supported adapter inputs are intentionally narrow; consult the [migration guide](../../examples/migration/README.md) for limits and compatibility findings.
|
|
82
|
+
|
|
83
|
+
Licensed under MIT; see [LICENSE](LICENSE).
|
|
84
|
+
|
|
85
|
+
## Git-backed registry
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from opf import Registry
|
|
89
|
+
|
|
90
|
+
registry = Registry.local("opf.yaml")
|
|
91
|
+
prepared = registry.get("support.reply", channel="production").render({"customer_message": "Hello"})
|
|
92
|
+
print(prepared.messages)
|
|
93
|
+
print(prepared.receipt)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The registry also supports `release`, `promote`, `verify`, `verify-all`, and `export` through the `opf` CLI. Run `opf verify-all --registry opf.yaml` in CI after fetching Git tags. `Registry.from_bundle("prompt.json")` loads an exported release without Git. Existing Markdown/Jinja projects can use the `jinja2` renderer with `pip install 'open-prompt-format[jinja]'`. The model is selected by the application and can be attached with `prepared.call_receipt(provider=..., model=...)`. See the [registry contract](../../spec/REGISTRY.md).
|
|
97
|
+
|
|
98
|
+
After `opf publish ID@VERSION --to langfuse`, `Registry.langfuse().get(ID, version=VERSION)` explicitly loads the verified remote bundle using Langfuse credentials from the environment.
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
## CLI onboarding and review
|
|
102
|
+
|
|
103
|
+
The Python distribution includes the `opf` CLI. `opf init . --id support.reply` creates a sample prompt, registry entry, and an OPF-owned guidance block in `AGENTS.md`. Add `--github` to also create a read-only GitHub Actions workflow that calls the published reusable OPF check workflow. It does not replace existing prompt files or content outside its markers; any conflicting target causes init to stop without partial writes. The generated workflow requires the matching OPF GitHub release and Python package to be published. `opf check .` validates discovered OPF prompts and registry references locally; `--format json` and `--strict` are available for CI.
|
|
104
|
+
|
|
105
|
+
Use `opf diff ID --base VERSION_OR_CHANNEL --target VERSION_OR_WORKING_TREE` to inspect source changes and shared prefix evidence. A stable prefix is only a cacheability candidate; it cannot establish a provider cache hit. Heuristic injection findings need human review and do not guarantee safety.
|
|
106
|
+
|
|
107
|
+
The reusable GitHub workflow has an optional paired Promptfoo job (`run-eval`, default false). It requires a protected `prompt-eval` environment with required reviewers and environment-scoped provider keys. It runs the same eval config against the PR base prompt and candidate prompt, writes a sanitized comparison to the workflow summary, skips forks, and deletes raw files. Each comparison makes two sets of provider calls and can cost money. `block-on-regression` also defaults false; ungraded rows are never counted as passes. Report states are `unchanged`, `regression`, `improved`, `changed`, `error`, and `ungraded`; provider/test/prompt matrix mismatches or missing base files abort comparison. Nondeterminism means a measured regression needs review, and a source diff by itself does not establish behavior quality. The included sample cases validate config wiring only; live model behavior is not verified by ordinary CI.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/open_prompt_format.egg-info/PKG-INFO
|
|
5
|
+
src/open_prompt_format.egg-info/SOURCES.txt
|
|
6
|
+
src/open_prompt_format.egg-info/dependency_links.txt
|
|
7
|
+
src/open_prompt_format.egg-info/entry_points.txt
|
|
8
|
+
src/open_prompt_format.egg-info/requires.txt
|
|
9
|
+
src/open_prompt_format.egg-info/top_level.txt
|
|
10
|
+
src/opf/__init__.py
|
|
11
|
+
src/opf/check.py
|
|
12
|
+
src/opf/cli.py
|
|
13
|
+
src/opf/compatibility.py
|
|
14
|
+
src/opf/core.py
|
|
15
|
+
src/opf/diff.py
|
|
16
|
+
src/opf/discovery.py
|
|
17
|
+
src/opf/init.py
|
|
18
|
+
src/opf/migrate.py
|
|
19
|
+
src/opf/publish.py
|
|
20
|
+
src/opf/registry.py
|
|
21
|
+
src/opf/safety.py
|
|
22
|
+
src/opf/adapters/__init__.py
|
|
23
|
+
src/opf/adapters/autogen.py
|
|
24
|
+
src/opf/adapters/base.py
|
|
25
|
+
src/opf/adapters/common.py
|
|
26
|
+
src/opf/adapters/crewai.py
|
|
27
|
+
src/opf/adapters/jinja.py
|
|
28
|
+
src/opf/adapters/langchain.py
|
|
29
|
+
src/opf/adapters/markdown.py
|
|
30
|
+
src/opf/adapters/openai.py
|
|
31
|
+
tests/test_conformance.py
|
|
32
|
+
tests/test_eval_report.py
|
|
33
|
+
tests/test_feedback_forms.py
|
|
34
|
+
tests/test_init.py
|
|
35
|
+
tests/test_next_version.py
|
|
36
|
+
tests/test_promptfoo_config.py
|
|
37
|
+
tests/test_registry.py
|
|
38
|
+
tests/test_starter_template.py
|
|
39
|
+
tests/test_workflow.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
opf
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""Minimal reader and renderer for OPF 0.1 prompt files."""
|
|
2
|
+
|
|
3
|
+
from .core import OPFError, Prompt, load, load_by_id, load_collection, parse
|
|
4
|
+
from .compatibility import CompatibilityFinding, CompatibilityReport
|
|
5
|
+
from .discovery import PromptFinding, scan
|
|
6
|
+
from .registry import PreparedPrompt, RegisteredPrompt, Registry
|
|
7
|
+
|
|
8
|
+
__all__ = ["OPFError", "Prompt", "PreparedPrompt", "RegisteredPrompt", "Registry", "CompatibilityFinding", "CompatibilityReport", "PromptFinding", "load", "load_by_id", "load_collection", "parse", "scan"]
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""Optional source import adapters. Framework packages are not imported here."""
|
|
2
|
+
|
|
3
|
+
from .autogen import AutoGenAdapter
|
|
4
|
+
from .crewai import CrewAIAdapter
|
|
5
|
+
from .jinja import JinjaAdapter
|
|
6
|
+
from .langchain import LangChainAdapter
|
|
7
|
+
from .markdown import MarkdownAdapter
|
|
8
|
+
from .openai import OpenAIPromptAdapter
|
|
9
|
+
|
|
10
|
+
__all__ = ["AutoGenAdapter", "CrewAIAdapter", "JinjaAdapter", "LangChainAdapter", "MarkdownAdapter", "OpenAIPromptAdapter"]
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""Extract only literal system_message values from AutoGen Python source."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import ast
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from ..compatibility import CompatibilityFinding
|
|
9
|
+
from ..core import OPFError
|
|
10
|
+
from .base import SourcePrompt, read_source
|
|
11
|
+
from .common import plan_messages
|
|
12
|
+
from .markdown import ID_RE
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class AutoGenAdapter:
|
|
16
|
+
source_kind = "autogen-python"
|
|
17
|
+
converter = "opf-migrate-autogen"
|
|
18
|
+
|
|
19
|
+
def inspect(self, path: str | Path, *, root: str | Path = ".") -> SourcePrompt:
|
|
20
|
+
source = read_source(path, root, self.source_kind)
|
|
21
|
+
try:
|
|
22
|
+
ast.parse(source.text, filename=source.relative_path)
|
|
23
|
+
except SyntaxError as exc:
|
|
24
|
+
raise OPFError("AutoGen source is not valid Python: {}".format(exc)) from exc
|
|
25
|
+
return SourcePrompt(source.path, source.relative_path, source.source_kind, source.text, source.source_digest, "python-ast-static/1")
|
|
26
|
+
|
|
27
|
+
def plan(self, source: SourcePrompt, prompt_id: str, *, role: str | None = None):
|
|
28
|
+
if not ID_RE.fullmatch(prompt_id):
|
|
29
|
+
raise OPFError("invalid prompt id")
|
|
30
|
+
tree = ast.parse(source.text)
|
|
31
|
+
candidates: list[str] = []
|
|
32
|
+
for node in ast.walk(tree):
|
|
33
|
+
if not isinstance(node, ast.Call):
|
|
34
|
+
continue
|
|
35
|
+
for keyword in node.keywords:
|
|
36
|
+
if keyword.arg != "system_message":
|
|
37
|
+
continue
|
|
38
|
+
try:
|
|
39
|
+
value = ast.literal_eval(keyword.value)
|
|
40
|
+
except (ValueError, TypeError):
|
|
41
|
+
raise OPFError("dynamic AutoGen system_message requires manual migration")
|
|
42
|
+
if not isinstance(value, str):
|
|
43
|
+
raise OPFError("AutoGen system_message must be a string literal")
|
|
44
|
+
candidates.append(value)
|
|
45
|
+
if len(candidates) != 1:
|
|
46
|
+
raise OPFError("expected exactly one explicit system_message; found {}".format(len(candidates)))
|
|
47
|
+
findings = [CompatibilityFinding("autogen.runtime.excluded", "warning", "dropped", "AutoGen tools, agent runtime, and control flow are not part of this migration")]
|
|
48
|
+
return plan_messages(source, prompt_id, [{"role": "system", "content": candidates[0]}], converter=self.converter, source_format_version=source.source_format_version, findings=findings)
|
|
49
|
+
|
|
50
|
+
def convert(self, source: SourcePrompt, plan):
|
|
51
|
+
if source.source_digest != plan.source.source_digest:
|
|
52
|
+
raise OPFError("source changed after migration plan was created")
|
|
53
|
+
return plan.output
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""Common types and interfaces for prompt import adapters."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
from abc import ABC, abstractmethod
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any, Mapping, Optional
|
|
10
|
+
|
|
11
|
+
from ..compatibility import CompatibilityReport
|
|
12
|
+
from ..core import OPFError
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def normalized_digest(source: str) -> str:
|
|
16
|
+
normalized = source.replace("\r\n", "\n").replace("\r", "\n")
|
|
17
|
+
return "sha256:" + hashlib.sha256(normalized.encode("utf-8")).hexdigest()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True)
|
|
21
|
+
class SourcePrompt:
|
|
22
|
+
path: Path
|
|
23
|
+
relative_path: str
|
|
24
|
+
source_kind: str
|
|
25
|
+
text: str
|
|
26
|
+
source_digest: str
|
|
27
|
+
source_format_version: Optional[str] = None
|
|
28
|
+
data: Mapping[str, Any] | None = None
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass(frozen=True)
|
|
32
|
+
class MigrationOutput:
|
|
33
|
+
files: Mapping[str, str]
|
|
34
|
+
registry_entry: Mapping[str, Any] | None
|
|
35
|
+
manifest_record: Mapping[str, Any]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclass(frozen=True)
|
|
39
|
+
class MigrationPlan:
|
|
40
|
+
prompt_id: str
|
|
41
|
+
source: SourcePrompt
|
|
42
|
+
output: MigrationOutput
|
|
43
|
+
compatibility: CompatibilityReport
|
|
44
|
+
converter: str
|
|
45
|
+
converter_version: str = "0.3.0"
|
|
46
|
+
|
|
47
|
+
def to_dict(self) -> dict[str, Any]:
|
|
48
|
+
return {
|
|
49
|
+
"prompt_id": self.prompt_id,
|
|
50
|
+
"source": {
|
|
51
|
+
"path": self.source.relative_path,
|
|
52
|
+
"kind": self.source.source_kind,
|
|
53
|
+
"format_version": self.source.source_format_version,
|
|
54
|
+
"digest": self.source.source_digest,
|
|
55
|
+
},
|
|
56
|
+
"generated_files": dict(self.output.files),
|
|
57
|
+
"registry_entry": dict(self.output.registry_entry) if self.output.registry_entry is not None else None,
|
|
58
|
+
"manifest_record": dict(self.output.manifest_record),
|
|
59
|
+
"compatibility": self.compatibility.to_dict(),
|
|
60
|
+
"converter": self.converter,
|
|
61
|
+
"converter_version": self.converter_version,
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class SourceAdapter(ABC):
|
|
66
|
+
source_kind = "unknown"
|
|
67
|
+
converter = "opf-migrate-unknown"
|
|
68
|
+
|
|
69
|
+
@abstractmethod
|
|
70
|
+
def inspect(self, path: str | Path, *, root: str | Path = ".") -> SourcePrompt:
|
|
71
|
+
"""Read a source prompt without modifying it."""
|
|
72
|
+
|
|
73
|
+
@abstractmethod
|
|
74
|
+
def plan(self, source: SourcePrompt, prompt_id: str, *, role: str | None = None) -> MigrationPlan:
|
|
75
|
+
"""Build a deterministic migration plan without filesystem writes."""
|
|
76
|
+
|
|
77
|
+
@abstractmethod
|
|
78
|
+
def convert(self, source: SourcePrompt, plan: MigrationPlan) -> MigrationOutput:
|
|
79
|
+
"""Return generated files and metadata for the previously inspected source."""
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def read_source(path: str | Path, root: str | Path, source_kind: str) -> SourcePrompt:
|
|
83
|
+
base = Path(root).resolve()
|
|
84
|
+
source_path = Path(path)
|
|
85
|
+
if not source_path.is_absolute():
|
|
86
|
+
source_path = base / source_path
|
|
87
|
+
try:
|
|
88
|
+
resolved = source_path.resolve(strict=True)
|
|
89
|
+
relative_path = resolved.relative_to(base).as_posix()
|
|
90
|
+
except (OSError, ValueError) as exc:
|
|
91
|
+
raise OPFError("source prompt must exist inside the migration root: {}".format(path)) from exc
|
|
92
|
+
if source_path.is_symlink() or not resolved.is_file():
|
|
93
|
+
raise OPFError("source prompt must be a regular file: {}".format(path))
|
|
94
|
+
try:
|
|
95
|
+
text = resolved.read_text(encoding="utf-8")
|
|
96
|
+
except (OSError, UnicodeError) as exc:
|
|
97
|
+
raise OPFError("cannot read source prompt {}: {}".format(relative_path, exc)) from exc
|
|
98
|
+
return SourcePrompt(resolved, relative_path, source_kind, text, normalized_digest(text))
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Shared conversion helpers for source formats with static messages."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from datetime import datetime, timezone
|
|
6
|
+
from typing import Any, Iterable
|
|
7
|
+
|
|
8
|
+
import yaml
|
|
9
|
+
|
|
10
|
+
from ..compatibility import CompatibilityFinding, CompatibilityReport
|
|
11
|
+
from ..core import OPFError, VARIABLE_RE, parse
|
|
12
|
+
from .base import MigrationOutput, MigrationPlan, SourcePrompt
|
|
13
|
+
from .markdown import ID_RE
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def plan_messages(
|
|
17
|
+
source: SourcePrompt,
|
|
18
|
+
prompt_id: str,
|
|
19
|
+
messages: list[dict[str, str]],
|
|
20
|
+
*,
|
|
21
|
+
converter: str,
|
|
22
|
+
source_format_version: str | None = None,
|
|
23
|
+
inputs: Iterable[str] = (),
|
|
24
|
+
extensions: dict[str, Any] | None = None,
|
|
25
|
+
findings: Iterable[CompatibilityFinding] = (),
|
|
26
|
+
) -> MigrationPlan:
|
|
27
|
+
if not ID_RE.fullmatch(prompt_id):
|
|
28
|
+
raise OPFError("prompt id must match [a-z0-9]+(?:[._-][a-z0-9]+)*")
|
|
29
|
+
if not messages or any(not isinstance(item, dict) or set(item) != {"role", "content"} or not isinstance(item["role"], str) or item["role"] not in {"system", "developer", "user", "assistant"} or not isinstance(item["content"], str) for item in messages):
|
|
30
|
+
raise OPFError("source must provide ordered text messages with supported roles")
|
|
31
|
+
declared = set(inputs)
|
|
32
|
+
for item in messages:
|
|
33
|
+
declared.update(VARIABLE_RE.findall(item["content"]))
|
|
34
|
+
metadata: dict[str, Any] = {"format": "opf/0.3", "id": prompt_id}
|
|
35
|
+
if declared:
|
|
36
|
+
metadata["inputs"] = {name: {"type": "string", "required": True} for name in sorted(declared)}
|
|
37
|
+
if extensions:
|
|
38
|
+
metadata["extensions"] = extensions
|
|
39
|
+
body = "\n\n".join("## {}\n{}".format(item["role"], item["content"]) for item in messages)
|
|
40
|
+
content = "---\n{}\n---\n\n{}".format(yaml.safe_dump(metadata, allow_unicode=True, sort_keys=False).rstrip(), body)
|
|
41
|
+
parse(content)
|
|
42
|
+
output_path = "prompts/{}.opf.md".format(prompt_id)
|
|
43
|
+
all_findings = tuple(findings) + (CompatibilityFinding("messages.preserved", "info", "preserved", "Ordered text messages were mapped to OPF core"),)
|
|
44
|
+
report = CompatibilityReport(source.source_kind, "opf/0.3", all_findings, all(item.disposition == "preserved" for item in all_findings), not any(item.severity == "error" for item in all_findings))
|
|
45
|
+
record = {
|
|
46
|
+
"source_path": source.relative_path,
|
|
47
|
+
"source_kind": source.source_kind,
|
|
48
|
+
**({"source_format_version": source_format_version or source.source_format_version} if (source_format_version or source.source_format_version) else {}),
|
|
49
|
+
"source_digest": source.source_digest,
|
|
50
|
+
"converter": converter,
|
|
51
|
+
"converter_version": "0.3.0",
|
|
52
|
+
"migrated_at": datetime.now(timezone.utc).isoformat().replace("+00:00", "Z"),
|
|
53
|
+
"findings": [{"code": item.code, "severity": item.severity, "disposition": item.disposition, "message": item.message, **({"path": item.source_path} if item.source_path else {})} for item in all_findings],
|
|
54
|
+
}
|
|
55
|
+
return MigrationPlan(prompt_id, source, MigrationOutput({output_path: content}, {"renderer": "opf", "source": output_path}, record), report, converter)
|