promptlayer 1.0.15__py3-none-any.whl → 1.0.16__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.
- promptlayer/__init__.py +1 -1
- promptlayer/promptlayer.py +53 -63
- {promptlayer-1.0.15.dist-info → promptlayer-1.0.16.dist-info}/METADATA +1 -1
- {promptlayer-1.0.15.dist-info → promptlayer-1.0.16.dist-info}/RECORD +6 -6
- {promptlayer-1.0.15.dist-info → promptlayer-1.0.16.dist-info}/LICENSE +0 -0
- {promptlayer-1.0.15.dist-info → promptlayer-1.0.16.dist-info}/WHEEL +0 -0
promptlayer/__init__.py
CHANGED
promptlayer/promptlayer.py
CHANGED
|
@@ -106,34 +106,22 @@ class PromptLayer:
|
|
|
106
106
|
raise AttributeError(f"module {__name__} has no attribute {name}")
|
|
107
107
|
|
|
108
108
|
def _create_track_request_callable(
|
|
109
|
-
self,
|
|
109
|
+
self,
|
|
110
|
+
*,
|
|
111
|
+
request_params,
|
|
112
|
+
tags,
|
|
113
|
+
input_variables,
|
|
114
|
+
group_id,
|
|
115
|
+
pl_run_span_id: str | None = None,
|
|
110
116
|
):
|
|
111
117
|
def _track_request(**body):
|
|
112
118
|
track_request_kwargs = self._prepare_track_request_kwargs(
|
|
113
|
-
request_params, tags, input_variables, group_id,
|
|
119
|
+
request_params, tags, input_variables, group_id, pl_run_span_id, **body
|
|
114
120
|
)
|
|
115
|
-
if self.tracer:
|
|
116
|
-
with self.tracer.start_as_current_span("track_request"):
|
|
117
|
-
return track_request(**track_request_kwargs)
|
|
118
121
|
return track_request(**track_request_kwargs)
|
|
119
122
|
|
|
120
123
|
return _track_request
|
|
121
124
|
|
|
122
|
-
def _fetch_prompt_blueprint(self, *, prompt_name, template_params):
|
|
123
|
-
if self.tracer:
|
|
124
|
-
with self.tracer.start_as_current_span("fetch_prompt_template") as span:
|
|
125
|
-
span.set_attribute("prompt_name", prompt_name)
|
|
126
|
-
span.set_attribute(
|
|
127
|
-
"function_input",
|
|
128
|
-
str(
|
|
129
|
-
{"prompt_name": prompt_name, "template_params": template_params}
|
|
130
|
-
),
|
|
131
|
-
)
|
|
132
|
-
result = self.templates.get(prompt_name, template_params)
|
|
133
|
-
span.set_attribute("function_output", str(result))
|
|
134
|
-
return result
|
|
135
|
-
return self.templates.get(prompt_name, template_params)
|
|
136
|
-
|
|
137
125
|
@staticmethod
|
|
138
126
|
def _initialize_tracer(api_key: str = None, enable_tracing: bool = False):
|
|
139
127
|
if enable_tracing:
|
|
@@ -149,26 +137,6 @@ class PromptLayer:
|
|
|
149
137
|
else:
|
|
150
138
|
return None
|
|
151
139
|
|
|
152
|
-
def _make_llm_request(self, request_params):
|
|
153
|
-
span_id = None
|
|
154
|
-
|
|
155
|
-
if self.tracer:
|
|
156
|
-
with self.tracer.start_as_current_span("llm_request") as span:
|
|
157
|
-
span.set_attribute("provider", request_params["provider"])
|
|
158
|
-
span.set_attribute("function_name", request_params["function_name"])
|
|
159
|
-
span.set_attribute("function_input", str(request_params))
|
|
160
|
-
span_id = hex(span.context.span_id)[2:].zfill(16)
|
|
161
|
-
response = request_params["request_function"](
|
|
162
|
-
request_params["prompt_blueprint"], **request_params["kwargs"]
|
|
163
|
-
)
|
|
164
|
-
span.set_attribute("function_output", str(response))
|
|
165
|
-
else:
|
|
166
|
-
response = request_params["request_function"](
|
|
167
|
-
request_params["prompt_blueprint"], **request_params["kwargs"]
|
|
168
|
-
)
|
|
169
|
-
|
|
170
|
-
return response, span_id
|
|
171
|
-
|
|
172
140
|
@staticmethod
|
|
173
141
|
def _prepare_get_prompt_template_params(
|
|
174
142
|
*, prompt_version, prompt_release_label, input_variables, metadata
|
|
@@ -211,7 +179,14 @@ class PromptLayer:
|
|
|
211
179
|
}
|
|
212
180
|
|
|
213
181
|
def _prepare_track_request_kwargs(
|
|
214
|
-
self,
|
|
182
|
+
self,
|
|
183
|
+
request_params,
|
|
184
|
+
tags,
|
|
185
|
+
input_variables,
|
|
186
|
+
group_id,
|
|
187
|
+
pl_run_span_id: str | None = None,
|
|
188
|
+
metadata: Dict[str, str] | None = None,
|
|
189
|
+
**body,
|
|
215
190
|
):
|
|
216
191
|
return {
|
|
217
192
|
"function_name": request_params["function_name"],
|
|
@@ -226,13 +201,13 @@ class PromptLayer:
|
|
|
226
201
|
datetime.timezone.utc
|
|
227
202
|
).timestamp(),
|
|
228
203
|
"api_key": self.api_key,
|
|
229
|
-
"metadata":
|
|
204
|
+
"metadata": metadata,
|
|
230
205
|
"prompt_id": request_params["prompt_blueprint"]["id"],
|
|
231
206
|
"prompt_version": request_params["prompt_blueprint"]["version"],
|
|
232
207
|
"prompt_input_variables": input_variables,
|
|
233
208
|
"group_id": group_id,
|
|
234
209
|
"return_prompt_blueprint": True,
|
|
235
|
-
"span_id":
|
|
210
|
+
"span_id": pl_run_span_id,
|
|
236
211
|
**body,
|
|
237
212
|
}
|
|
238
213
|
|
|
@@ -247,6 +222,7 @@ class PromptLayer:
|
|
|
247
222
|
metadata: Union[Dict[str, str], None] = None,
|
|
248
223
|
group_id: Union[int, None] = None,
|
|
249
224
|
stream: bool = False,
|
|
225
|
+
pl_run_span_id: str | None = None,
|
|
250
226
|
) -> Dict[str, Any]:
|
|
251
227
|
get_prompt_template_params = self._prepare_get_prompt_template_params(
|
|
252
228
|
prompt_version=prompt_version,
|
|
@@ -254,9 +230,7 @@ class PromptLayer:
|
|
|
254
230
|
input_variables=input_variables,
|
|
255
231
|
metadata=metadata,
|
|
256
232
|
)
|
|
257
|
-
prompt_blueprint = self.
|
|
258
|
-
prompt_name=prompt_name, template_params=get_prompt_template_params
|
|
259
|
-
)
|
|
233
|
+
prompt_blueprint = self.templates.get(prompt_name, get_prompt_template_params)
|
|
260
234
|
prompt_blueprint_model = self._validate_and_extract_model_from_prompt_blueprint(
|
|
261
235
|
prompt_blueprint=prompt_blueprint, prompt_name=prompt_name
|
|
262
236
|
)
|
|
@@ -267,13 +241,19 @@ class PromptLayer:
|
|
|
267
241
|
stream=stream,
|
|
268
242
|
)
|
|
269
243
|
|
|
270
|
-
response
|
|
244
|
+
response = llm_request_params["request_function"](
|
|
245
|
+
llm_request_params["prompt_blueprint"], **llm_request_params["kwargs"]
|
|
246
|
+
)
|
|
271
247
|
|
|
272
248
|
if stream:
|
|
273
249
|
return stream_response(
|
|
274
250
|
response,
|
|
275
251
|
self._create_track_request_callable(
|
|
276
|
-
llm_request_params,
|
|
252
|
+
request_params=llm_request_params,
|
|
253
|
+
tags=tags,
|
|
254
|
+
input_variables=input_variables,
|
|
255
|
+
group_id=group_id,
|
|
256
|
+
pl_run_span_id=pl_run_span_id,
|
|
277
257
|
),
|
|
278
258
|
llm_request_params["stream_function"],
|
|
279
259
|
)
|
|
@@ -283,7 +263,8 @@ class PromptLayer:
|
|
|
283
263
|
tags,
|
|
284
264
|
input_variables,
|
|
285
265
|
group_id,
|
|
286
|
-
|
|
266
|
+
pl_run_span_id,
|
|
267
|
+
metadata=metadata,
|
|
287
268
|
request_response=response.model_dump(),
|
|
288
269
|
)
|
|
289
270
|
|
|
@@ -294,17 +275,24 @@ class PromptLayer:
|
|
|
294
275
|
}
|
|
295
276
|
|
|
296
277
|
def _track_request_log(
|
|
297
|
-
self,
|
|
278
|
+
self,
|
|
279
|
+
request_params,
|
|
280
|
+
tags,
|
|
281
|
+
input_variables,
|
|
282
|
+
group_id,
|
|
283
|
+
pl_run_span_id: str | None = None,
|
|
284
|
+
metadata: Dict[str, str] | None = None,
|
|
285
|
+
**body,
|
|
298
286
|
):
|
|
299
287
|
track_request_kwargs = self._prepare_track_request_kwargs(
|
|
300
|
-
request_params,
|
|
288
|
+
request_params,
|
|
289
|
+
tags,
|
|
290
|
+
input_variables,
|
|
291
|
+
group_id,
|
|
292
|
+
pl_run_span_id,
|
|
293
|
+
metadata=metadata,
|
|
294
|
+
**body,
|
|
301
295
|
)
|
|
302
|
-
if self.tracer:
|
|
303
|
-
with self.tracer.start_as_current_span("track_request") as span:
|
|
304
|
-
span.set_attribute("function_input", str(track_request_kwargs))
|
|
305
|
-
result = track_request(**track_request_kwargs)
|
|
306
|
-
span.set_attribute("function_output", str(result))
|
|
307
|
-
return result
|
|
308
296
|
return track_request(**track_request_kwargs)
|
|
309
297
|
|
|
310
298
|
@staticmethod
|
|
@@ -355,12 +343,14 @@ class PromptLayer:
|
|
|
355
343
|
}
|
|
356
344
|
|
|
357
345
|
if self.tracer:
|
|
358
|
-
with self.tracer.start_as_current_span("PromptLayer
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
result = self._run_internal(
|
|
363
|
-
|
|
346
|
+
with self.tracer.start_as_current_span("PromptLayer Run") as span:
|
|
347
|
+
span.set_attribute("prompt_name", prompt_name)
|
|
348
|
+
span.set_attribute("function_input", str(_run_internal_kwargs))
|
|
349
|
+
pl_run_span_id = hex(span.context.span_id)[2:].zfill(16)
|
|
350
|
+
result = self._run_internal(
|
|
351
|
+
**_run_internal_kwargs, pl_run_span_id=pl_run_span_id
|
|
352
|
+
)
|
|
353
|
+
span.set_attribute("function_output", str(result))
|
|
364
354
|
return result
|
|
365
355
|
else:
|
|
366
356
|
return self._run_internal(**_run_internal_kwargs)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
promptlayer/__init__.py,sha256=
|
|
1
|
+
promptlayer/__init__.py,sha256=NPhgcyisSfks_AFSRjhlScwwHQRlZSKiPBJS-Lm_grg,102
|
|
2
2
|
promptlayer/groups/__init__.py,sha256=-xs-2cn0nc0D_5YxZr3nC86iTdRVZmBhEpOKDJXE-sQ,224
|
|
3
3
|
promptlayer/groups/groups.py,sha256=yeO6T0TM3qB0ondZRiHhcH8G06YygrpFoM8b9RmoIao,165
|
|
4
|
-
promptlayer/promptlayer.py,sha256=
|
|
4
|
+
promptlayer/promptlayer.py,sha256=xqnwYO5p2JPA_mQbP-5l9yQlQ1bKrfms803CrJBSiFA,13824
|
|
5
5
|
promptlayer/promptlayer_base.py,sha256=sev-EZehRXJSZSmJtMkqmAUK1345pqbDY_lNjPP5MYA,7158
|
|
6
6
|
promptlayer/span_exporter.py,sha256=zIJNsb3Fe6yb5wKLDmkoPF2wqFjk1p39E0jWHD2plzI,2658
|
|
7
7
|
promptlayer/templates.py,sha256=aY_-BCrL0AgIdYEUE28pi0AP_avTVAgwv5hgzrh75vo,717
|
|
@@ -10,7 +10,7 @@ promptlayer/track/track.py,sha256=XNEZT9yNiRBPp9vaDZo_f0dP_ldOu8q1qafpVfS5Ze8,16
|
|
|
10
10
|
promptlayer/types/__init__.py,sha256=ulWSyCrk5hZ_PI-nKGpd6GPcRaK8lqP4wFl0LPNUYWk,61
|
|
11
11
|
promptlayer/types/prompt_template.py,sha256=QbxYSeIubrwp8KmDKdt9syAwzONFPh_So9yr4H73ANQ,4429
|
|
12
12
|
promptlayer/utils.py,sha256=-p0qapUvkZYJd_Dfat3c8LANXWU1JN0bJB91IyjB8iA,29656
|
|
13
|
-
promptlayer-1.0.
|
|
14
|
-
promptlayer-1.0.
|
|
15
|
-
promptlayer-1.0.
|
|
16
|
-
promptlayer-1.0.
|
|
13
|
+
promptlayer-1.0.16.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
14
|
+
promptlayer-1.0.16.dist-info/METADATA,sha256=HpWQPpYbuABRRj4feBBLYpZvviPcIe25q5S0fBKlzR8,4609
|
|
15
|
+
promptlayer-1.0.16.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
16
|
+
promptlayer-1.0.16.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|