prompty 0.1.14__py2.py3-none-any.whl → 0.1.16__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 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
prompty/azure/__init__.py CHANGED
@@ -1,3 +1,10 @@
1
1
  # __init__.py
2
- from .executor import AzureOpenAIExecutor
3
- from .processor import AzureOpenAIProcessor
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")
@@ -1,3 +1,10 @@
1
1
  # __init__.py
2
- from .executor import AzureOpenAIExecutor
3
- from .processor import AzureOpenAIProcessor
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
+ )
@@ -7,7 +7,7 @@ VERSION = importlib.metadata.version("prompty")
7
7
 
8
8
 
9
9
  @InvokerFactory.register_executor("openai")
10
- class AzureOpenAIExecutor(Invoker):
10
+ class OpenAIExecutor(Invoker):
11
11
  """OpenAI Executor"""
12
12
 
13
13
  def __init__(self, prompty: Prompty) -> None:
@@ -6,7 +6,7 @@ from openai.types.create_embedding_response import CreateEmbeddingResponse
6
6
 
7
7
 
8
8
  @InvokerFactory.register_processor("openai")
9
- class AzureOpenAIProcessor(Invoker):
9
+ class OpenAIProcessor(Invoker):
10
10
  """OpenAI Processor"""
11
11
 
12
12
  def __init__(self, prompty: Prompty) -> None:
@@ -1,3 +1,8 @@
1
1
  # __init__.py
2
- from .executor import ServerlessExecutor
3
- from .processor import ServerlessProcessor
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/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')}.ptrace"
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.14
3
+ Version: 0.1.16
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,21 @@
1
+ prompty-0.1.16.dist-info/METADATA,sha256=GrbCbCC5h_7Jen_jONo7lTvsfMvkvjuodRJDbBKvt4I,8916
2
+ prompty-0.1.16.dist-info/WHEEL,sha256=CuZGaXTwoRLAOVv0AcE3bCTxO5ejVuBEJkUBe9C-kvk,94
3
+ prompty-0.1.16.dist-info/entry_points.txt,sha256=9y1lKPWUpPWRJzUslcVH-gMwbNoa2PzjyoZsKYLQqyw,45
4
+ prompty-0.1.16.dist-info/licenses/LICENSE,sha256=KWSC4z9cfML_t0xThoQYjzTdcZQj86Y_mhXdatzU-KM,1052
5
+ prompty/__init__.py,sha256=XTUgJ3xT7HYJieuWW5PBItey0BWneg3G7iBBjIeNJZU,11628
6
+ prompty/azure/__init__.py,sha256=ptGajCh68s_tugPv45Y4GJCyBToNFCExUzUh9yIBIfo,292
7
+ prompty/azure/executor.py,sha256=x2ng2EbYUxbingjy8w27TFGWezs4QC0LHh_S0F0-E1U,3082
8
+ prompty/azure/processor.py,sha256=e9CcKG665zvCLPeJfS91FM6c_W_6YY0mVENxinCo19A,2253
9
+ prompty/azure_openai/__init__.py,sha256=tjCu2NEF-YV3AZPPZfYjdkCzPtPbc2NfYazPb1Gu4GI,306
10
+ prompty/cli.py,sha256=oIJ5aPCjwBl4xA5SWkbQ_Xj0KhzuSJhRnqV95DhfORc,3382
11
+ prompty/core.py,sha256=O_Kvj7XjaNG50_mWzpxf5xVOEOWGYBkwBXqPA__5kz0,17126
12
+ prompty/openai/__init__.py,sha256=16LxFrG_qGMg_Nx_BTMkCZupPEADsi8Gj234uFiXoZo,273
13
+ prompty/openai/executor.py,sha256=5LXME0ACvbX3PSpSfh9ohDGWB50ZYBXLZG238wQiVGc,2212
14
+ prompty/openai/processor.py,sha256=Cw-_O_r9B5QqiCsfIglI5lcJgKCStkse2iIDbPWxfhg,2169
15
+ prompty/parsers.py,sha256=4mmIn4SVNs8B0R1BufanqUJk8v4r0OEEo8yx6UOxQpA,4670
16
+ prompty/renderers.py,sha256=RSHFQFx7AtKLUfsMLCXR0a56Mb7DL1NJNgjUqgg3IqU,776
17
+ prompty/serverless/__init__.py,sha256=NPqoFATEMQ96G8OQkVcGxUWU4llIQCwxfJePPo8YFY8,279
18
+ prompty/serverless/executor.py,sha256=fYCMV01iLBLpH2SQ9nxmrvY9ijAGpZezwkobZwUjSVQ,2781
19
+ prompty/serverless/processor.py,sha256=pft1XGbPzo0MzQMbAt1VxsLsvRrjQO3B8MXEE2PfSA0,1982
20
+ prompty/tracer.py,sha256=dwASxJsVnoUNIKLuBHtZAhD0JctbTCImBP5mjVGCnPo,8809
21
+ prompty-0.1.16.dist-info/RECORD,,
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ prompty = prompty.cli:run
3
+
@@ -1,19 +0,0 @@
1
- prompty-0.1.14.dist-info/METADATA,sha256=lbEMlGMerWd1XGwjZwG-DDy2wQQ9rzUowD0JNxaqTZE,8951
2
- prompty-0.1.14.dist-info/WHEEL,sha256=CuZGaXTwoRLAOVv0AcE3bCTxO5ejVuBEJkUBe9C-kvk,94
3
- prompty-0.1.14.dist-info/licenses/LICENSE,sha256=KWSC4z9cfML_t0xThoQYjzTdcZQj86Y_mhXdatzU-KM,1052
4
- prompty/__init__.py,sha256=mg_lSGVEe4etHHRhxoVLa6wgQDipFECd1rVFPyXzkUA,11148
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=fYCMV01iLBLpH2SQ9nxmrvY9ijAGpZezwkobZwUjSVQ,2781
17
- prompty/serverless/processor.py,sha256=pft1XGbPzo0MzQMbAt1VxsLsvRrjQO3B8MXEE2PfSA0,1982
18
- prompty/tracer.py,sha256=r-HC__xLtFPb2pr-xGUuhdlAaMA_PmsBB_NG79jKRO4,8810
19
- prompty-0.1.14.dist-info/RECORD,,