promptlayer 1.0.18__py3-none-any.whl → 1.0.20__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.
Potentially problematic release.
This version of promptlayer might be problematic. Click here for more details.
- promptlayer/__init__.py +1 -1
- promptlayer/promptlayer.py +49 -3
- promptlayer/types/__init__.py +2 -1
- promptlayer/types/prompt_template.py +2 -2
- promptlayer/types/request_log.py +8 -0
- promptlayer/utils.py +23 -0
- {promptlayer-1.0.18.dist-info → promptlayer-1.0.20.dist-info}/METADATA +1 -1
- promptlayer-1.0.20.dist-info/RECORD +17 -0
- promptlayer-1.0.18.dist-info/RECORD +0 -16
- {promptlayer-1.0.18.dist-info → promptlayer-1.0.20.dist-info}/LICENSE +0 -0
- {promptlayer-1.0.18.dist-info → promptlayer-1.0.20.dist-info}/WHEEL +0 -0
promptlayer/__init__.py
CHANGED
promptlayer/promptlayer.py
CHANGED
|
@@ -15,6 +15,7 @@ from promptlayer.promptlayer_base import PromptLayerBase
|
|
|
15
15
|
from promptlayer.span_exporter import PromptLayerSpanExporter
|
|
16
16
|
from promptlayer.templates import TemplateManager
|
|
17
17
|
from promptlayer.track import TrackManager
|
|
18
|
+
from promptlayer.types.prompt_template import PromptTemplate
|
|
18
19
|
from promptlayer.utils import (
|
|
19
20
|
anthropic_request,
|
|
20
21
|
anthropic_stream_completion,
|
|
@@ -24,6 +25,7 @@ from promptlayer.utils import (
|
|
|
24
25
|
openai_stream_completion,
|
|
25
26
|
stream_response,
|
|
26
27
|
track_request,
|
|
28
|
+
util_log_request,
|
|
27
29
|
)
|
|
28
30
|
|
|
29
31
|
MAP_PROVIDER_TO_FUNCTION_NAME = {
|
|
@@ -356,12 +358,13 @@ class PromptLayer:
|
|
|
356
358
|
else:
|
|
357
359
|
return self._run_internal(**_run_internal_kwargs)
|
|
358
360
|
|
|
359
|
-
def traceable(self, attributes=None):
|
|
361
|
+
def traceable(self, attributes=None, name=None):
|
|
360
362
|
def decorator(func):
|
|
361
363
|
@wraps(func)
|
|
362
364
|
def sync_wrapper(*args, **kwargs):
|
|
363
365
|
if self.tracer:
|
|
364
|
-
|
|
366
|
+
span_name = name or func.__name__
|
|
367
|
+
with self.tracer.start_as_current_span(span_name) as span:
|
|
365
368
|
if attributes:
|
|
366
369
|
for key, value in attributes.items():
|
|
367
370
|
span.set_attribute(key, value)
|
|
@@ -379,7 +382,8 @@ class PromptLayer:
|
|
|
379
382
|
@wraps(func)
|
|
380
383
|
async def async_wrapper(*args, **kwargs):
|
|
381
384
|
if self.tracer:
|
|
382
|
-
|
|
385
|
+
span_name = name or func.__name__
|
|
386
|
+
with self.tracer.start_as_current_span(span_name) as span:
|
|
383
387
|
if attributes:
|
|
384
388
|
for key, value in attributes.items():
|
|
385
389
|
span.set_attribute(key, value)
|
|
@@ -397,3 +401,45 @@ class PromptLayer:
|
|
|
397
401
|
return async_wrapper if asyncio.iscoroutinefunction(func) else sync_wrapper
|
|
398
402
|
|
|
399
403
|
return decorator
|
|
404
|
+
|
|
405
|
+
def log_request(
|
|
406
|
+
self,
|
|
407
|
+
*,
|
|
408
|
+
provider: str,
|
|
409
|
+
model: str,
|
|
410
|
+
input: PromptTemplate,
|
|
411
|
+
output: PromptTemplate,
|
|
412
|
+
request_start_time: float,
|
|
413
|
+
request_end_time: float,
|
|
414
|
+
parameters: Dict[str, Any] = {},
|
|
415
|
+
tags: List[str] = [],
|
|
416
|
+
metadata: Dict[str, str] = {},
|
|
417
|
+
prompt_name: Union[str, None] = None,
|
|
418
|
+
prompt_version_number: Union[int, None] = None,
|
|
419
|
+
prompt_input_variables: Dict[str, Any] = {},
|
|
420
|
+
input_tokens: int = 0,
|
|
421
|
+
output_tokens: int = 0,
|
|
422
|
+
price: float = 0.0,
|
|
423
|
+
function_name: str = "",
|
|
424
|
+
score: int = 0,
|
|
425
|
+
):
|
|
426
|
+
return util_log_request(
|
|
427
|
+
self.api_key,
|
|
428
|
+
provider=provider,
|
|
429
|
+
model=model,
|
|
430
|
+
input=input,
|
|
431
|
+
output=output,
|
|
432
|
+
request_start_time=request_start_time,
|
|
433
|
+
request_end_time=request_end_time,
|
|
434
|
+
parameters=parameters,
|
|
435
|
+
tags=tags,
|
|
436
|
+
metadata=metadata,
|
|
437
|
+
prompt_name=prompt_name,
|
|
438
|
+
prompt_version_number=prompt_version_number,
|
|
439
|
+
prompt_input_variables=prompt_input_variables,
|
|
440
|
+
input_tokens=input_tokens,
|
|
441
|
+
output_tokens=output_tokens,
|
|
442
|
+
price=price,
|
|
443
|
+
function_name=function_name,
|
|
444
|
+
score=score,
|
|
445
|
+
)
|
promptlayer/types/__init__.py
CHANGED
|
@@ -157,13 +157,13 @@ class BasePromptTemplate(TypedDict, total=False):
|
|
|
157
157
|
tags: List[str]
|
|
158
158
|
|
|
159
159
|
|
|
160
|
-
class
|
|
160
|
+
class PromptBlueprint(TypedDict, total=False):
|
|
161
161
|
prompt_template: PromptTemplate
|
|
162
162
|
commit_message: str
|
|
163
163
|
metadata: Metadata
|
|
164
164
|
|
|
165
165
|
|
|
166
|
-
class PublishPromptTemplate(BasePromptTemplate,
|
|
166
|
+
class PublishPromptTemplate(BasePromptTemplate, PromptBlueprint, total=False):
|
|
167
167
|
release_labels: Optional[List[str]] = None
|
|
168
168
|
|
|
169
169
|
|
promptlayer/utils.py
CHANGED
|
@@ -13,6 +13,7 @@ from typing import Callable, Generator, List, Union
|
|
|
13
13
|
import requests
|
|
14
14
|
from opentelemetry import context, trace
|
|
15
15
|
|
|
16
|
+
from promptlayer.types import RequestLog
|
|
16
17
|
from promptlayer.types.prompt_template import (
|
|
17
18
|
GetPromptTemplate,
|
|
18
19
|
GetPromptTemplateResponse,
|
|
@@ -907,3 +908,25 @@ def get_api_key():
|
|
|
907
908
|
"Please set your PROMPTLAYER_API_KEY environment variable or set API KEY in code using 'promptlayer.api_key = <your_api_key>' "
|
|
908
909
|
)
|
|
909
910
|
return api_key
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
def util_log_request(api_key: str, **kwargs) -> Union[RequestLog, None]:
|
|
914
|
+
try:
|
|
915
|
+
response = requests.post(
|
|
916
|
+
f"{URL_API_PROMPTLAYER}/log-request",
|
|
917
|
+
headers={"X-API-KEY": api_key},
|
|
918
|
+
json=kwargs,
|
|
919
|
+
)
|
|
920
|
+
if response.status_code != 201:
|
|
921
|
+
warn_on_bad_response(
|
|
922
|
+
response,
|
|
923
|
+
"WARNING: While logging your request PromptLayer had the following error",
|
|
924
|
+
)
|
|
925
|
+
return None
|
|
926
|
+
return response.json()
|
|
927
|
+
except Exception as e:
|
|
928
|
+
print(
|
|
929
|
+
f"WARNING: While tracking your prompt PromptLayer had the following error: {e}",
|
|
930
|
+
file=sys.stderr,
|
|
931
|
+
)
|
|
932
|
+
return None
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
promptlayer/__init__.py,sha256=cL0dESTkFuO6urMy37H4-l4eueAOO7MP-Hl9lt5LHws,102
|
|
2
|
+
promptlayer/groups/__init__.py,sha256=-xs-2cn0nc0D_5YxZr3nC86iTdRVZmBhEpOKDJXE-sQ,224
|
|
3
|
+
promptlayer/groups/groups.py,sha256=yeO6T0TM3qB0ondZRiHhcH8G06YygrpFoM8b9RmoIao,165
|
|
4
|
+
promptlayer/promptlayer.py,sha256=9pQkicXafiEHw4kS5CiIBRzECg7I6VCuQSKKaAEyE-4,15401
|
|
5
|
+
promptlayer/promptlayer_base.py,sha256=sev-EZehRXJSZSmJtMkqmAUK1345pqbDY_lNjPP5MYA,7158
|
|
6
|
+
promptlayer/span_exporter.py,sha256=zIJNsb3Fe6yb5wKLDmkoPF2wqFjk1p39E0jWHD2plzI,2658
|
|
7
|
+
promptlayer/templates.py,sha256=aY_-BCrL0AgIdYEUE28pi0AP_avTVAgwv5hgzrh75vo,717
|
|
8
|
+
promptlayer/track/__init__.py,sha256=VheO_Au0lffGlPKYYPQwkv8ci16wSXABCVSNRoFWu_w,945
|
|
9
|
+
promptlayer/track/track.py,sha256=XNEZT9yNiRBPp9vaDZo_f0dP_ldOu8q1qafpVfS5Ze8,1610
|
|
10
|
+
promptlayer/types/__init__.py,sha256=xJcvQuOk91ZBBePb40-1FDNDKYrZoH5lPE2q6_UhprM,111
|
|
11
|
+
promptlayer/types/prompt_template.py,sha256=TUXLXvuvew0EBLfTMBa2LhFeQoF7R-tcFKg7_UUtHMQ,4433
|
|
12
|
+
promptlayer/types/request_log.py,sha256=xU6bcxQar6GaBOJlgZTavXUV3FjE8sF_nSjPu4Ya_00,174
|
|
13
|
+
promptlayer/utils.py,sha256=wWsep8gFMAlAaZgzo6g8uLwoBA5uIql1PAnq7nSUw8c,30398
|
|
14
|
+
promptlayer-1.0.20.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
15
|
+
promptlayer-1.0.20.dist-info/METADATA,sha256=5XLJbk34lEE8l67mlaAtNZVZEl6GlODn1x1YrkSlTB8,4609
|
|
16
|
+
promptlayer-1.0.20.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
17
|
+
promptlayer-1.0.20.dist-info/RECORD,,
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
promptlayer/__init__.py,sha256=MVQ-wlZkL_mEj_JfMdDtR1lv1x5c_b3saQtpNBQCmEM,102
|
|
2
|
-
promptlayer/groups/__init__.py,sha256=-xs-2cn0nc0D_5YxZr3nC86iTdRVZmBhEpOKDJXE-sQ,224
|
|
3
|
-
promptlayer/groups/groups.py,sha256=yeO6T0TM3qB0ondZRiHhcH8G06YygrpFoM8b9RmoIao,165
|
|
4
|
-
promptlayer/promptlayer.py,sha256=OzwekB-elWljFTUciOg3KiMWJKGleZkR9G3hxtxyj7A,13878
|
|
5
|
-
promptlayer/promptlayer_base.py,sha256=sev-EZehRXJSZSmJtMkqmAUK1345pqbDY_lNjPP5MYA,7158
|
|
6
|
-
promptlayer/span_exporter.py,sha256=zIJNsb3Fe6yb5wKLDmkoPF2wqFjk1p39E0jWHD2plzI,2658
|
|
7
|
-
promptlayer/templates.py,sha256=aY_-BCrL0AgIdYEUE28pi0AP_avTVAgwv5hgzrh75vo,717
|
|
8
|
-
promptlayer/track/__init__.py,sha256=VheO_Au0lffGlPKYYPQwkv8ci16wSXABCVSNRoFWu_w,945
|
|
9
|
-
promptlayer/track/track.py,sha256=XNEZT9yNiRBPp9vaDZo_f0dP_ldOu8q1qafpVfS5Ze8,1610
|
|
10
|
-
promptlayer/types/__init__.py,sha256=ulWSyCrk5hZ_PI-nKGpd6GPcRaK8lqP4wFl0LPNUYWk,61
|
|
11
|
-
promptlayer/types/prompt_template.py,sha256=QbxYSeIubrwp8KmDKdt9syAwzONFPh_So9yr4H73ANQ,4429
|
|
12
|
-
promptlayer/utils.py,sha256=-p0qapUvkZYJd_Dfat3c8LANXWU1JN0bJB91IyjB8iA,29656
|
|
13
|
-
promptlayer-1.0.18.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
14
|
-
promptlayer-1.0.18.dist-info/METADATA,sha256=qU7gZWgtYWWWuJ3fXx2cKbaz9W7bmzFGM6pOodi4_KU,4609
|
|
15
|
-
promptlayer-1.0.18.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
16
|
-
promptlayer-1.0.18.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|