openlit 1.16.0__py3-none-any.whl → 1.17.0__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.
- openlit/instrumentation/anthropic/anthropic.py +30 -12
- openlit/instrumentation/anthropic/async_anthropic.py +29 -12
- openlit/instrumentation/bedrock/__init__.py +3 -3
- openlit/instrumentation/bedrock/bedrock.py +77 -307
- openlit/instrumentation/cohere/cohere.py +35 -14
- openlit/instrumentation/elevenlabs/async_elevenlabs.py +6 -2
- openlit/instrumentation/elevenlabs/elevenlabs.py +6 -2
- openlit/instrumentation/gpt4all/gpt4all.py +30 -10
- openlit/instrumentation/groq/async_groq.py +41 -21
- openlit/instrumentation/groq/groq.py +41 -21
- openlit/instrumentation/mistral/async_mistral.py +37 -16
- openlit/instrumentation/mistral/mistral.py +37 -16
- openlit/instrumentation/ollama/async_ollama.py +57 -20
- openlit/instrumentation/ollama/ollama.py +57 -20
- openlit/instrumentation/openai/async_azure_openai.py +106 -47
- openlit/instrumentation/openai/async_openai.py +78 -37
- openlit/instrumentation/openai/azure_openai.py +101 -43
- openlit/instrumentation/openai/openai.py +78 -39
- openlit/instrumentation/transformers/transformers.py +21 -17
- openlit/instrumentation/vertexai/async_vertexai.py +104 -35
- openlit/instrumentation/vertexai/vertexai.py +104 -35
- openlit/semcov/__init__.py +6 -4
- {openlit-1.16.0.dist-info → openlit-1.17.0.dist-info}/METADATA +2 -2
- {openlit-1.16.0.dist-info → openlit-1.17.0.dist-info}/RECORD +26 -26
- {openlit-1.16.0.dist-info → openlit-1.17.0.dist-info}/LICENSE +0 -0
- {openlit-1.16.0.dist-info → openlit-1.17.0.dist-info}/WHEEL +0 -0
@@ -120,10 +120,18 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
|
|
120
120
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
121
121
|
cost)
|
122
122
|
if trace_content:
|
123
|
-
span.
|
124
|
-
|
125
|
-
|
126
|
-
|
123
|
+
span.add_event(
|
124
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
125
|
+
attributes={
|
126
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
127
|
+
},
|
128
|
+
)
|
129
|
+
span.add_event(
|
130
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
131
|
+
attributes={
|
132
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
|
133
|
+
},
|
134
|
+
)
|
127
135
|
|
128
136
|
span.set_status(Status(StatusCode.OK))
|
129
137
|
|
@@ -198,10 +206,18 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
|
|
198
206
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
199
207
|
False)
|
200
208
|
if trace_content:
|
201
|
-
span.
|
202
|
-
|
203
|
-
|
204
|
-
|
209
|
+
span.add_event(
|
210
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
211
|
+
attributes={
|
212
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
213
|
+
},
|
214
|
+
)
|
215
|
+
span.add_event(
|
216
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
217
|
+
attributes={
|
218
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response['message']['content'],
|
219
|
+
},
|
220
|
+
)
|
205
221
|
|
206
222
|
# Calculate cost of the operation
|
207
223
|
cost = 0
|
@@ -216,7 +232,7 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
|
|
216
232
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
|
217
233
|
total_tokens)
|
218
234
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
219
|
-
response["done_reason"])
|
235
|
+
[response["done_reason"]])
|
220
236
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
221
237
|
cost)
|
222
238
|
|
@@ -345,10 +361,19 @@ def async_generate(gen_ai_endpoint, version, environment, application_name,
|
|
345
361
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
346
362
|
cost)
|
347
363
|
if trace_content:
|
348
|
-
span.
|
349
|
-
|
350
|
-
|
351
|
-
|
364
|
+
span.add_event(
|
365
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
366
|
+
attributes={
|
367
|
+
# pylint: disable=line-too-long
|
368
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),
|
369
|
+
},
|
370
|
+
)
|
371
|
+
span.add_event(
|
372
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
373
|
+
attributes={
|
374
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
|
375
|
+
},
|
376
|
+
)
|
352
377
|
|
353
378
|
span.set_status(Status(StatusCode.OK))
|
354
379
|
|
@@ -404,10 +429,18 @@ def async_generate(gen_ai_endpoint, version, environment, application_name,
|
|
404
429
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
405
430
|
False)
|
406
431
|
if trace_content:
|
407
|
-
span.
|
408
|
-
|
409
|
-
|
410
|
-
|
432
|
+
span.add_event(
|
433
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
434
|
+
attributes={
|
435
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),
|
436
|
+
},
|
437
|
+
)
|
438
|
+
span.add_event(
|
439
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
440
|
+
attributes={
|
441
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response['response'],
|
442
|
+
},
|
443
|
+
)
|
411
444
|
|
412
445
|
# Calculate cost of the operation
|
413
446
|
cost = 0
|
@@ -422,7 +455,7 @@ def async_generate(gen_ai_endpoint, version, environment, application_name,
|
|
422
455
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
|
423
456
|
total_tokens)
|
424
457
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
425
|
-
response["done_reason"])
|
458
|
+
[response["done_reason"]])
|
426
459
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
427
460
|
cost)
|
428
461
|
|
@@ -525,8 +558,12 @@ def async_embeddings(gen_ai_endpoint, version, environment, application_name,
|
|
525
558
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
526
559
|
cost)
|
527
560
|
if trace_content:
|
528
|
-
span.
|
529
|
-
|
561
|
+
span.add_event(
|
562
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
563
|
+
attributes={
|
564
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),
|
565
|
+
},
|
566
|
+
)
|
530
567
|
|
531
568
|
span.set_status(Status(StatusCode.OK))
|
532
569
|
|
@@ -120,10 +120,18 @@ def chat(gen_ai_endpoint, version, environment, application_name,
|
|
120
120
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
121
121
|
cost)
|
122
122
|
if trace_content:
|
123
|
-
span.
|
124
|
-
|
125
|
-
|
126
|
-
|
123
|
+
span.add_event(
|
124
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
125
|
+
attributes={
|
126
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
127
|
+
},
|
128
|
+
)
|
129
|
+
span.add_event(
|
130
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
131
|
+
attributes={
|
132
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
|
133
|
+
},
|
134
|
+
)
|
127
135
|
|
128
136
|
span.set_status(Status(StatusCode.OK))
|
129
137
|
|
@@ -198,10 +206,18 @@ def chat(gen_ai_endpoint, version, environment, application_name,
|
|
198
206
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
199
207
|
False)
|
200
208
|
if trace_content:
|
201
|
-
span.
|
202
|
-
|
203
|
-
|
204
|
-
|
209
|
+
span.add_event(
|
210
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
211
|
+
attributes={
|
212
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
213
|
+
},
|
214
|
+
)
|
215
|
+
span.add_event(
|
216
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
217
|
+
attributes={
|
218
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response['message']['content'],
|
219
|
+
},
|
220
|
+
)
|
205
221
|
|
206
222
|
# Calculate cost of the operation
|
207
223
|
cost = 0
|
@@ -216,7 +232,7 @@ def chat(gen_ai_endpoint, version, environment, application_name,
|
|
216
232
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
|
217
233
|
total_tokens)
|
218
234
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
219
|
-
response["done_reason"])
|
235
|
+
[response["done_reason"]])
|
220
236
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
221
237
|
cost)
|
222
238
|
|
@@ -345,10 +361,19 @@ def generate(gen_ai_endpoint, version, environment, application_name,
|
|
345
361
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
346
362
|
cost)
|
347
363
|
if trace_content:
|
348
|
-
span.
|
349
|
-
|
350
|
-
|
351
|
-
|
364
|
+
span.add_event(
|
365
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
366
|
+
attributes={
|
367
|
+
# pylint: disable=line-too-long
|
368
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),
|
369
|
+
},
|
370
|
+
)
|
371
|
+
span.add_event(
|
372
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
373
|
+
attributes={
|
374
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
|
375
|
+
},
|
376
|
+
)
|
352
377
|
|
353
378
|
span.set_status(Status(StatusCode.OK))
|
354
379
|
|
@@ -404,10 +429,18 @@ def generate(gen_ai_endpoint, version, environment, application_name,
|
|
404
429
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
405
430
|
False)
|
406
431
|
if trace_content:
|
407
|
-
span.
|
408
|
-
|
409
|
-
|
410
|
-
|
432
|
+
span.add_event(
|
433
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
434
|
+
attributes={
|
435
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),
|
436
|
+
},
|
437
|
+
)
|
438
|
+
span.add_event(
|
439
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
440
|
+
attributes={
|
441
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response['response'],
|
442
|
+
},
|
443
|
+
)
|
411
444
|
|
412
445
|
# Calculate cost of the operation
|
413
446
|
cost = 0
|
@@ -422,7 +455,7 @@ def generate(gen_ai_endpoint, version, environment, application_name,
|
|
422
455
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
|
423
456
|
total_tokens)
|
424
457
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
425
|
-
response["done_reason"])
|
458
|
+
[response["done_reason"]])
|
426
459
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
427
460
|
cost)
|
428
461
|
|
@@ -525,8 +558,12 @@ def embeddings(gen_ai_endpoint, version, environment, application_name,
|
|
525
558
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
526
559
|
cost)
|
527
560
|
if trace_content:
|
528
|
-
span.
|
529
|
-
|
561
|
+
span.add_event(
|
562
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
563
|
+
attributes={
|
564
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),
|
565
|
+
},
|
566
|
+
)
|
530
567
|
|
531
568
|
span.set_status(Status(StatusCode.OK))
|
532
569
|
|
@@ -125,11 +125,11 @@ def azure_async_chat_completions(gen_ai_endpoint, version, environment, applicat
|
|
125
125
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOOL_CHOICE,
|
126
126
|
kwargs.get("tool_choice", ""))
|
127
127
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
|
128
|
-
kwargs.get("temperature", 1))
|
128
|
+
kwargs.get("temperature", 1.0))
|
129
129
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_PRESENCE_PENALTY,
|
130
|
-
kwargs.get("presence_penalty", 0))
|
130
|
+
kwargs.get("presence_penalty", 0.0))
|
131
131
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,
|
132
|
-
kwargs.get("frequency_penalty", 0))
|
132
|
+
kwargs.get("frequency_penalty", 0.0))
|
133
133
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
|
134
134
|
kwargs.get("seed", ""))
|
135
135
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
@@ -143,10 +143,18 @@ def azure_async_chat_completions(gen_ai_endpoint, version, environment, applicat
|
|
143
143
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
144
144
|
cost)
|
145
145
|
if trace_content:
|
146
|
-
span.
|
147
|
-
|
148
|
-
|
149
|
-
|
146
|
+
span.add_event(
|
147
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
148
|
+
attributes={
|
149
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
150
|
+
},
|
151
|
+
)
|
152
|
+
span.add_event(
|
153
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
154
|
+
attributes={
|
155
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
|
156
|
+
},
|
157
|
+
)
|
150
158
|
|
151
159
|
span.set_status(Status(StatusCode.OK))
|
152
160
|
|
@@ -228,18 +236,22 @@ def azure_async_chat_completions(gen_ai_endpoint, version, environment, applicat
|
|
228
236
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOOL_CHOICE,
|
229
237
|
kwargs.get("tool_choice", ""))
|
230
238
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
|
231
|
-
kwargs.get("temperature", 1))
|
239
|
+
kwargs.get("temperature", 1.0))
|
232
240
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_PRESENCE_PENALTY,
|
233
|
-
kwargs.get("presence_penalty", 0))
|
241
|
+
kwargs.get("presence_penalty", 0.0))
|
234
242
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,
|
235
|
-
kwargs.get("frequency_penalty", 0))
|
243
|
+
kwargs.get("frequency_penalty", 0.0))
|
236
244
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
|
237
245
|
kwargs.get("seed", ""))
|
238
246
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
239
247
|
False)
|
240
248
|
if trace_content:
|
241
|
-
span.
|
242
|
-
|
249
|
+
span.add_event(
|
250
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
251
|
+
attributes={
|
252
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
253
|
+
},
|
254
|
+
)
|
243
255
|
|
244
256
|
# Set span attributes when tools is not passed to the function call
|
245
257
|
if "tools" not in kwargs:
|
@@ -255,23 +267,31 @@ def azure_async_chat_completions(gen_ai_endpoint, version, environment, applicat
|
|
255
267
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
|
256
268
|
response.usage.total_tokens)
|
257
269
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
258
|
-
response.choices[0].finish_reason)
|
270
|
+
[response.choices[0].finish_reason])
|
259
271
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
260
272
|
cost)
|
261
273
|
|
262
274
|
# Set span attributes for when n = 1 (default)
|
263
275
|
if "n" not in kwargs or kwargs["n"] == 1:
|
264
276
|
if trace_content:
|
265
|
-
span.
|
266
|
-
|
277
|
+
span.add_event(
|
278
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
279
|
+
attributes={
|
280
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].message.content,
|
281
|
+
},
|
282
|
+
)
|
267
283
|
|
268
284
|
# Set span attributes for when n > 0
|
269
285
|
else:
|
270
286
|
i = 0
|
271
287
|
while i < kwargs["n"] and trace_content is True:
|
272
|
-
attribute_name = f"gen_ai.completion.{i}"
|
273
|
-
span.
|
274
|
-
|
288
|
+
attribute_name = f"gen_ai.content.completion.{i}"
|
289
|
+
span.add_event(
|
290
|
+
name=attribute_name,
|
291
|
+
attributes={
|
292
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[i].message.content,
|
293
|
+
},
|
294
|
+
)
|
275
295
|
i += 1
|
276
296
|
|
277
297
|
# Return original response
|
@@ -284,8 +304,12 @@ def azure_async_chat_completions(gen_ai_endpoint, version, environment, applicat
|
|
284
304
|
response.usage.prompt_tokens,
|
285
305
|
response.usage.completion_tokens)
|
286
306
|
|
287
|
-
span.
|
288
|
-
|
307
|
+
span.add_event(
|
308
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
309
|
+
attributes={
|
310
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: "Function called with tools",
|
311
|
+
},
|
312
|
+
)
|
289
313
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
|
290
314
|
response.usage.prompt_tokens)
|
291
315
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
|
@@ -425,11 +449,11 @@ def azure_async_completions(gen_ai_endpoint, version, environment, application_n
|
|
425
449
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOOL_CHOICE,
|
426
450
|
kwargs.get("tool_choice", ""))
|
427
451
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
|
428
|
-
kwargs.get("temperature", 1))
|
452
|
+
kwargs.get("temperature", 1.0))
|
429
453
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_PRESENCE_PENALTY,
|
430
|
-
kwargs.get("presence_penalty", 0))
|
454
|
+
kwargs.get("presence_penalty", 0.0))
|
431
455
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,
|
432
|
-
kwargs.get("frequency_penalty", 0))
|
456
|
+
kwargs.get("frequency_penalty", 0.0))
|
433
457
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
|
434
458
|
kwargs.get("seed", ""))
|
435
459
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
@@ -443,10 +467,18 @@ def azure_async_completions(gen_ai_endpoint, version, environment, application_n
|
|
443
467
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
444
468
|
cost)
|
445
469
|
if trace_content:
|
446
|
-
span.
|
447
|
-
|
448
|
-
|
449
|
-
|
470
|
+
span.add_event(
|
471
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
472
|
+
attributes={
|
473
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
474
|
+
},
|
475
|
+
)
|
476
|
+
span.add_event(
|
477
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
478
|
+
attributes={
|
479
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
|
480
|
+
},
|
481
|
+
)
|
450
482
|
|
451
483
|
span.set_status(Status(StatusCode.OK))
|
452
484
|
|
@@ -509,18 +541,22 @@ def azure_async_completions(gen_ai_endpoint, version, environment, application_n
|
|
509
541
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOOL_CHOICE,
|
510
542
|
kwargs.get("tool_choice", ""))
|
511
543
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
|
512
|
-
kwargs.get("temperature", 1))
|
544
|
+
kwargs.get("temperature", 1.0))
|
513
545
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_PRESENCE_PENALTY,
|
514
|
-
kwargs.get("presence_penalty", 0))
|
546
|
+
kwargs.get("presence_penalty", 0.0))
|
515
547
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,
|
516
|
-
kwargs.get("frequency_penalty", 0))
|
548
|
+
kwargs.get("frequency_penalty", 0.0))
|
517
549
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
|
518
550
|
kwargs.get("seed", ""))
|
519
551
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
520
552
|
False)
|
521
553
|
if trace_content:
|
522
|
-
span.
|
523
|
-
|
554
|
+
span.add_event(
|
555
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
556
|
+
attributes={
|
557
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),
|
558
|
+
},
|
559
|
+
)
|
524
560
|
|
525
561
|
# Set span attributes when tools is not passed to the function call
|
526
562
|
if "tools" not in kwargs:
|
@@ -536,23 +572,31 @@ def azure_async_completions(gen_ai_endpoint, version, environment, application_n
|
|
536
572
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
|
537
573
|
response.usage.total_tokens)
|
538
574
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
539
|
-
response.choices[0].finish_reason)
|
575
|
+
[response.choices[0].finish_reason])
|
540
576
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
541
577
|
cost)
|
542
578
|
|
543
579
|
# Set span attributes for when n = 1 (default)
|
544
580
|
if "n" not in kwargs or kwargs["n"] == 1:
|
545
581
|
if trace_content:
|
546
|
-
span.
|
547
|
-
|
582
|
+
span.add_event(
|
583
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
584
|
+
attributes={
|
585
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].text,
|
586
|
+
},
|
587
|
+
)
|
548
588
|
|
549
589
|
# Set span attributes for when n > 0
|
550
590
|
else:
|
551
591
|
i = 0
|
552
592
|
while i < kwargs["n"] and trace_content is True:
|
553
|
-
attribute_name = f"gen_ai.completion.{i}"
|
554
|
-
span.
|
555
|
-
|
593
|
+
attribute_name = f"gen_ai.content.completion.{i}"
|
594
|
+
span.add_event(
|
595
|
+
name=attribute_name,
|
596
|
+
attributes={
|
597
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[i].text,
|
598
|
+
},
|
599
|
+
)
|
556
600
|
i += 1
|
557
601
|
return response
|
558
602
|
|
@@ -563,8 +607,12 @@ def azure_async_completions(gen_ai_endpoint, version, environment, application_n
|
|
563
607
|
response.usage.prompt_tokens,
|
564
608
|
response.usage.completion_tokens)
|
565
609
|
|
566
|
-
span.
|
567
|
-
|
610
|
+
span.add_event(
|
611
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
612
|
+
attributes={
|
613
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: "Function called with tools",
|
614
|
+
},
|
615
|
+
)
|
568
616
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
|
569
617
|
response.usage.prompt_tokens)
|
570
618
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
|
@@ -679,8 +727,12 @@ def azure_async_embedding(gen_ai_endpoint, version, environment, application_nam
|
|
679
727
|
response.usage.total_tokens)
|
680
728
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST, cost)
|
681
729
|
if trace_content:
|
682
|
-
span.
|
683
|
-
|
730
|
+
span.add_event(
|
731
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
732
|
+
attributes={
|
733
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("input", ""),
|
734
|
+
},
|
735
|
+
)
|
684
736
|
|
685
737
|
span.set_status(Status(StatusCode.OK))
|
686
738
|
|
@@ -796,12 +848,19 @@ def azure_async_image_generate(gen_ai_endpoint, version, environment, applicatio
|
|
796
848
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,
|
797
849
|
kwargs.get("user", ""))
|
798
850
|
if trace_content:
|
799
|
-
span.
|
800
|
-
|
801
|
-
|
851
|
+
span.add_event(
|
852
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
853
|
+
attributes={
|
854
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("prompt", ""),
|
855
|
+
},
|
856
|
+
)
|
802
857
|
attribute_name = f"gen_ai.response.image.{images_count}"
|
803
|
-
span.
|
804
|
-
|
858
|
+
span.add_event(
|
859
|
+
name=attribute_name,
|
860
|
+
attributes={
|
861
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: getattr(items, image),
|
862
|
+
},
|
863
|
+
)
|
805
864
|
|
806
865
|
images_count+=1
|
807
866
|
|