prompty 0.1.13__py2.py3-none-any.whl → 0.1.15__py2.py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- prompty/__init__.py +19 -8
- prompty/azure/__init__.py +9 -2
- prompty/azure_openai/__init__.py +10 -0
- prompty/core.py +26 -0
- prompty/openai/__init__.py +9 -2
- prompty/openai/executor.py +1 -1
- prompty/openai/processor.py +1 -1
- prompty/serverless/__init__.py +7 -2
- prompty/serverless/executor.py +2 -0
- prompty/tracer.py +1 -1
- {prompty-0.1.13.dist-info → prompty-0.1.15.dist-info}/METADATA +1 -2
- prompty-0.1.15.dist-info/RECORD +20 -0
- prompty-0.1.13.dist-info/RECORD +0 -19
- {prompty-0.1.13.dist-info → prompty-0.1.15.dist-info}/WHEEL +0 -0
- {prompty-0.1.13.dist-info → prompty-0.1.15.dist-info}/licenses/LICENSE +0 -0
prompty/__init__.py
CHANGED
@@ -6,6 +6,7 @@ from typing import Dict, List, Union
|
|
6
6
|
from prompty.tracer import trace
|
7
7
|
from prompty.core import (
|
8
8
|
Frontmatter,
|
9
|
+
InvokerException,
|
9
10
|
InvokerFactory,
|
10
11
|
ModelSettings,
|
11
12
|
Prompty,
|
@@ -321,18 +322,28 @@ def run(
|
|
321
322
|
if parameters != {}:
|
322
323
|
prompt.model.parameters = param_hoisting(parameters, prompt.model.parameters)
|
323
324
|
|
325
|
+
invoker_type = prompt.model.configuration["type"]
|
326
|
+
|
327
|
+
# invoker registration check
|
328
|
+
if not InvokerFactory.has_invoker("executor", invoker_type):
|
329
|
+
raise InvokerException(
|
330
|
+
f"{invoker_type} Invoker has not been registered properly.", invoker_type
|
331
|
+
)
|
332
|
+
|
324
333
|
# execute
|
325
|
-
executor = InvokerFactory.create_executor(
|
326
|
-
prompt.model.configuration["type"], prompt
|
327
|
-
)
|
334
|
+
executor = InvokerFactory.create_executor(invoker_type, prompt)
|
328
335
|
result = executor(content)
|
329
336
|
|
330
337
|
# skip?
|
331
338
|
if not raw:
|
339
|
+
# invoker registration check
|
340
|
+
if not InvokerFactory.has_invoker("processor", invoker_type):
|
341
|
+
raise InvokerException(
|
342
|
+
f"{invoker_type} Invoker has not been registered properly.", invoker_type
|
343
|
+
)
|
344
|
+
|
332
345
|
# process
|
333
|
-
processor = InvokerFactory.create_processor(
|
334
|
-
prompt.model.configuration["type"], prompt
|
335
|
-
)
|
346
|
+
processor = InvokerFactory.create_processor(invoker_type, prompt)
|
336
347
|
result = processor(result)
|
337
348
|
|
338
349
|
return result
|
@@ -344,7 +355,7 @@ def execute(
|
|
344
355
|
parameters: Dict[str, any] = {},
|
345
356
|
inputs: Dict[str, any] = {},
|
346
357
|
raw: bool = False,
|
347
|
-
|
358
|
+
config_name: str = "default",
|
348
359
|
):
|
349
360
|
"""Execute a prompty.
|
350
361
|
|
@@ -380,7 +391,7 @@ def execute(
|
|
380
391
|
# get caller's path (take into account trace frame)
|
381
392
|
caller = Path(traceback.extract_stack()[-3].filename)
|
382
393
|
path = Path(caller.parent / path).resolve().absolute()
|
383
|
-
prompt = load(path,
|
394
|
+
prompt = load(path, config_name)
|
384
395
|
|
385
396
|
# prepare content
|
386
397
|
content = prepare(prompt, inputs)
|
prompty/azure/__init__.py
CHANGED
@@ -1,3 +1,10 @@
|
|
1
1
|
# __init__.py
|
2
|
-
from .
|
3
|
-
|
2
|
+
from prompty.core import InvokerException
|
3
|
+
|
4
|
+
try:
|
5
|
+
from .executor import AzureOpenAIExecutor
|
6
|
+
from .processor import AzureOpenAIProcessor
|
7
|
+
except ImportError:
|
8
|
+
raise InvokerException(
|
9
|
+
"Error registering AzureOpenAIExecutor and AzureOpenAIProcessor", "azure"
|
10
|
+
)
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# __init__.py
|
2
|
+
from prompty.core import InvokerException
|
3
|
+
|
4
|
+
try:
|
5
|
+
from ..azure.executor import AzureOpenAIExecutor
|
6
|
+
from ..azure.processor import AzureOpenAIProcessor
|
7
|
+
except ImportError:
|
8
|
+
raise InvokerException(
|
9
|
+
"Error registering AzureOpenAIExecutor and AzureOpenAIProcessor", "azure"
|
10
|
+
)
|
prompty/core.py
CHANGED
@@ -343,6 +343,21 @@ class InvokerFactory:
|
|
343
343
|
_executors: Dict[str, Invoker] = {}
|
344
344
|
_processors: Dict[str, Invoker] = {}
|
345
345
|
|
346
|
+
@classmethod
|
347
|
+
def has_invoker(
|
348
|
+
cls, type: Literal["renderer", "parser", "executor", "processor"], name: str
|
349
|
+
) -> bool:
|
350
|
+
if type == "renderer":
|
351
|
+
return name in cls._renderers
|
352
|
+
elif type == "parser":
|
353
|
+
return name in cls._parsers
|
354
|
+
elif type == "executor":
|
355
|
+
return name in cls._executors
|
356
|
+
elif type == "processor":
|
357
|
+
return name in cls._processors
|
358
|
+
else:
|
359
|
+
raise ValueError(f"Type {type} not found")
|
360
|
+
|
346
361
|
@classmethod
|
347
362
|
def add_renderer(cls, name: str, invoker: Invoker) -> None:
|
348
363
|
cls._renderers[name] = invoker
|
@@ -416,6 +431,17 @@ class InvokerFactory:
|
|
416
431
|
return cls._processors[name](prompty)
|
417
432
|
|
418
433
|
|
434
|
+
class InvokerException(Exception):
|
435
|
+
"""Exception class for Invoker"""
|
436
|
+
|
437
|
+
def __init__(self, message: str, type: str) -> None:
|
438
|
+
super().__init__(message)
|
439
|
+
self.type = type
|
440
|
+
|
441
|
+
def __str__(self) -> str:
|
442
|
+
return f"{super().__str__()}. Make sure to pip install any necessary package extras (i.e. could be something like `pip install prompty[{self.type}]`) for {self.type} as well as import the appropriate invokers (i.e. could be something like `import prompty.{self.type}`)."
|
443
|
+
|
444
|
+
|
419
445
|
@InvokerFactory.register_renderer("NOOP")
|
420
446
|
@InvokerFactory.register_parser("NOOP")
|
421
447
|
@InvokerFactory.register_executor("NOOP")
|
prompty/openai/__init__.py
CHANGED
@@ -1,3 +1,10 @@
|
|
1
1
|
# __init__.py
|
2
|
-
from .
|
3
|
-
|
2
|
+
from prompty.core import InvokerException
|
3
|
+
|
4
|
+
try:
|
5
|
+
from .executor import OpenAIExecutor
|
6
|
+
from .processor import OpenAIProcessor
|
7
|
+
except ImportError:
|
8
|
+
raise InvokerException(
|
9
|
+
"Error registering OpenAIExecutor and OpenAIProcessor", "openai"
|
10
|
+
)
|
prompty/openai/executor.py
CHANGED
prompty/openai/processor.py
CHANGED
@@ -6,7 +6,7 @@ from openai.types.create_embedding_response import CreateEmbeddingResponse
|
|
6
6
|
|
7
7
|
|
8
8
|
@InvokerFactory.register_processor("openai")
|
9
|
-
class
|
9
|
+
class OpenAIProcessor(Invoker):
|
10
10
|
"""OpenAI Processor"""
|
11
11
|
|
12
12
|
def __init__(self, prompty: Prompty) -> None:
|
prompty/serverless/__init__.py
CHANGED
@@ -1,3 +1,8 @@
|
|
1
1
|
# __init__.py
|
2
|
-
from .
|
3
|
-
|
2
|
+
from prompty.core import InvokerException
|
3
|
+
|
4
|
+
try:
|
5
|
+
from .executor import ServerlessExecutor
|
6
|
+
from .processor import ServerlessProcessor
|
7
|
+
except ImportError:
|
8
|
+
raise InvokerException("Error registering ServerlessExecutor and ServerlessProcessor", "serverless")
|
prompty/serverless/executor.py
CHANGED
@@ -46,6 +46,7 @@ class ServerlessExecutor(Invoker):
|
|
46
46
|
response = ChatCompletionsClient(
|
47
47
|
endpoint=self.endpoint,
|
48
48
|
credential=AzureKeyCredential(self.key),
|
49
|
+
user_agent=f"prompty/{VERSION}"
|
49
50
|
).complete(
|
50
51
|
model=self.model,
|
51
52
|
messages=data if isinstance(data, list) else [data],
|
@@ -61,6 +62,7 @@ class ServerlessExecutor(Invoker):
|
|
61
62
|
response = EmbeddingsClient(
|
62
63
|
endpoint=self.endpoint,
|
63
64
|
credential=AzureKeyCredential(self.key),
|
65
|
+
user_agent=f"prompty/{VERSION}",
|
64
66
|
).complete(
|
65
67
|
model=self.model,
|
66
68
|
input=data if isinstance(data, list) else [data],
|
prompty/tracer.py
CHANGED
@@ -232,7 +232,7 @@ class PromptyTracer:
|
|
232
232
|
if len(self.stack) == 0:
|
233
233
|
trace_file = (
|
234
234
|
self.output
|
235
|
-
/ f"{frame['name']}.{datetime.now().strftime('%Y%m%d.%H%M%S')}.
|
235
|
+
/ f"{frame['name']}.{datetime.now().strftime('%Y%m%d.%H%M%S')}.tracy"
|
236
236
|
)
|
237
237
|
|
238
238
|
v = importlib.metadata.version("prompty")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: prompty
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.15
|
4
4
|
Summary: Prompty is a new asset class and format for LLM prompts that aims to provide observability, understandability, and portability for developers. It includes spec, tooling, and a runtime. This Prompty runtime supports Python
|
5
5
|
Author-Email: Seth Juarez <seth.juarez@microsoft.com>
|
6
6
|
Requires-Dist: pyyaml>=6.0.1
|
@@ -39,7 +39,6 @@ model:
|
|
39
39
|
api: chat
|
40
40
|
configuration:
|
41
41
|
api_version: 2023-12-01-preview
|
42
|
-
azure_deployment: gpt-35-turbo
|
43
42
|
azure_endpoint: ${env:AZURE_OPENAI_ENDPOINT}
|
44
43
|
azure_deployment: ${env:AZURE_OPENAI_DEPLOYMENT:gpt-35-turbo}
|
45
44
|
sample:
|
@@ -0,0 +1,20 @@
|
|
1
|
+
prompty-0.1.15.dist-info/METADATA,sha256=LjD9DJ73cHctVn2EVIvKSsjbOleo_412rjBBafYYYPg,8916
|
2
|
+
prompty-0.1.15.dist-info/WHEEL,sha256=CuZGaXTwoRLAOVv0AcE3bCTxO5ejVuBEJkUBe9C-kvk,94
|
3
|
+
prompty-0.1.15.dist-info/licenses/LICENSE,sha256=KWSC4z9cfML_t0xThoQYjzTdcZQj86Y_mhXdatzU-KM,1052
|
4
|
+
prompty/__init__.py,sha256=XTUgJ3xT7HYJieuWW5PBItey0BWneg3G7iBBjIeNJZU,11628
|
5
|
+
prompty/azure/__init__.py,sha256=ptGajCh68s_tugPv45Y4GJCyBToNFCExUzUh9yIBIfo,292
|
6
|
+
prompty/azure/executor.py,sha256=x2ng2EbYUxbingjy8w27TFGWezs4QC0LHh_S0F0-E1U,3082
|
7
|
+
prompty/azure/processor.py,sha256=e9CcKG665zvCLPeJfS91FM6c_W_6YY0mVENxinCo19A,2253
|
8
|
+
prompty/azure_openai/__init__.py,sha256=tjCu2NEF-YV3AZPPZfYjdkCzPtPbc2NfYazPb1Gu4GI,306
|
9
|
+
prompty/cli.py,sha256=oIJ5aPCjwBl4xA5SWkbQ_Xj0KhzuSJhRnqV95DhfORc,3382
|
10
|
+
prompty/core.py,sha256=O_Kvj7XjaNG50_mWzpxf5xVOEOWGYBkwBXqPA__5kz0,17126
|
11
|
+
prompty/openai/__init__.py,sha256=16LxFrG_qGMg_Nx_BTMkCZupPEADsi8Gj234uFiXoZo,273
|
12
|
+
prompty/openai/executor.py,sha256=5LXME0ACvbX3PSpSfh9ohDGWB50ZYBXLZG238wQiVGc,2212
|
13
|
+
prompty/openai/processor.py,sha256=Cw-_O_r9B5QqiCsfIglI5lcJgKCStkse2iIDbPWxfhg,2169
|
14
|
+
prompty/parsers.py,sha256=4mmIn4SVNs8B0R1BufanqUJk8v4r0OEEo8yx6UOxQpA,4670
|
15
|
+
prompty/renderers.py,sha256=RSHFQFx7AtKLUfsMLCXR0a56Mb7DL1NJNgjUqgg3IqU,776
|
16
|
+
prompty/serverless/__init__.py,sha256=NPqoFATEMQ96G8OQkVcGxUWU4llIQCwxfJePPo8YFY8,279
|
17
|
+
prompty/serverless/executor.py,sha256=fYCMV01iLBLpH2SQ9nxmrvY9ijAGpZezwkobZwUjSVQ,2781
|
18
|
+
prompty/serverless/processor.py,sha256=pft1XGbPzo0MzQMbAt1VxsLsvRrjQO3B8MXEE2PfSA0,1982
|
19
|
+
prompty/tracer.py,sha256=dwASxJsVnoUNIKLuBHtZAhD0JctbTCImBP5mjVGCnPo,8809
|
20
|
+
prompty-0.1.15.dist-info/RECORD,,
|
prompty-0.1.13.dist-info/RECORD
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
prompty-0.1.13.dist-info/METADATA,sha256=QTF628f7AXmm8K6MvnafJJGJk6ye-FuYaf6m8-d8WWk,8951
|
2
|
-
prompty-0.1.13.dist-info/WHEEL,sha256=CuZGaXTwoRLAOVv0AcE3bCTxO5ejVuBEJkUBe9C-kvk,94
|
3
|
-
prompty-0.1.13.dist-info/licenses/LICENSE,sha256=KWSC4z9cfML_t0xThoQYjzTdcZQj86Y_mhXdatzU-KM,1052
|
4
|
-
prompty/__init__.py,sha256=5t_hxoRVxsbc7gfMyH9EVO2j259dM6uac3GmspQ-MjE,11146
|
5
|
-
prompty/azure/__init__.py,sha256=6duJ79CDPG3w-cLk3vt8YfELDMOtSsnI2ClNLMFP_Og,100
|
6
|
-
prompty/azure/executor.py,sha256=x2ng2EbYUxbingjy8w27TFGWezs4QC0LHh_S0F0-E1U,3082
|
7
|
-
prompty/azure/processor.py,sha256=e9CcKG665zvCLPeJfS91FM6c_W_6YY0mVENxinCo19A,2253
|
8
|
-
prompty/cli.py,sha256=oIJ5aPCjwBl4xA5SWkbQ_Xj0KhzuSJhRnqV95DhfORc,3382
|
9
|
-
prompty/core.py,sha256=Zy6BFYUAMTeaAFeHdcRkm4lrxlyBEKHwc96XQJH3M2U,16120
|
10
|
-
prompty/openai/__init__.py,sha256=6duJ79CDPG3w-cLk3vt8YfELDMOtSsnI2ClNLMFP_Og,100
|
11
|
-
prompty/openai/executor.py,sha256=hlze8dXG_jPurPBN7vPC-HJC1dYXSSZeElhE_X_BJhk,2217
|
12
|
-
prompty/openai/processor.py,sha256=PacKjMmGO-fd5KhOs98JyjsIf0Kl_J2SX5VroA8lVbI,2174
|
13
|
-
prompty/parsers.py,sha256=4mmIn4SVNs8B0R1BufanqUJk8v4r0OEEo8yx6UOxQpA,4670
|
14
|
-
prompty/renderers.py,sha256=RSHFQFx7AtKLUfsMLCXR0a56Mb7DL1NJNgjUqgg3IqU,776
|
15
|
-
prompty/serverless/__init__.py,sha256=KgsiNr-IhPiIuZoChvDf6xbbvFF467MCUKspJHo56yc,98
|
16
|
-
prompty/serverless/executor.py,sha256=2XVzFX9SMX33sQTW-AZObiZ5NtVl3xVahb79ejMrlz8,2684
|
17
|
-
prompty/serverless/processor.py,sha256=pft1XGbPzo0MzQMbAt1VxsLsvRrjQO3B8MXEE2PfSA0,1982
|
18
|
-
prompty/tracer.py,sha256=r-HC__xLtFPb2pr-xGUuhdlAaMA_PmsBB_NG79jKRO4,8810
|
19
|
-
prompty-0.1.13.dist-info/RECORD,,
|
File without changes
|
File without changes
|