pixie-prompts 0.1.10.dev1__tar.gz → 0.1.11__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.
- {pixie_prompts-0.1.10.dev1 → pixie_prompts-0.1.11}/PKG-INFO +1 -1
- {pixie_prompts-0.1.10.dev1 → pixie_prompts-0.1.11}/pixie/prompts/prompt.py +2 -2
- {pixie_prompts-0.1.10.dev1 → pixie_prompts-0.1.11}/pixie/prompts/storage.py +42 -13
- {pixie_prompts-0.1.10.dev1 → pixie_prompts-0.1.11}/pyproject.toml +1 -1
- {pixie_prompts-0.1.10.dev1 → pixie_prompts-0.1.11}/LICENSE +0 -0
- {pixie_prompts-0.1.10.dev1 → pixie_prompts-0.1.11}/README.md +0 -0
- {pixie_prompts-0.1.10.dev1 → pixie_prompts-0.1.11}/pixie/prompts/__init__.py +0 -0
- {pixie_prompts-0.1.10.dev1 → pixie_prompts-0.1.11}/pixie/prompts/file_watcher.py +0 -0
- {pixie_prompts-0.1.10.dev1 → pixie_prompts-0.1.11}/pixie/prompts/graphql.py +0 -0
- {pixie_prompts-0.1.10.dev1 → pixie_prompts-0.1.11}/pixie/prompts/prompt_management.py +0 -0
- {pixie_prompts-0.1.10.dev1 → pixie_prompts-0.1.11}/pixie/prompts/server.py +0 -0
- {pixie_prompts-0.1.10.dev1 → pixie_prompts-0.1.11}/pixie/prompts/utils.py +0 -0
|
@@ -49,7 +49,7 @@ key is the id() of the compiled string."""
|
|
|
49
49
|
def _find_matching_prompt(obj):
|
|
50
50
|
if isinstance(obj, str):
|
|
51
51
|
for compiled in _compiled_prompt_registry.values():
|
|
52
|
-
if compiled.value
|
|
52
|
+
if compiled.value in obj:
|
|
53
53
|
return compiled
|
|
54
54
|
return None
|
|
55
55
|
elif isinstance(obj, dict):
|
|
@@ -76,7 +76,7 @@ def get_compiled_prompt(text: str) -> CompiledPrompt | None:
|
|
|
76
76
|
if direct_match:
|
|
77
77
|
return direct_match
|
|
78
78
|
for compiled in _compiled_prompt_registry.values():
|
|
79
|
-
if compiled.value
|
|
79
|
+
if compiled.value in text:
|
|
80
80
|
return compiled
|
|
81
81
|
try:
|
|
82
82
|
obj = json.loads(text)
|
|
@@ -41,6 +41,10 @@ class PromptLoadError(Exception):
|
|
|
41
41
|
super().__init__(message)
|
|
42
42
|
|
|
43
43
|
|
|
44
|
+
class PromptNotFoundError(KeyError):
|
|
45
|
+
pass
|
|
46
|
+
|
|
47
|
+
|
|
44
48
|
class BaseUntypedPromptWithCreationTime(BaseUntypedPrompt):
|
|
45
49
|
|
|
46
50
|
def __init__(
|
|
@@ -254,7 +258,12 @@ class _FilePromptStorage(PromptStorage):
|
|
|
254
258
|
return original is None
|
|
255
259
|
|
|
256
260
|
def get(self, prompt_id: str) -> BaseUntypedPromptWithCreationTime:
|
|
257
|
-
|
|
261
|
+
try:
|
|
262
|
+
return self._prompts[prompt_id]
|
|
263
|
+
except KeyError:
|
|
264
|
+
raise PromptNotFoundError(
|
|
265
|
+
f"Prompt with ID '{prompt_id}' not found in storage."
|
|
266
|
+
)
|
|
258
267
|
|
|
259
268
|
|
|
260
269
|
_storage_instance: PromptStorage | None = None
|
|
@@ -306,9 +315,11 @@ class StorageBackedPrompt(Prompt[TPromptVar]):
|
|
|
306
315
|
id: str,
|
|
307
316
|
*,
|
|
308
317
|
variables_definition: type[TPromptVar] = NoneType,
|
|
318
|
+
default: str | None = None,
|
|
309
319
|
) -> None:
|
|
310
320
|
self._id = id
|
|
311
321
|
self._variables_definition = variables_definition
|
|
322
|
+
self._default = default
|
|
312
323
|
self._prompt: BasePrompt[TPromptVar] | None = None
|
|
313
324
|
|
|
314
325
|
@property
|
|
@@ -319,24 +330,42 @@ class StorageBackedPrompt(Prompt[TPromptVar]):
|
|
|
319
330
|
def variables_definition(self) -> type[TPromptVar]:
|
|
320
331
|
return self._variables_definition
|
|
321
332
|
|
|
333
|
+
@property
|
|
334
|
+
def default(self) -> str | None:
|
|
335
|
+
return self._default
|
|
336
|
+
|
|
322
337
|
def get_variables_schema(self) -> dict[str, Any]:
|
|
323
338
|
return variables_definition_to_schema(self._variables_definition)
|
|
324
339
|
|
|
325
340
|
def _get_prompt(self) -> BasePrompt[TPromptVar]:
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
341
|
+
if self._prompt is not None:
|
|
342
|
+
return self._prompt
|
|
343
|
+
try:
|
|
344
|
+
storage = _ensure_storage_initialized()
|
|
345
|
+
if self._prompt is None:
|
|
346
|
+
untyped_prompt = storage.get(self.id)
|
|
347
|
+
self._prompt = BasePrompt.from_untyped(
|
|
348
|
+
untyped_prompt,
|
|
349
|
+
variables_definition=self.variables_definition,
|
|
350
|
+
)
|
|
351
|
+
schema_from_storage = untyped_prompt.get_variables_schema()
|
|
352
|
+
schema_from_definition = self.get_variables_schema()
|
|
353
|
+
if not isSubschema(schema_from_definition, schema_from_storage):
|
|
354
|
+
raise TypeError(
|
|
355
|
+
"Schema from definition is not a subschema of the schema from storage."
|
|
356
|
+
)
|
|
357
|
+
return self._prompt
|
|
358
|
+
except (PromptNotFoundError, PromptLoadError):
|
|
359
|
+
if self.default is None:
|
|
360
|
+
raise PromptNotFoundError(
|
|
361
|
+
f"Cannot load prompt with id '{self.id}' from storage, and no default is provided."
|
|
362
|
+
)
|
|
363
|
+
self._prompt = BasePrompt(
|
|
364
|
+
id=self.id,
|
|
365
|
+
versions={"v0": self.default},
|
|
331
366
|
variables_definition=self.variables_definition,
|
|
332
367
|
)
|
|
333
|
-
|
|
334
|
-
schema_from_definition = self.get_variables_schema()
|
|
335
|
-
if not isSubschema(schema_from_definition, schema_from_storage):
|
|
336
|
-
raise TypeError(
|
|
337
|
-
"Schema from definition is not a subschema of the schema from storage."
|
|
338
|
-
)
|
|
339
|
-
return self._prompt
|
|
368
|
+
return self._prompt
|
|
340
369
|
|
|
341
370
|
def actualize(self) -> Self:
|
|
342
371
|
self._get_prompt()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|