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
@@ -89,8 +89,12 @@ def embed(gen_ai_endpoint, version, environment, application_name, tracer,
|
|
89
89
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
90
90
|
cost)
|
91
91
|
if trace_content:
|
92
|
-
span.
|
93
|
-
|
92
|
+
span.add_event(
|
93
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
94
|
+
attributes={
|
95
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
96
|
+
},
|
97
|
+
)
|
94
98
|
|
95
99
|
span.set_status(Status(StatusCode.OK))
|
96
100
|
|
@@ -193,7 +197,7 @@ def chat(gen_ai_endpoint, version, environment, application_name, tracer,
|
|
193
197
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
|
194
198
|
kwargs.get("temperature", 0.3))
|
195
199
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
|
196
|
-
kwargs.get("max_tokens",
|
200
|
+
kwargs.get("max_tokens", -1))
|
197
201
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
|
198
202
|
kwargs.get("seed", ""))
|
199
203
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,
|
@@ -205,7 +209,7 @@ def chat(gen_ai_endpoint, version, environment, application_name, tracer,
|
|
205
209
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
|
206
210
|
response.generation_id)
|
207
211
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
208
|
-
response.finish_reason)
|
212
|
+
[response.finish_reason])
|
209
213
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
|
210
214
|
response.meta.billed_units.input_tokens)
|
211
215
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
|
@@ -215,11 +219,20 @@ def chat(gen_ai_endpoint, version, environment, application_name, tracer,
|
|
215
219
|
response.meta.billed_units.output_tokens)
|
216
220
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
217
221
|
cost)
|
222
|
+
|
218
223
|
if trace_content:
|
219
|
-
span.
|
220
|
-
|
221
|
-
|
222
|
-
|
224
|
+
span.add_event(
|
225
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
226
|
+
attributes={
|
227
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("message", ""),
|
228
|
+
},
|
229
|
+
)
|
230
|
+
span.add_event(
|
231
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
232
|
+
attributes={
|
233
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.text,
|
234
|
+
},
|
235
|
+
)
|
223
236
|
|
224
237
|
span.set_status(Status(StatusCode.OK))
|
225
238
|
|
@@ -336,7 +349,7 @@ def chat_stream(gen_ai_endpoint, version, environment, application_name,
|
|
336
349
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
|
337
350
|
kwargs.get("temperature", 0.3))
|
338
351
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
|
339
|
-
kwargs.get("max_tokens",
|
352
|
+
kwargs.get("max_tokens", -1))
|
340
353
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
|
341
354
|
kwargs.get("seed", ""))
|
342
355
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,
|
@@ -348,7 +361,7 @@ def chat_stream(gen_ai_endpoint, version, environment, application_name,
|
|
348
361
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_ID,
|
349
362
|
response_id)
|
350
363
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
351
|
-
finish_reason)
|
364
|
+
[finish_reason])
|
352
365
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
|
353
366
|
prompt_tokens)
|
354
367
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
|
@@ -358,10 +371,18 @@ def chat_stream(gen_ai_endpoint, version, environment, application_name,
|
|
358
371
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
359
372
|
cost)
|
360
373
|
if trace_content:
|
361
|
-
span.
|
362
|
-
|
363
|
-
|
364
|
-
|
374
|
+
span.add_event(
|
375
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
376
|
+
attributes={
|
377
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: kwargs.get("message", ""),
|
378
|
+
},
|
379
|
+
)
|
380
|
+
span.add_event(
|
381
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
382
|
+
attributes={
|
383
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
|
384
|
+
},
|
385
|
+
)
|
365
386
|
|
366
387
|
span.set_status(Status(StatusCode.OK))
|
367
388
|
|
@@ -80,8 +80,12 @@ def async_generate(gen_ai_endpoint, version, environment, application_name,
|
|
80
80
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
81
81
|
cost)
|
82
82
|
if trace_content:
|
83
|
-
span.
|
84
|
-
|
83
|
+
span.add_event(
|
84
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
85
|
+
attributes={
|
86
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: str(kwargs.get("text", "")),
|
87
|
+
},
|
88
|
+
)
|
85
89
|
|
86
90
|
span.set_status(Status(StatusCode.OK))
|
87
91
|
|
@@ -86,8 +86,12 @@ def generate(gen_ai_endpoint, version, environment, application_name,
|
|
86
86
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
87
87
|
cost)
|
88
88
|
if trace_content:
|
89
|
-
span.
|
90
|
-
|
89
|
+
span.add_event(
|
90
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
91
|
+
attributes={
|
92
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: str(kwargs.get("text", "")),
|
93
|
+
},
|
94
|
+
)
|
91
95
|
|
92
96
|
span.set_status(Status(StatusCode.OK))
|
93
97
|
|
@@ -107,10 +107,18 @@ def generate(gen_ai_endpoint, version, environment, application_name,
|
|
107
107
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
108
108
|
True)
|
109
109
|
if trace_content:
|
110
|
-
span.
|
111
|
-
|
112
|
-
|
113
|
-
|
110
|
+
span.add_event(
|
111
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
112
|
+
attributes={
|
113
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
114
|
+
},
|
115
|
+
)
|
116
|
+
span.add_event(
|
117
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
118
|
+
attributes={
|
119
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
|
120
|
+
},
|
121
|
+
)
|
114
122
|
|
115
123
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
|
116
124
|
prompt_tokens)
|
@@ -195,10 +203,18 @@ def generate(gen_ai_endpoint, version, environment, application_name,
|
|
195
203
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
196
204
|
False)
|
197
205
|
if trace_content:
|
198
|
-
span.
|
199
|
-
|
200
|
-
|
201
|
-
|
206
|
+
span.add_event(
|
207
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
208
|
+
attributes={
|
209
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
210
|
+
},
|
211
|
+
)
|
212
|
+
span.add_event(
|
213
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
214
|
+
attributes={
|
215
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response,
|
216
|
+
},
|
217
|
+
)
|
202
218
|
|
203
219
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
|
204
220
|
prompt_tokens)
|
@@ -313,8 +329,12 @@ def embed(gen_ai_endpoint, version, environment, application_name,
|
|
313
329
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
314
330
|
cost)
|
315
331
|
if trace_content:
|
316
|
-
span.
|
317
|
-
|
332
|
+
span.add_event(
|
333
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
334
|
+
attributes={
|
335
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
336
|
+
},
|
337
|
+
)
|
318
338
|
|
319
339
|
span.set_status(Status(StatusCode.OK))
|
320
340
|
|
@@ -119,15 +119,15 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
|
|
119
119
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,
|
120
120
|
kwargs.get("user", ""))
|
121
121
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
|
122
|
-
kwargs.get("top_p", 1))
|
122
|
+
kwargs.get("top_p", 1.0))
|
123
123
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
|
124
|
-
kwargs.get("max_tokens",
|
124
|
+
kwargs.get("max_tokens", -1))
|
125
125
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
|
126
|
-
kwargs.get("temperature", 1))
|
126
|
+
kwargs.get("temperature", 1.0))
|
127
127
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_PRESENCE_PENALTY,
|
128
|
-
kwargs.get("presence_penalty", 0))
|
128
|
+
kwargs.get("presence_penalty", 0.0))
|
129
129
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,
|
130
|
-
kwargs.get("frequency_penalty", 0))
|
130
|
+
kwargs.get("frequency_penalty", 0.0))
|
131
131
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
|
132
132
|
kwargs.get("seed", ""))
|
133
133
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
@@ -141,10 +141,18 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
|
|
141
141
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
142
142
|
cost)
|
143
143
|
if trace_content:
|
144
|
-
span.
|
145
|
-
|
146
|
-
|
147
|
-
|
144
|
+
span.add_event(
|
145
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
146
|
+
attributes={
|
147
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
148
|
+
},
|
149
|
+
)
|
150
|
+
span.add_event(
|
151
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
152
|
+
attributes={
|
153
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
|
154
|
+
},
|
155
|
+
)
|
148
156
|
|
149
157
|
span.set_status(Status(StatusCode.OK))
|
150
158
|
|
@@ -221,24 +229,28 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
|
|
221
229
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
|
222
230
|
kwargs.get("model", "llama3-8b-8192"))
|
223
231
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
|
224
|
-
kwargs.get("top_p", 1))
|
232
|
+
kwargs.get("top_p", 1.0))
|
225
233
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
|
226
|
-
kwargs.get("max_tokens",
|
234
|
+
kwargs.get("max_tokens", -1))
|
227
235
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,
|
228
236
|
kwargs.get("name", ""))
|
229
237
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
|
230
|
-
kwargs.get("temperature", 1))
|
238
|
+
kwargs.get("temperature", 1.0))
|
231
239
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_PRESENCE_PENALTY,
|
232
|
-
kwargs.get("presence_penalty", 0))
|
240
|
+
kwargs.get("presence_penalty", 0.0))
|
233
241
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,
|
234
|
-
kwargs.get("frequency_penalty", 0))
|
242
|
+
kwargs.get("frequency_penalty", 0.0))
|
235
243
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
|
236
244
|
kwargs.get("seed", ""))
|
237
245
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
238
246
|
False)
|
239
247
|
if trace_content:
|
240
|
-
span.
|
241
|
-
|
248
|
+
span.add_event(
|
249
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
250
|
+
attributes={
|
251
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
252
|
+
},
|
253
|
+
)
|
242
254
|
|
243
255
|
# Set span attributes when tools is not passed to the function call
|
244
256
|
if "tools" not in kwargs:
|
@@ -254,23 +266,31 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
|
|
254
266
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
|
255
267
|
response.usage.total_tokens)
|
256
268
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
257
|
-
response.choices[0].finish_reason)
|
269
|
+
[response.choices[0].finish_reason])
|
258
270
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
259
271
|
cost)
|
260
272
|
|
261
273
|
# Set span attributes for when n = 1 (default)
|
262
274
|
if "n" not in kwargs or kwargs["n"] == 1:
|
263
275
|
if trace_content:
|
264
|
-
span.
|
265
|
-
|
276
|
+
span.add_event(
|
277
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
278
|
+
attributes={
|
279
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].message.content,
|
280
|
+
},
|
281
|
+
)
|
266
282
|
|
267
283
|
# Set span attributes for when n > 0
|
268
284
|
else:
|
269
285
|
i = 0
|
270
286
|
while i < kwargs["n"] and trace_content is True:
|
271
287
|
attribute_name = f"gen_ai.completion.{i}"
|
272
|
-
span.
|
273
|
-
|
288
|
+
span.add_event(
|
289
|
+
name=attribute_name,
|
290
|
+
attributes={
|
291
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[i].message.content,
|
292
|
+
},
|
293
|
+
)
|
274
294
|
i += 1
|
275
295
|
|
276
296
|
# Return original response
|
@@ -119,15 +119,15 @@ def chat(gen_ai_endpoint, version, environment, application_name,
|
|
119
119
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,
|
120
120
|
kwargs.get("user", ""))
|
121
121
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
|
122
|
-
kwargs.get("top_p", 1))
|
122
|
+
kwargs.get("top_p", 1.0))
|
123
123
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
|
124
|
-
kwargs.get("max_tokens",
|
124
|
+
kwargs.get("max_tokens", -1))
|
125
125
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
|
126
|
-
kwargs.get("temperature", 1))
|
126
|
+
kwargs.get("temperature", 1.0))
|
127
127
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_PRESENCE_PENALTY,
|
128
|
-
kwargs.get("presence_penalty", 0))
|
128
|
+
kwargs.get("presence_penalty", 0.0))
|
129
129
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,
|
130
|
-
kwargs.get("frequency_penalty", 0))
|
130
|
+
kwargs.get("frequency_penalty", 0.0))
|
131
131
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
|
132
132
|
kwargs.get("seed", ""))
|
133
133
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
@@ -141,10 +141,18 @@ def chat(gen_ai_endpoint, version, environment, application_name,
|
|
141
141
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
142
142
|
cost)
|
143
143
|
if trace_content:
|
144
|
-
span.
|
145
|
-
|
146
|
-
|
147
|
-
|
144
|
+
span.add_event(
|
145
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
146
|
+
attributes={
|
147
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
148
|
+
},
|
149
|
+
)
|
150
|
+
span.add_event(
|
151
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
152
|
+
attributes={
|
153
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
|
154
|
+
},
|
155
|
+
)
|
148
156
|
|
149
157
|
span.set_status(Status(StatusCode.OK))
|
150
158
|
|
@@ -221,24 +229,28 @@ def chat(gen_ai_endpoint, version, environment, application_name,
|
|
221
229
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MODEL,
|
222
230
|
kwargs.get("model", "llama3-8b-8192"))
|
223
231
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
|
224
|
-
kwargs.get("top_p", 1))
|
232
|
+
kwargs.get("top_p", 1.0))
|
225
233
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
|
226
|
-
kwargs.get("max_tokens",
|
234
|
+
kwargs.get("max_tokens", -1))
|
227
235
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_USER,
|
228
236
|
kwargs.get("name", ""))
|
229
237
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
|
230
|
-
kwargs.get("temperature", 1))
|
238
|
+
kwargs.get("temperature", 1.0))
|
231
239
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_PRESENCE_PENALTY,
|
232
|
-
kwargs.get("presence_penalty", 0))
|
240
|
+
kwargs.get("presence_penalty", 0.0))
|
233
241
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_FREQUENCY_PENALTY,
|
234
|
-
kwargs.get("frequency_penalty", 0))
|
242
|
+
kwargs.get("frequency_penalty", 0.0))
|
235
243
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
|
236
244
|
kwargs.get("seed", ""))
|
237
245
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
238
246
|
False)
|
239
247
|
if trace_content:
|
240
|
-
span.
|
241
|
-
|
248
|
+
span.add_event(
|
249
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
250
|
+
attributes={
|
251
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
252
|
+
},
|
253
|
+
)
|
242
254
|
|
243
255
|
# Set span attributes when tools is not passed to the function call
|
244
256
|
if "tools" not in kwargs:
|
@@ -254,23 +266,31 @@ def chat(gen_ai_endpoint, version, environment, application_name,
|
|
254
266
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_TOTAL_TOKENS,
|
255
267
|
response.usage.total_tokens)
|
256
268
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
257
|
-
response.choices[0].finish_reason)
|
269
|
+
[response.choices[0].finish_reason])
|
258
270
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
259
271
|
cost)
|
260
272
|
|
261
273
|
# Set span attributes for when n = 1 (default)
|
262
274
|
if "n" not in kwargs or kwargs["n"] == 1:
|
263
275
|
if trace_content:
|
264
|
-
span.
|
265
|
-
|
276
|
+
span.add_event(
|
277
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
278
|
+
attributes={
|
279
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].message.content,
|
280
|
+
},
|
281
|
+
)
|
266
282
|
|
267
283
|
# Set span attributes for when n > 0
|
268
284
|
else:
|
269
285
|
i = 0
|
270
286
|
while i < kwargs["n"] and trace_content is True:
|
271
287
|
attribute_name = f"gen_ai.completion.{i}"
|
272
|
-
span.
|
273
|
-
|
288
|
+
span.add_event(
|
289
|
+
name=attribute_name,
|
290
|
+
attributes={
|
291
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[i].message.content,
|
292
|
+
},
|
293
|
+
)
|
274
294
|
i += 1
|
275
295
|
|
276
296
|
# Return original response
|
@@ -95,15 +95,15 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
|
|
95
95
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
|
96
96
|
kwargs.get("temperature", 0.7))
|
97
97
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
|
98
|
-
kwargs.get("top_p", 1))
|
98
|
+
kwargs.get("top_p", 1.0))
|
99
99
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
|
100
|
-
kwargs.get("max_tokens",
|
100
|
+
kwargs.get("max_tokens", -1))
|
101
101
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
|
102
102
|
kwargs.get("random_seed", ""))
|
103
103
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
104
104
|
False)
|
105
105
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
106
|
-
response.choices[0].finish_reason)
|
106
|
+
[response.choices[0].finish_reason])
|
107
107
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
|
108
108
|
response.usage.prompt_tokens)
|
109
109
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
|
@@ -113,10 +113,19 @@ def async_chat(gen_ai_endpoint, version, environment, application_name,
|
|
113
113
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
114
114
|
cost)
|
115
115
|
if trace_content:
|
116
|
-
span.
|
117
|
-
|
118
|
-
|
119
|
-
|
116
|
+
span.add_event(
|
117
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
118
|
+
attributes={
|
119
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
120
|
+
},
|
121
|
+
)
|
122
|
+
span.add_event(
|
123
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
124
|
+
attributes={
|
125
|
+
# pylint: disable=line-too-long
|
126
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].message.content if response.choices[0].message.content else "",
|
127
|
+
},
|
128
|
+
)
|
120
129
|
|
121
130
|
span.set_status(Status(StatusCode.OK))
|
122
131
|
|
@@ -252,15 +261,15 @@ def async_chat_stream(gen_ai_endpoint, version, environment, application_name,
|
|
252
261
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
|
253
262
|
kwargs.get("temperature", 0.7))
|
254
263
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
|
255
|
-
kwargs.get("top_p", 1))
|
264
|
+
kwargs.get("top_p", 1.0))
|
256
265
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
|
257
|
-
kwargs.get("max_tokens",
|
266
|
+
kwargs.get("max_tokens", -1))
|
258
267
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
|
259
268
|
kwargs.get("random_seed", ""))
|
260
269
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
261
270
|
True)
|
262
271
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
263
|
-
finish_reason)
|
272
|
+
[finish_reason])
|
264
273
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
|
265
274
|
prompt_tokens)
|
266
275
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
|
@@ -270,10 +279,18 @@ def async_chat_stream(gen_ai_endpoint, version, environment, application_name,
|
|
270
279
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
271
280
|
cost)
|
272
281
|
if trace_content:
|
273
|
-
span.
|
274
|
-
|
275
|
-
|
276
|
-
|
282
|
+
span.add_event(
|
283
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
284
|
+
attributes={
|
285
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
286
|
+
},
|
287
|
+
)
|
288
|
+
span.add_event(
|
289
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
290
|
+
attributes={
|
291
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
|
292
|
+
},
|
293
|
+
)
|
277
294
|
|
278
295
|
span.set_status(Status(StatusCode.OK))
|
279
296
|
|
@@ -378,8 +395,12 @@ def async_embeddings(gen_ai_endpoint, version, environment, application_name,
|
|
378
395
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
379
396
|
cost)
|
380
397
|
if trace_content:
|
381
|
-
span.
|
382
|
-
|
398
|
+
span.add_event(
|
399
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
400
|
+
attributes={
|
401
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
402
|
+
},
|
403
|
+
)
|
383
404
|
|
384
405
|
span.set_status(Status(StatusCode.OK))
|
385
406
|
|
@@ -94,15 +94,15 @@ def chat(gen_ai_endpoint, version, environment, application_name,
|
|
94
94
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
|
95
95
|
kwargs.get("temperature", 0.7))
|
96
96
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
|
97
|
-
kwargs.get("top_p", 1))
|
97
|
+
kwargs.get("top_p", 1.0))
|
98
98
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
|
99
|
-
kwargs.get("max_tokens",
|
99
|
+
kwargs.get("max_tokens", -1))
|
100
100
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
|
101
101
|
kwargs.get("random_seed", ""))
|
102
102
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
103
103
|
False)
|
104
104
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
105
|
-
response.choices[0].finish_reason)
|
105
|
+
[response.choices[0].finish_reason])
|
106
106
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
|
107
107
|
response.usage.prompt_tokens)
|
108
108
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
|
@@ -112,10 +112,19 @@ def chat(gen_ai_endpoint, version, environment, application_name,
|
|
112
112
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
113
113
|
cost)
|
114
114
|
if trace_content:
|
115
|
-
span.
|
116
|
-
|
117
|
-
|
118
|
-
|
115
|
+
span.add_event(
|
116
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
117
|
+
attributes={
|
118
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
119
|
+
},
|
120
|
+
)
|
121
|
+
span.add_event(
|
122
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
123
|
+
# pylint: disable=line-too-long
|
124
|
+
attributes={
|
125
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: response.choices[0].message.content if response.choices[0].message.content else "",
|
126
|
+
},
|
127
|
+
)
|
119
128
|
|
120
129
|
span.set_status(Status(StatusCode.OK))
|
121
130
|
|
@@ -251,15 +260,15 @@ def chat_stream(gen_ai_endpoint, version, environment, application_name,
|
|
251
260
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TEMPERATURE,
|
252
261
|
kwargs.get("temperature", 0.7))
|
253
262
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_TOP_P,
|
254
|
-
kwargs.get("top_p", 1))
|
263
|
+
kwargs.get("top_p", 1.0))
|
255
264
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_MAX_TOKENS,
|
256
|
-
kwargs.get("max_tokens",
|
265
|
+
kwargs.get("max_tokens", -1))
|
257
266
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_SEED,
|
258
267
|
kwargs.get("random_seed", ""))
|
259
268
|
span.set_attribute(SemanticConvetion.GEN_AI_REQUEST_IS_STREAM,
|
260
269
|
True)
|
261
270
|
span.set_attribute(SemanticConvetion.GEN_AI_RESPONSE_FINISH_REASON,
|
262
|
-
finish_reason)
|
271
|
+
[finish_reason])
|
263
272
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_PROMPT_TOKENS,
|
264
273
|
prompt_tokens)
|
265
274
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COMPLETION_TOKENS,
|
@@ -269,10 +278,18 @@ def chat_stream(gen_ai_endpoint, version, environment, application_name,
|
|
269
278
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
270
279
|
cost)
|
271
280
|
if trace_content:
|
272
|
-
span.
|
273
|
-
|
274
|
-
|
275
|
-
|
281
|
+
span.add_event(
|
282
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
283
|
+
attributes={
|
284
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
285
|
+
},
|
286
|
+
)
|
287
|
+
span.add_event(
|
288
|
+
name=SemanticConvetion.GEN_AI_CONTENT_COMPLETION_EVENT,
|
289
|
+
attributes={
|
290
|
+
SemanticConvetion.GEN_AI_CONTENT_COMPLETION: llmresponse,
|
291
|
+
},
|
292
|
+
)
|
276
293
|
|
277
294
|
span.set_status(Status(StatusCode.OK))
|
278
295
|
|
@@ -377,8 +394,12 @@ def embeddings(gen_ai_endpoint, version, environment, application_name,
|
|
377
394
|
span.set_attribute(SemanticConvetion.GEN_AI_USAGE_COST,
|
378
395
|
cost)
|
379
396
|
if trace_content:
|
380
|
-
span.
|
381
|
-
|
397
|
+
span.add_event(
|
398
|
+
name=SemanticConvetion.GEN_AI_CONTENT_PROMPT_EVENT,
|
399
|
+
attributes={
|
400
|
+
SemanticConvetion.GEN_AI_CONTENT_PROMPT: prompt,
|
401
|
+
},
|
402
|
+
)
|
382
403
|
|
383
404
|
span.set_status(Status(StatusCode.OK))
|
384
405
|
|