pixie-prompts 0.1.7__py3-none-any.whl → 0.1.8.dev6__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.
- pixie/prompts/graphql.py +12 -1
- pixie_prompts-0.1.8.dev6.dist-info/METADATA +138 -0
- {pixie_prompts-0.1.7.dist-info → pixie_prompts-0.1.8.dev6.dist-info}/RECORD +6 -6
- pixie_prompts-0.1.7.dist-info/METADATA +0 -40
- {pixie_prompts-0.1.7.dist-info → pixie_prompts-0.1.8.dev6.dist-info}/WHEEL +0 -0
- {pixie_prompts-0.1.7.dist-info → pixie_prompts-0.1.8.dev6.dist-info}/entry_points.txt +0 -0
- {pixie_prompts-0.1.7.dist-info → pixie_prompts-0.1.8.dev6.dist-info}/licenses/LICENSE +0 -0
pixie/prompts/graphql.py
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
from datetime import datetime
|
|
4
4
|
import json
|
|
5
5
|
import logging
|
|
6
|
+
import os
|
|
6
7
|
from typing import Any, Optional, cast, get_args
|
|
7
8
|
|
|
8
9
|
from graphql import GraphQLError
|
|
@@ -94,6 +95,11 @@ class LlmCallResult:
|
|
|
94
95
|
reasoning: str | None
|
|
95
96
|
|
|
96
97
|
|
|
98
|
+
def is_demo_mode() -> bool:
|
|
99
|
+
is_demo_mode = os.getenv("IS_DEMO_MODE", "0") in ("1", "true", "True")
|
|
100
|
+
return is_demo_mode
|
|
101
|
+
|
|
102
|
+
|
|
97
103
|
@strawberry.type
|
|
98
104
|
class Query:
|
|
99
105
|
"""GraphQL queries."""
|
|
@@ -219,6 +225,8 @@ class Mutation:
|
|
|
219
225
|
GraphQLError: If the LLM call fails.
|
|
220
226
|
"""
|
|
221
227
|
try:
|
|
228
|
+
if is_demo_mode():
|
|
229
|
+
model = "openai:gpt-4o-mini"
|
|
222
230
|
template = jinja2.Template(prompt_template)
|
|
223
231
|
prompt = template.render(**(cast(dict[str, Any], variables) or {}))
|
|
224
232
|
print(prompt)
|
|
@@ -243,7 +251,6 @@ class Mutation:
|
|
|
243
251
|
elif part.part_kind == "system-prompt":
|
|
244
252
|
part.content = part.content.replace(prompt_placeholder, prompt)
|
|
245
253
|
|
|
246
|
-
print(pydantic_messages)
|
|
247
254
|
# Replace the placeholder in input messages
|
|
248
255
|
response = await model_request(
|
|
249
256
|
model=model,
|
|
@@ -309,6 +316,8 @@ class Mutation:
|
|
|
309
316
|
Returns:
|
|
310
317
|
The updated BasePrompt object.
|
|
311
318
|
"""
|
|
319
|
+
if is_demo_mode():
|
|
320
|
+
raise GraphQLError("Modifications are not allowed in demo mode.")
|
|
312
321
|
prompt_with_registration = get_prompt((str(prompt_id)))
|
|
313
322
|
if prompt_with_registration is None:
|
|
314
323
|
raise GraphQLError(f"Prompt with id '{prompt_id}' not found.")
|
|
@@ -338,6 +347,8 @@ class Mutation:
|
|
|
338
347
|
Returns:
|
|
339
348
|
True if the update was successful.
|
|
340
349
|
"""
|
|
350
|
+
if is_demo_mode():
|
|
351
|
+
raise GraphQLError("Modifications are not allowed in demo mode.")
|
|
341
352
|
prompt_with_registration = get_prompt((str(prompt_id)))
|
|
342
353
|
if prompt_with_registration is None:
|
|
343
354
|
raise GraphQLError(f"Prompt with id '{prompt_id}' not found.")
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pixie-prompts
|
|
3
|
+
Version: 0.1.8.dev6
|
|
4
|
+
Summary: Code-first, type-safe prompt management
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Author: Yiou Li
|
|
8
|
+
Author-email: yol@gopixie.ai
|
|
9
|
+
Requires-Python: >=3.10,<4.0
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Provides-Extra: server
|
|
18
|
+
Requires-Dist: brotli (>=1.2.0,<2.0.0) ; extra == "server"
|
|
19
|
+
Requires-Dist: colorlog (>=6.10.1) ; extra == "server"
|
|
20
|
+
Requires-Dist: dotenv (>=0.9.9) ; extra == "server"
|
|
21
|
+
Requires-Dist: fastapi (>=0.128.0) ; extra == "server"
|
|
22
|
+
Requires-Dist: jinja2 (>=3.1.6,<4.0.0)
|
|
23
|
+
Requires-Dist: jsonsubschema (>=0.0.7,<0.0.8)
|
|
24
|
+
Requires-Dist: openai[server] (>=2.15.0,<3.0.0) ; extra == "server"
|
|
25
|
+
Requires-Dist: pydantic (>=2.12.5,<3.0.0)
|
|
26
|
+
Requires-Dist: pydantic-ai-slim (>=1.39.0) ; extra == "server"
|
|
27
|
+
Requires-Dist: strawberry-graphql (>=0.288.1) ; extra == "server"
|
|
28
|
+
Requires-Dist: uvicorn (>=0.40.0) ; extra == "server"
|
|
29
|
+
Requires-Dist: watchdog (>=6.0.0) ; extra == "server"
|
|
30
|
+
Requires-Dist: watchfiles[server] (>=1.1.1,<2.0.0) ; extra == "server"
|
|
31
|
+
Project-URL: Changelog, https://github.com/yiouli/pixie-prompts/commits/main/
|
|
32
|
+
Project-URL: Documentation, https://yiouli.github.io/pixie-prompts/
|
|
33
|
+
Project-URL: Homepage, https://gopixie.ai
|
|
34
|
+
Project-URL: Issues, https://github.com/yiouli/pixie-prompts/issues
|
|
35
|
+
Project-URL: Repository, https://github.com/yiouli/pixie-prompts
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# pixie-prompts
|
|
39
|
+
**Code-first, type-checked prompt management.**
|
|
40
|
+
Manage prompt locally in your codebase, with Jinja rendering, variable type-hint and validations.
|
|
41
|
+
|
|
42
|
+
[**Demo**](https://github.com/user-attachments/assets/aba55aca-1ad3-4f25-97f9-db0f8e67dbe6)
|
|
43
|
+
|
|
44
|
+
[**Try it live**](https://gopixie.ai/?url=https%3A%2F%2Fpixie-prompts-examples.vercel.app%2Fgraphql)
|
|
45
|
+
|
|
46
|
+
## Setup
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
In your project folder, install **pixie-prompts[server]** Python package:
|
|
52
|
+
```bash
|
|
53
|
+
pip install pixie-prompts[server]
|
|
54
|
+
```
|
|
55
|
+
> Note: you can install **pixie-prompts** without the server extras for your production build.
|
|
56
|
+
|
|
57
|
+
Start the local dev server and open the web UI by running:
|
|
58
|
+
```bash
|
|
59
|
+
pp
|
|
60
|
+
```
|
|
61
|
+
> Note: The web-browser would automatically open [http://localhost:8000](http://localhost:8000). You can also access the web UI at [gopixie.ai](https://gopixie.ai).
|
|
62
|
+
|
|
63
|
+
To test prompts, create *.env* file with LLM API key(s):
|
|
64
|
+
```ini
|
|
65
|
+
# .env
|
|
66
|
+
OPENAI_API_KEY=...
|
|
67
|
+
GEMINI_API_KEY=...
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Register Prompt
|
|
71
|
+
|
|
72
|
+
In your code, create a new prompt using `create_prompt`:
|
|
73
|
+
```python
|
|
74
|
+
# prompts.py
|
|
75
|
+
from pixie.prompts import create_prompt
|
|
76
|
+
|
|
77
|
+
simple_prompt = create_prompt('simple_prompt')
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Your prompt would automatically appear in the web UI after your code is saved.
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
## Manage Prompt
|
|
84
|
+
|
|
85
|
+
You can create new version(s) of a prompt in the web UI.
|
|
86
|
+
|
|
87
|
+
Once saved from web UI, it will be assigned a new version id, and the content would be saved in your codebase at */.pixie/prompts/<prompt_name>/<version_id>.jinja*.
|
|
88
|
+
|
|
89
|
+
> Note: it's recommended to only edit your prompts via the web UI to get type-hint and validation.
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
## Define Variables
|
|
93
|
+
|
|
94
|
+
For prompt that has variable(s) in it, define a class extending `pixie.prompts.Variables` (which extends `pydantic.BaseModel`. Then use the class type when registering your prompt.
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
# prompts.py
|
|
98
|
+
from pixie.prompts import Variables, create_prompt
|
|
99
|
+
|
|
100
|
+
class Person(Variables):
|
|
101
|
+
name: str
|
|
102
|
+
age: int
|
|
103
|
+
|
|
104
|
+
# Create a prompt with variables
|
|
105
|
+
typed_prompt = create_prompt('typed_prompt', Person)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Other than using dict, you can define your variable class in anyway that's permissible in Pydantic. I.e. you can define your field as basic types such as `str`, `int`, `bool`, you can have a `list` of permissible items, you can use `Union` type, and you can have nested `Variable` field.
|
|
109
|
+
|
|
110
|
+
The web UI will parse your variable definitions and use it to decide input fields, type-hints and validations.
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
## Use Prompt
|
|
114
|
+
|
|
115
|
+
Compile your prompt into string with the `compile` function on the prompt object. Pass in the Variables object (if defined) for your prompt as argument.
|
|
116
|
+
```python
|
|
117
|
+
# demo.py
|
|
118
|
+
|
|
119
|
+
from pixie.prompts import Variables, create_prompt
|
|
120
|
+
|
|
121
|
+
simple_prompt = create_prompt('simple_prompt')
|
|
122
|
+
|
|
123
|
+
class Person(Variables):
|
|
124
|
+
name: str
|
|
125
|
+
age: int
|
|
126
|
+
|
|
127
|
+
# Create a prompt with variables
|
|
128
|
+
typed_prompt = create_prompt('typed_prompt', Person)
|
|
129
|
+
|
|
130
|
+
simple_prompt_str = simple_prompt.compile()
|
|
131
|
+
typed_prompt_str = typed_prompt.compile(Person(name="Jane", age=30))
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
Check out more [examples](https://github.com/yiouli/pixie-prompts-examples/blob/main/examples/prompts.py).
|
|
138
|
+
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
pixie/prompts/__init__.py,sha256=ZueU9cJ7aiVHBQYH4g3MXAFtjQwTfvvpy3d8ZTtBQ2c,396
|
|
2
2
|
pixie/prompts/file_watcher.py,sha256=YujSP6vo6clkKY_Bwh5faS_EtIupNOZDzEwrOgIwjew,10679
|
|
3
|
-
pixie/prompts/graphql.py,sha256=
|
|
3
|
+
pixie/prompts/graphql.py,sha256=TvFaPOrbImBfCMdouNJw0AEvy63EmdQotdKyFC2sxFA,12189
|
|
4
4
|
pixie/prompts/prompt.py,sha256=7nBn1PCXNOVL6OflHak7MG9rlZ4Ooa14eTamYk2mE3I,11472
|
|
5
5
|
pixie/prompts/prompt_management.py,sha256=gq5Eklqy2_Sq8jATVae4eANNmyFE8s8a9cedxWs2P_Y,2816
|
|
6
6
|
pixie/prompts/server.py,sha256=gaZ4ws78f2381Zvegphy0yit1pAYZvm4kC7SJeGqYrs,7817
|
|
7
7
|
pixie/prompts/storage.py,sha256=syVHO5IWZXtN20ozPoBq_Anbu0NAH056EWbvlNNWLGU,14448
|
|
8
8
|
pixie/prompts/utils.py,sha256=ssAb4HdwZX__Fq50i2-DFsYXD5vpsYEliA_XI8GPx3Y,21929
|
|
9
|
-
pixie_prompts-0.1.
|
|
10
|
-
pixie_prompts-0.1.
|
|
11
|
-
pixie_prompts-0.1.
|
|
12
|
-
pixie_prompts-0.1.
|
|
13
|
-
pixie_prompts-0.1.
|
|
9
|
+
pixie_prompts-0.1.8.dev6.dist-info/METADATA,sha256=mzBl7mCWNS285U9ZUCXlNZbTvtd5pS2XVu5qUQ4V97g,4723
|
|
10
|
+
pixie_prompts-0.1.8.dev6.dist-info/WHEEL,sha256=3ny-bZhpXrU6vSQ1UPG34FoxZBp3lVcvK0LkgUz6VLk,88
|
|
11
|
+
pixie_prompts-0.1.8.dev6.dist-info/entry_points.txt,sha256=SWOSFuUXDxkJMmf28u7E0Go_LcEpofz7NAlV70Cp8Es,48
|
|
12
|
+
pixie_prompts-0.1.8.dev6.dist-info/licenses/LICENSE,sha256=nZoehBpdSXe6iTF2ZWzM-fgXdXECUZ0J8LrW_1tBwyk,1064
|
|
13
|
+
pixie_prompts-0.1.8.dev6.dist-info/RECORD,,
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: pixie-prompts
|
|
3
|
-
Version: 0.1.7
|
|
4
|
-
Summary: Code-first, type-safe prompt management
|
|
5
|
-
License: MIT
|
|
6
|
-
License-File: LICENSE
|
|
7
|
-
Author: Yiou Li
|
|
8
|
-
Author-email: yol@gopixie.ai
|
|
9
|
-
Requires-Python: >=3.10,<4.0
|
|
10
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
-
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
-
Provides-Extra: server
|
|
18
|
-
Requires-Dist: brotli (>=1.2.0,<2.0.0) ; extra == "server"
|
|
19
|
-
Requires-Dist: colorlog (>=6.10.1) ; extra == "server"
|
|
20
|
-
Requires-Dist: dotenv (>=0.9.9) ; extra == "server"
|
|
21
|
-
Requires-Dist: fastapi (>=0.128.0) ; extra == "server"
|
|
22
|
-
Requires-Dist: jinja2 (>=3.1.6,<4.0.0)
|
|
23
|
-
Requires-Dist: jsonsubschema (>=0.0.7,<0.0.8)
|
|
24
|
-
Requires-Dist: openai[server] (>=2.15.0,<3.0.0) ; extra == "server"
|
|
25
|
-
Requires-Dist: pydantic (>=2.12.5,<3.0.0)
|
|
26
|
-
Requires-Dist: pydantic-ai-slim (>=1.39.0) ; extra == "server"
|
|
27
|
-
Requires-Dist: strawberry-graphql (>=0.288.1) ; extra == "server"
|
|
28
|
-
Requires-Dist: uvicorn (>=0.40.0) ; extra == "server"
|
|
29
|
-
Requires-Dist: watchdog (>=6.0.0) ; extra == "server"
|
|
30
|
-
Requires-Dist: watchfiles[server] (>=1.1.1,<2.0.0) ; extra == "server"
|
|
31
|
-
Project-URL: Changelog, https://github.com/yiouli/pixie-prompts/commits/main/
|
|
32
|
-
Project-URL: Documentation, https://yiouli.github.io/pixie-prompts/
|
|
33
|
-
Project-URL: Homepage, https://gopixie.ai
|
|
34
|
-
Project-URL: Issues, https://github.com/yiouli/pixie-prompts/issues
|
|
35
|
-
Project-URL: Repository, https://github.com/yiouli/pixie-prompts
|
|
36
|
-
Description-Content-Type: text/markdown
|
|
37
|
-
|
|
38
|
-
# pixie-prompts
|
|
39
|
-
Code-first, type-checked prompt management.
|
|
40
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|