promptlayer 1.0.71__py3-none-any.whl → 1.0.73__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 +37 -2
- promptlayer/exceptions.py +119 -0
- promptlayer/groups/__init__.py +9 -5
- promptlayer/groups/groups.py +4 -6
- promptlayer/promptlayer.py +76 -28
- promptlayer/promptlayer_base.py +19 -9
- promptlayer/promptlayer_mixins.py +5 -3
- promptlayer/span_exporter.py +16 -9
- promptlayer/templates.py +11 -7
- promptlayer/track/__init__.py +18 -10
- promptlayer/track/track.py +53 -28
- promptlayer/utils.py +717 -306
- {promptlayer-1.0.71.dist-info → promptlayer-1.0.73.dist-info}/METADATA +3 -1
- promptlayer-1.0.73.dist-info/RECORD +23 -0
- promptlayer-1.0.71.dist-info/RECORD +0 -22
- {promptlayer-1.0.71.dist-info → promptlayer-1.0.73.dist-info}/WHEEL +0 -0
- {promptlayer-1.0.71.dist-info → promptlayer-1.0.73.dist-info}/licenses/LICENSE +0 -0
promptlayer/span_exporter.py
CHANGED
|
@@ -4,13 +4,25 @@ import requests
|
|
|
4
4
|
from opentelemetry.sdk.trace import ReadableSpan
|
|
5
5
|
from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
|
|
6
6
|
|
|
7
|
-
from promptlayer.utils import
|
|
7
|
+
from promptlayer.utils import raise_on_bad_response, retry_on_api_error
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class PromptLayerSpanExporter(SpanExporter):
|
|
11
|
-
def __init__(self, api_key: str
|
|
11
|
+
def __init__(self, api_key: str, base_url: str, throw_on_error: bool):
|
|
12
12
|
self.api_key = api_key
|
|
13
|
-
self.url = f"{
|
|
13
|
+
self.url = f"{base_url}/spans-bulk"
|
|
14
|
+
self.throw_on_error = throw_on_error
|
|
15
|
+
|
|
16
|
+
@retry_on_api_error
|
|
17
|
+
def _post_spans(self, request_data):
|
|
18
|
+
response = requests.post(
|
|
19
|
+
self.url,
|
|
20
|
+
headers={"X-Api-Key": self.api_key, "Content-Type": "application/json"},
|
|
21
|
+
json={"spans": request_data},
|
|
22
|
+
)
|
|
23
|
+
if response.status_code not in (200, 201):
|
|
24
|
+
raise_on_bad_response(response, "PromptLayer had the following error while exporting spans")
|
|
25
|
+
return response
|
|
14
26
|
|
|
15
27
|
def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult:
|
|
16
28
|
request_data = []
|
|
@@ -49,12 +61,7 @@ class PromptLayerSpanExporter(SpanExporter):
|
|
|
49
61
|
request_data.append(span_info)
|
|
50
62
|
|
|
51
63
|
try:
|
|
52
|
-
|
|
53
|
-
self.url,
|
|
54
|
-
headers={"X-Api-Key": self.api_key, "Content-Type": "application/json"},
|
|
55
|
-
json={"spans": request_data},
|
|
56
|
-
)
|
|
57
|
-
response.raise_for_status()
|
|
64
|
+
self._post_spans(request_data)
|
|
58
65
|
return SpanExportResult.SUCCESS
|
|
59
66
|
except requests.RequestException:
|
|
60
67
|
return SpanExportResult.FAILURE
|
promptlayer/templates.py
CHANGED
|
@@ -11,25 +11,29 @@ from promptlayer.utils import (
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class TemplateManager:
|
|
14
|
-
def __init__(self, api_key: str):
|
|
14
|
+
def __init__(self, api_key: str, base_url: str, throw_on_error: bool):
|
|
15
15
|
self.api_key = api_key
|
|
16
|
+
self.base_url = base_url
|
|
17
|
+
self.throw_on_error = throw_on_error
|
|
16
18
|
|
|
17
19
|
def get(self, prompt_name: str, params: Union[GetPromptTemplate, None] = None):
|
|
18
|
-
return get_prompt_template(
|
|
20
|
+
return get_prompt_template(self.api_key, self.base_url, self.throw_on_error, prompt_name, params)
|
|
19
21
|
|
|
20
22
|
def publish(self, body: PublishPromptTemplate):
|
|
21
|
-
return publish_prompt_template(
|
|
23
|
+
return publish_prompt_template(self.api_key, self.base_url, self.throw_on_error, body)
|
|
22
24
|
|
|
23
25
|
def all(self, page: int = 1, per_page: int = 30, label: str = None):
|
|
24
|
-
return get_all_prompt_templates(
|
|
26
|
+
return get_all_prompt_templates(self.api_key, self.base_url, self.throw_on_error, page, per_page, label)
|
|
25
27
|
|
|
26
28
|
|
|
27
29
|
class AsyncTemplateManager:
|
|
28
|
-
def __init__(self, api_key: str):
|
|
30
|
+
def __init__(self, api_key: str, base_url: str, throw_on_error: bool):
|
|
29
31
|
self.api_key = api_key
|
|
32
|
+
self.base_url = base_url
|
|
33
|
+
self.throw_on_error = throw_on_error
|
|
30
34
|
|
|
31
35
|
async def get(self, prompt_name: str, params: Union[GetPromptTemplate, None] = None):
|
|
32
|
-
return await aget_prompt_template(
|
|
36
|
+
return await aget_prompt_template(self.api_key, self.base_url, self.throw_on_error, prompt_name, params)
|
|
33
37
|
|
|
34
38
|
async def all(self, page: int = 1, per_page: int = 30, label: str = None):
|
|
35
|
-
return await aget_all_prompt_templates(
|
|
39
|
+
return await aget_all_prompt_templates(self.api_key, self.base_url, self.throw_on_error, page, per_page, label)
|
promptlayer/track/__init__.py
CHANGED
|
@@ -13,51 +13,59 @@ from promptlayer.track.track import (
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
class TrackManager:
|
|
16
|
-
def __init__(self, api_key: str):
|
|
16
|
+
def __init__(self, api_key: str, base_url: str, throw_on_error: bool):
|
|
17
17
|
self.api_key = api_key
|
|
18
|
+
self.base_url = base_url
|
|
19
|
+
self.throw_on_error = throw_on_error
|
|
18
20
|
|
|
19
21
|
def group(self, request_id, group_id):
|
|
20
|
-
return group(
|
|
22
|
+
return group(self.api_key, self.base_url, self.throw_on_error, request_id, group_id)
|
|
21
23
|
|
|
22
24
|
def metadata(self, request_id, metadata):
|
|
23
|
-
return metadata_(
|
|
25
|
+
return metadata_(self.api_key, self.base_url, self.throw_on_error, request_id, metadata)
|
|
24
26
|
|
|
25
27
|
def prompt(self, request_id, prompt_name, prompt_input_variables, version=None, label=None):
|
|
26
28
|
return prompt(
|
|
29
|
+
self.api_key,
|
|
30
|
+
self.base_url,
|
|
31
|
+
self.throw_on_error,
|
|
27
32
|
request_id,
|
|
28
33
|
prompt_name,
|
|
29
34
|
prompt_input_variables,
|
|
30
35
|
version,
|
|
31
36
|
label,
|
|
32
|
-
self.api_key,
|
|
33
37
|
)
|
|
34
38
|
|
|
35
39
|
def score(self, request_id, score, score_name=None):
|
|
36
|
-
return score_(request_id, score, score_name
|
|
40
|
+
return score_(self.api_key, self.base_url, self.throw_on_error, request_id, score, score_name)
|
|
37
41
|
|
|
38
42
|
|
|
39
43
|
class AsyncTrackManager:
|
|
40
|
-
def __init__(self, api_key: str):
|
|
44
|
+
def __init__(self, api_key: str, base_url: str, throw_on_error: bool):
|
|
41
45
|
self.api_key = api_key
|
|
46
|
+
self.base_url = base_url
|
|
47
|
+
self.throw_on_error = throw_on_error
|
|
42
48
|
|
|
43
49
|
async def group(self, request_id, group_id):
|
|
44
|
-
return await agroup(
|
|
50
|
+
return await agroup(self.api_key, self.base_url, self.throw_on_error, request_id, group_id)
|
|
45
51
|
|
|
46
52
|
async def metadata(self, request_id, metadata):
|
|
47
|
-
return await ametadata(
|
|
53
|
+
return await ametadata(self.api_key, self.base_url, self.throw_on_error, request_id, metadata)
|
|
48
54
|
|
|
49
55
|
async def prompt(self, request_id, prompt_name, prompt_input_variables, version=None, label=None):
|
|
50
56
|
return await aprompt(
|
|
57
|
+
self.api_key,
|
|
58
|
+
self.base_url,
|
|
59
|
+
self.throw_on_error,
|
|
51
60
|
request_id,
|
|
52
61
|
prompt_name,
|
|
53
62
|
prompt_input_variables,
|
|
54
63
|
version,
|
|
55
64
|
label,
|
|
56
|
-
self.api_key,
|
|
57
65
|
)
|
|
58
66
|
|
|
59
67
|
async def score(self, request_id, score, score_name=None):
|
|
60
|
-
return await ascore(request_id, score, score_name
|
|
68
|
+
return await ascore(self.api_key, self.base_url, self.throw_on_error, request_id, score, score_name)
|
|
61
69
|
|
|
62
70
|
|
|
63
71
|
__all__ = ["TrackManager"]
|
promptlayer/track/track.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from promptlayer import exceptions as _exceptions
|
|
1
2
|
from promptlayer.utils import (
|
|
2
3
|
apromptlayer_track_group,
|
|
3
4
|
apromptlayer_track_metadata,
|
|
@@ -11,72 +12,96 @@ from promptlayer.utils import (
|
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
def prompt(
|
|
15
|
+
api_key: str,
|
|
16
|
+
base_url: str,
|
|
17
|
+
throw_on_error: bool,
|
|
14
18
|
request_id,
|
|
15
19
|
prompt_name,
|
|
16
20
|
prompt_input_variables,
|
|
17
21
|
version=None,
|
|
18
22
|
label=None,
|
|
19
|
-
api_key: str = None,
|
|
20
23
|
):
|
|
21
24
|
if not isinstance(prompt_input_variables, dict):
|
|
22
|
-
raise
|
|
23
|
-
|
|
25
|
+
raise _exceptions.PromptLayerValidationError(
|
|
26
|
+
"Please provide a dictionary of input variables.", response=None, body=None
|
|
27
|
+
)
|
|
28
|
+
return promptlayer_track_prompt(
|
|
29
|
+
api_key, base_url, throw_on_error, request_id, prompt_name, prompt_input_variables, api_key, version, label
|
|
30
|
+
)
|
|
24
31
|
|
|
25
32
|
|
|
26
|
-
def metadata(
|
|
33
|
+
def metadata(api_key: str, base_url: str, throw_on_error: bool, request_id, metadata):
|
|
27
34
|
if not isinstance(metadata, dict):
|
|
28
|
-
raise
|
|
35
|
+
raise _exceptions.PromptLayerValidationError(
|
|
36
|
+
"Please provide a dictionary of metadata.", response=None, body=None
|
|
37
|
+
)
|
|
29
38
|
for key, value in metadata.items():
|
|
30
39
|
if not isinstance(key, str) or not isinstance(value, str):
|
|
31
|
-
raise
|
|
32
|
-
|
|
40
|
+
raise _exceptions.PromptLayerValidationError(
|
|
41
|
+
"Please provide a dictionary of metadata with key value pair of strings.", response=None, body=None
|
|
42
|
+
)
|
|
43
|
+
return promptlayer_track_metadata(api_key, base_url, throw_on_error, request_id, metadata)
|
|
33
44
|
|
|
34
45
|
|
|
35
|
-
def score(
|
|
46
|
+
def score(api_key: str, base_url: str, throw_on_error: bool, request_id, score, score_name=None):
|
|
36
47
|
if not isinstance(score, int):
|
|
37
|
-
raise
|
|
48
|
+
raise _exceptions.PromptLayerValidationError("Please provide a int score.", response=None, body=None)
|
|
38
49
|
if not isinstance(score_name, str) and score_name is not None:
|
|
39
|
-
raise
|
|
50
|
+
raise _exceptions.PromptLayerValidationError("Please provide a string as score name.", response=None, body=None)
|
|
40
51
|
if score < 0 or score > 100:
|
|
41
|
-
raise
|
|
42
|
-
|
|
52
|
+
raise _exceptions.PromptLayerValidationError(
|
|
53
|
+
"Please provide a score between 0 and 100.", response=None, body=None
|
|
54
|
+
)
|
|
55
|
+
return promptlayer_track_score(api_key, base_url, throw_on_error, request_id, score, score_name)
|
|
43
56
|
|
|
44
57
|
|
|
45
|
-
def group(
|
|
46
|
-
return promptlayer_track_group(request_id, group_id
|
|
58
|
+
def group(api_key: str, base_url: str, throw_on_error: bool, request_id, group_id):
|
|
59
|
+
return promptlayer_track_group(api_key, base_url, throw_on_error, request_id, group_id)
|
|
47
60
|
|
|
48
61
|
|
|
49
62
|
async def aprompt(
|
|
63
|
+
api_key: str,
|
|
64
|
+
base_url: str,
|
|
65
|
+
throw_on_error: bool,
|
|
50
66
|
request_id,
|
|
51
67
|
prompt_name,
|
|
52
68
|
prompt_input_variables,
|
|
53
69
|
version=None,
|
|
54
70
|
label=None,
|
|
55
|
-
api_key: str = None,
|
|
56
71
|
):
|
|
57
72
|
if not isinstance(prompt_input_variables, dict):
|
|
58
|
-
raise
|
|
59
|
-
|
|
73
|
+
raise _exceptions.PromptLayerValidationError(
|
|
74
|
+
"Please provide a dictionary of input variables.", response=None, body=None
|
|
75
|
+
)
|
|
76
|
+
return await apromptlayer_track_prompt(
|
|
77
|
+
api_key, base_url, throw_on_error, request_id, prompt_name, prompt_input_variables, version, label
|
|
78
|
+
)
|
|
60
79
|
|
|
61
80
|
|
|
62
|
-
async def ametadata(
|
|
81
|
+
async def ametadata(api_key: str, base_url: str, throw_on_error: bool, request_id, metadata):
|
|
63
82
|
if not isinstance(metadata, dict):
|
|
64
|
-
raise
|
|
83
|
+
raise _exceptions.PromptLayerValidationError(
|
|
84
|
+
"Please provide a dictionary of metadata.", response=None, body=None
|
|
85
|
+
)
|
|
65
86
|
for key, value in metadata.items():
|
|
66
87
|
if not isinstance(key, str) or not isinstance(value, str):
|
|
67
|
-
raise
|
|
68
|
-
|
|
88
|
+
raise _exceptions.PromptLayerValidationError(
|
|
89
|
+
"Please provide a dictionary of metadata with key-value pairs of strings.", response=None, body=None
|
|
90
|
+
)
|
|
91
|
+
return await apromptlayer_track_metadata(api_key, base_url, throw_on_error, request_id, metadata)
|
|
69
92
|
|
|
70
93
|
|
|
71
|
-
async def ascore(
|
|
94
|
+
async def ascore(api_key: str, base_url: str, throw_on_error: bool, request_id, score, score_name=None):
|
|
72
95
|
if not isinstance(score, int):
|
|
73
|
-
raise
|
|
96
|
+
raise _exceptions.PromptLayerValidationError("Please provide an integer score.", response=None, body=None)
|
|
74
97
|
if not isinstance(score_name, str) and score_name is not None:
|
|
75
|
-
raise
|
|
98
|
+
raise _exceptions.PromptLayerValidationError("Please provide a string as score name.", response=None, body=None)
|
|
76
99
|
if score < 0 or score > 100:
|
|
77
|
-
raise
|
|
78
|
-
|
|
100
|
+
raise _exceptions.PromptLayerValidationError(
|
|
101
|
+
"Please provide a score between 0 and 100.", response=None, body=None
|
|
102
|
+
)
|
|
103
|
+
return await apromptlayer_track_score(api_key, base_url, throw_on_error, request_id, score, score_name)
|
|
79
104
|
|
|
80
105
|
|
|
81
|
-
async def agroup(
|
|
82
|
-
return await apromptlayer_track_group(request_id, group_id
|
|
106
|
+
async def agroup(api_key: str, base_url: str, throw_on_error: bool, request_id, group_id):
|
|
107
|
+
return await apromptlayer_track_group(api_key, base_url, throw_on_error, request_id, group_id)
|