pixie-prompts 0.1.7__tar.gz → 0.1.8.dev6__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.
@@ -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
+
@@ -0,0 +1,100 @@
1
+ # pixie-prompts
2
+ **Code-first, type-checked prompt management.**
3
+ Manage prompt locally in your codebase, with Jinja rendering, variable type-hint and validations.
4
+
5
+ [**Demo**](https://github.com/user-attachments/assets/aba55aca-1ad3-4f25-97f9-db0f8e67dbe6)
6
+
7
+ [**Try it live**](https://gopixie.ai/?url=https%3A%2F%2Fpixie-prompts-examples.vercel.app%2Fgraphql)
8
+
9
+ ## Setup
10
+
11
+
12
+
13
+
14
+ In your project folder, install **pixie-prompts[server]** Python package:
15
+ ```bash
16
+ pip install pixie-prompts[server]
17
+ ```
18
+ > Note: you can install **pixie-prompts** without the server extras for your production build.
19
+
20
+ Start the local dev server and open the web UI by running:
21
+ ```bash
22
+ pp
23
+ ```
24
+ > 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).
25
+
26
+ To test prompts, create *.env* file with LLM API key(s):
27
+ ```ini
28
+ # .env
29
+ OPENAI_API_KEY=...
30
+ GEMINI_API_KEY=...
31
+ ```
32
+
33
+ ## Register Prompt
34
+
35
+ In your code, create a new prompt using `create_prompt`:
36
+ ```python
37
+ # prompts.py
38
+ from pixie.prompts import create_prompt
39
+
40
+ simple_prompt = create_prompt('simple_prompt')
41
+ ```
42
+
43
+ Your prompt would automatically appear in the web UI after your code is saved.
44
+
45
+
46
+ ## Manage Prompt
47
+
48
+ You can create new version(s) of a prompt in the web UI.
49
+
50
+ 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*.
51
+
52
+ > Note: it's recommended to only edit your prompts via the web UI to get type-hint and validation.
53
+
54
+
55
+ ## Define Variables
56
+
57
+ 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.
58
+
59
+ ```python
60
+ # prompts.py
61
+ from pixie.prompts import Variables, create_prompt
62
+
63
+ class Person(Variables):
64
+ name: str
65
+ age: int
66
+
67
+ # Create a prompt with variables
68
+ typed_prompt = create_prompt('typed_prompt', Person)
69
+ ```
70
+
71
+ 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.
72
+
73
+ The web UI will parse your variable definitions and use it to decide input fields, type-hints and validations.
74
+
75
+
76
+ ## Use Prompt
77
+
78
+ 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.
79
+ ```python
80
+ # demo.py
81
+
82
+ from pixie.prompts import Variables, create_prompt
83
+
84
+ simple_prompt = create_prompt('simple_prompt')
85
+
86
+ class Person(Variables):
87
+ name: str
88
+ age: int
89
+
90
+ # Create a prompt with variables
91
+ typed_prompt = create_prompt('typed_prompt', Person)
92
+
93
+ simple_prompt_str = simple_prompt.compile()
94
+ typed_prompt_str = typed_prompt.compile(Person(name="Jane", age=30))
95
+
96
+ ```
97
+
98
+
99
+
100
+ Check out more [examples](https://github.com/yiouli/pixie-prompts-examples/blob/main/examples/prompts.py).
@@ -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.")
@@ -4,7 +4,7 @@ packages = [
4
4
  { include = "pixie" },
5
5
  ]
6
6
 
7
- version = "0.1.7"
7
+ version = "0.1.8.dev6"
8
8
  description = "Code-first, type-safe prompt management"
9
9
  authors = ["Yiou Li <yol@gopixie.ai>"]
10
10
  license = "MIT"
@@ -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
-
@@ -1,2 +0,0 @@
1
- # pixie-prompts
2
- Code-first, type-checked prompt management.