promptlayer 1.0.12__tar.gz → 1.0.14__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.
Potentially problematic release.
This version of promptlayer might be problematic. Click here for more details.
- {promptlayer-1.0.12 → promptlayer-1.0.14}/PKG-INFO +1 -1
- {promptlayer-1.0.12 → promptlayer-1.0.14}/promptlayer/__init__.py +1 -1
- {promptlayer-1.0.12 → promptlayer-1.0.14}/promptlayer/promptlayer.py +27 -10
- {promptlayer-1.0.12 → promptlayer-1.0.14}/promptlayer/span_exporter.py +4 -3
- {promptlayer-1.0.12 → promptlayer-1.0.14}/pyproject.toml +1 -1
- {promptlayer-1.0.12 → promptlayer-1.0.14}/LICENSE +0 -0
- {promptlayer-1.0.12 → promptlayer-1.0.14}/README.md +0 -0
- {promptlayer-1.0.12 → promptlayer-1.0.14}/promptlayer/groups/__init__.py +0 -0
- {promptlayer-1.0.12 → promptlayer-1.0.14}/promptlayer/groups/groups.py +0 -0
- {promptlayer-1.0.12 → promptlayer-1.0.14}/promptlayer/promptlayer_base.py +0 -0
- {promptlayer-1.0.12 → promptlayer-1.0.14}/promptlayer/templates.py +0 -0
- {promptlayer-1.0.12 → promptlayer-1.0.14}/promptlayer/track/__init__.py +0 -0
- {promptlayer-1.0.12 → promptlayer-1.0.14}/promptlayer/track/track.py +0 -0
- {promptlayer-1.0.12 → promptlayer-1.0.14}/promptlayer/types/__init__.py +0 -0
- {promptlayer-1.0.12 → promptlayer-1.0.14}/promptlayer/types/prompt_template.py +0 -0
- {promptlayer-1.0.12 → promptlayer-1.0.14}/promptlayer/utils.py +0 -0
|
@@ -57,18 +57,30 @@ MAP_PROVIDER_TO_FUNCTION = {
|
|
|
57
57
|
|
|
58
58
|
|
|
59
59
|
class PromptLayer:
|
|
60
|
-
def __init__(
|
|
60
|
+
def __init__(
|
|
61
|
+
self,
|
|
62
|
+
api_key: str = None,
|
|
63
|
+
enable_tracing: bool = False,
|
|
64
|
+
workspace_id: int = None,
|
|
65
|
+
):
|
|
61
66
|
if api_key is None:
|
|
62
67
|
api_key = os.environ.get("PROMPTLAYER_API_KEY")
|
|
68
|
+
|
|
63
69
|
if api_key is None:
|
|
64
70
|
raise ValueError(
|
|
65
|
-
"PromptLayer API key not provided.
|
|
71
|
+
"PromptLayer API key not provided. "
|
|
72
|
+
"Please set the PROMPTLAYER_API_KEY environment variable or pass the api_key parameter."
|
|
66
73
|
)
|
|
74
|
+
|
|
75
|
+
if enable_tracing and not workspace_id:
|
|
76
|
+
raise ValueError("Please set a workspace_id to enable tracing.")
|
|
77
|
+
|
|
67
78
|
self.api_key = api_key
|
|
68
79
|
self.templates = TemplateManager(api_key)
|
|
69
80
|
self.group = GroupManager(api_key)
|
|
81
|
+
self.tracer = self._initialize_tracer(api_key, enable_tracing, workspace_id)
|
|
70
82
|
self.track = TrackManager(api_key)
|
|
71
|
-
self.
|
|
83
|
+
self.workspace_id = workspace_id
|
|
72
84
|
|
|
73
85
|
def __getattr__(
|
|
74
86
|
self,
|
|
@@ -127,13 +139,18 @@ class PromptLayer:
|
|
|
127
139
|
return result
|
|
128
140
|
return self.templates.get(prompt_name, template_params)
|
|
129
141
|
|
|
130
|
-
|
|
142
|
+
@staticmethod
|
|
143
|
+
def _initialize_tracer(
|
|
144
|
+
api_key: str = None, enable_tracing: bool = False, workspace_id: int = None
|
|
145
|
+
):
|
|
131
146
|
if enable_tracing:
|
|
132
147
|
resource = Resource(
|
|
133
148
|
attributes={ResourceAttributes.SERVICE_NAME: "prompt-layer-library"}
|
|
134
149
|
)
|
|
135
150
|
tracer_provider = TracerProvider(resource=resource)
|
|
136
|
-
promptlayer_exporter = PromptLayerSpanExporter(
|
|
151
|
+
promptlayer_exporter = PromptLayerSpanExporter(
|
|
152
|
+
api_key=api_key, workspace_id=workspace_id
|
|
153
|
+
)
|
|
137
154
|
span_processor = BatchSpanProcessor(promptlayer_exporter)
|
|
138
155
|
tracer_provider.add_span_processor(span_processor)
|
|
139
156
|
trace.set_tracer_provider(tracer_provider)
|
|
@@ -357,14 +374,14 @@ class PromptLayer:
|
|
|
357
374
|
else:
|
|
358
375
|
return self._run_internal(**_run_internal_kwargs)
|
|
359
376
|
|
|
360
|
-
def traceable(self,
|
|
377
|
+
def traceable(self, attributes=None):
|
|
361
378
|
def decorator(func):
|
|
362
379
|
@wraps(func)
|
|
363
380
|
def sync_wrapper(*args, **kwargs):
|
|
364
381
|
if self.tracer:
|
|
365
382
|
with self.tracer.start_as_current_span(func.__name__) as span:
|
|
366
|
-
if
|
|
367
|
-
for key, value in
|
|
383
|
+
if attributes:
|
|
384
|
+
for key, value in attributes.items():
|
|
368
385
|
span.set_attribute(key, value)
|
|
369
386
|
|
|
370
387
|
span.set_attribute(
|
|
@@ -381,8 +398,8 @@ class PromptLayer:
|
|
|
381
398
|
async def async_wrapper(*args, **kwargs):
|
|
382
399
|
if self.tracer:
|
|
383
400
|
with self.tracer.start_as_current_span(func.__name__) as span:
|
|
384
|
-
if
|
|
385
|
-
for key, value in
|
|
401
|
+
if attributes:
|
|
402
|
+
for key, value in attributes.items():
|
|
386
403
|
span.set_attribute(key, value)
|
|
387
404
|
|
|
388
405
|
span.set_attribute(
|
|
@@ -8,9 +8,10 @@ from promptlayer.utils import URL_API_PROMPTLAYER
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class PromptLayerSpanExporter(SpanExporter):
|
|
11
|
-
def __init__(self, api_key=None):
|
|
12
|
-
self.url = f"{URL_API_PROMPTLAYER}/spans-bulk"
|
|
11
|
+
def __init__(self, api_key: str = None, workspace_id: int = None):
|
|
13
12
|
self.api_key = api_key
|
|
13
|
+
self.url = f"{URL_API_PROMPTLAYER}/spans-bulk"
|
|
14
|
+
self.workspace_id = workspace_id
|
|
14
15
|
|
|
15
16
|
def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult:
|
|
16
17
|
request_data = []
|
|
@@ -64,7 +65,7 @@ class PromptLayerSpanExporter(SpanExporter):
|
|
|
64
65
|
},
|
|
65
66
|
json={
|
|
66
67
|
"spans": request_data,
|
|
67
|
-
"workspace_id":
|
|
68
|
+
"workspace_id": self.workspace_id,
|
|
68
69
|
},
|
|
69
70
|
)
|
|
70
71
|
response.raise_for_status()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|