judgeval 0.16.4__py3-none-any.whl → 0.16.6__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 judgeval might be problematic. Click here for more details.
- judgeval/__init__.py +7 -2
- judgeval/scorers/judgeval_scorers/api_scorers/prompt_scorer.py +15 -4
- judgeval/tracer/__init__.py +9 -1
- judgeval/tracer/llm/llm_anthropic/wrapper.py +160 -130
- judgeval/tracer/llm/llm_google/wrapper.py +137 -98
- judgeval/tracer/llm/llm_groq/wrapper.py +137 -116
- judgeval/tracer/llm/llm_openai/wrapper.py +130 -106
- judgeval/tracer/llm/llm_together/wrapper.py +145 -120
- judgeval/tracer/utils.py +1 -1
- judgeval/utils/decorators/dont_throw.py +1 -1
- judgeval/version.py +1 -1
- {judgeval-0.16.4.dist-info → judgeval-0.16.6.dist-info}/METADATA +2 -2
- {judgeval-0.16.4.dist-info → judgeval-0.16.6.dist-info}/RECORD +16 -16
- {judgeval-0.16.4.dist-info → judgeval-0.16.6.dist-info}/WHEEL +0 -0
- {judgeval-0.16.4.dist-info → judgeval-0.16.6.dist-info}/entry_points.txt +0 -0
- {judgeval-0.16.4.dist-info → judgeval-0.16.6.dist-info}/licenses/LICENSE.md +0 -0
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
import functools
|
|
3
|
-
import orjson
|
|
4
3
|
from typing import (
|
|
5
4
|
TYPE_CHECKING,
|
|
6
5
|
Any,
|
|
@@ -22,6 +21,7 @@ from judgeval.tracer.llm.llm_openai.config import (
|
|
|
22
21
|
openai_AsyncOpenAI,
|
|
23
22
|
)
|
|
24
23
|
from judgeval.tracer.managers import sync_span_context, async_span_context
|
|
24
|
+
from judgeval.logger import judgeval_logger
|
|
25
25
|
from judgeval.tracer.keys import AttributeKeys
|
|
26
26
|
from judgeval.tracer.utils import set_span_attribute
|
|
27
27
|
from judgeval.utils.serialize import safe_serialize
|
|
@@ -426,7 +426,7 @@ class TracedOpenAIAsyncGenerator:
|
|
|
426
426
|
raise
|
|
427
427
|
|
|
428
428
|
|
|
429
|
-
TClient = TypeVar("TClient", bound=OpenAIClient)
|
|
429
|
+
TClient = TypeVar("TClient", bound=Union[OpenAIClient, OpenAIAsyncClient])
|
|
430
430
|
|
|
431
431
|
|
|
432
432
|
def wrap_openai_client(tracer: Tracer, client: TClient) -> TClient:
|
|
@@ -457,66 +457,78 @@ def wrap_openai_client(tracer: Tracer, client: TClient) -> TClient:
|
|
|
457
457
|
with sync_span_context(
|
|
458
458
|
tracer, span_name, {AttributeKeys.JUDGMENT_SPAN_KIND: "llm"}
|
|
459
459
|
) as span:
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
span, AttributeKeys.GEN_AI_PROMPT, safe_serialize(kwargs)
|
|
463
|
-
)
|
|
464
|
-
model_name = kwargs.get("model", "")
|
|
465
|
-
set_span_attribute(
|
|
466
|
-
span, AttributeKeys.GEN_AI_REQUEST_MODEL, model_name
|
|
467
|
-
)
|
|
468
|
-
response = function(*args, **kwargs)
|
|
469
|
-
|
|
470
|
-
if isinstance(response, (OpenAIChatCompletionBase, OpenAIResponse)):
|
|
471
|
-
output, usage_data = _format_openai_output(response)
|
|
472
|
-
# Serialize structured data to JSON for span attribute
|
|
473
|
-
if isinstance(output, list):
|
|
474
|
-
output_str = orjson.dumps(
|
|
475
|
-
output, option=orjson.OPT_INDENT_2
|
|
476
|
-
).decode()
|
|
477
|
-
else:
|
|
478
|
-
output_str = str(output) if output is not None else None
|
|
460
|
+
try:
|
|
461
|
+
tracer.add_agent_attributes_to_span(span)
|
|
479
462
|
set_span_attribute(
|
|
480
|
-
span, AttributeKeys.
|
|
463
|
+
span, AttributeKeys.GEN_AI_PROMPT, safe_serialize(kwargs)
|
|
481
464
|
)
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
)
|
|
465
|
+
model_name = kwargs.get("model", "")
|
|
466
|
+
set_span_attribute(
|
|
467
|
+
span, AttributeKeys.GEN_AI_REQUEST_MODEL, model_name
|
|
468
|
+
)
|
|
469
|
+
except Exception as e:
|
|
470
|
+
judgeval_logger.error(
|
|
471
|
+
f"[openai wrapped] Error adding span metadata: {e}"
|
|
472
|
+
)
|
|
473
|
+
|
|
474
|
+
response = function(*args, **kwargs)
|
|
475
|
+
|
|
476
|
+
try:
|
|
477
|
+
if isinstance(
|
|
478
|
+
response, (OpenAIChatCompletionBase, OpenAIResponse)
|
|
479
|
+
):
|
|
480
|
+
output, usage_data = _format_openai_output(response)
|
|
481
|
+
# Serialize structured data to JSON for span attribute
|
|
482
|
+
if isinstance(output, list):
|
|
483
|
+
output_str = safe_serialize(output)
|
|
484
|
+
else:
|
|
485
|
+
output_str = str(output) if output is not None else None
|
|
504
486
|
set_span_attribute(
|
|
505
|
-
span,
|
|
506
|
-
AttributeKeys.GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS,
|
|
507
|
-
cache_creation,
|
|
487
|
+
span, AttributeKeys.GEN_AI_COMPLETION, output_str
|
|
508
488
|
)
|
|
489
|
+
if usage_data:
|
|
490
|
+
(
|
|
491
|
+
prompt_tokens,
|
|
492
|
+
completion_tokens,
|
|
493
|
+
cache_read,
|
|
494
|
+
cache_creation,
|
|
495
|
+
) = _extract_openai_tokens(usage_data)
|
|
496
|
+
set_span_attribute(
|
|
497
|
+
span,
|
|
498
|
+
AttributeKeys.GEN_AI_USAGE_INPUT_TOKENS,
|
|
499
|
+
prompt_tokens,
|
|
500
|
+
)
|
|
501
|
+
set_span_attribute(
|
|
502
|
+
span,
|
|
503
|
+
AttributeKeys.GEN_AI_USAGE_OUTPUT_TOKENS,
|
|
504
|
+
completion_tokens,
|
|
505
|
+
)
|
|
506
|
+
set_span_attribute(
|
|
507
|
+
span,
|
|
508
|
+
AttributeKeys.GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS,
|
|
509
|
+
cache_read,
|
|
510
|
+
)
|
|
511
|
+
set_span_attribute(
|
|
512
|
+
span,
|
|
513
|
+
AttributeKeys.GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS,
|
|
514
|
+
cache_creation,
|
|
515
|
+
)
|
|
516
|
+
set_span_attribute(
|
|
517
|
+
span,
|
|
518
|
+
AttributeKeys.JUDGMENT_USAGE_METADATA,
|
|
519
|
+
safe_serialize(usage_data),
|
|
520
|
+
)
|
|
509
521
|
set_span_attribute(
|
|
510
522
|
span,
|
|
511
|
-
AttributeKeys.
|
|
512
|
-
|
|
523
|
+
AttributeKeys.GEN_AI_RESPONSE_MODEL,
|
|
524
|
+
getattr(response, "model", model_name),
|
|
513
525
|
)
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
getattr(response, "model", model_name),
|
|
526
|
+
except Exception as e:
|
|
527
|
+
judgeval_logger.error(
|
|
528
|
+
f"[openai wrapped] Error adding span metadata: {e}"
|
|
518
529
|
)
|
|
519
|
-
|
|
530
|
+
finally:
|
|
531
|
+
return response
|
|
520
532
|
|
|
521
533
|
return wrapper
|
|
522
534
|
|
|
@@ -541,66 +553,78 @@ def wrap_openai_client(tracer: Tracer, client: TClient) -> TClient:
|
|
|
541
553
|
async with async_span_context(
|
|
542
554
|
tracer, span_name, {AttributeKeys.JUDGMENT_SPAN_KIND: "llm"}
|
|
543
555
|
) as span:
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
span, AttributeKeys.GEN_AI_PROMPT, safe_serialize(kwargs)
|
|
547
|
-
)
|
|
548
|
-
model_name = kwargs.get("model", "")
|
|
549
|
-
set_span_attribute(
|
|
550
|
-
span, AttributeKeys.GEN_AI_REQUEST_MODEL, model_name
|
|
551
|
-
)
|
|
552
|
-
response = await function(*args, **kwargs)
|
|
553
|
-
|
|
554
|
-
if isinstance(response, (OpenAIChatCompletionBase, OpenAIResponse)):
|
|
555
|
-
output, usage_data = _format_openai_output(response)
|
|
556
|
-
# Serialize structured data to JSON for span attribute
|
|
557
|
-
if isinstance(output, list):
|
|
558
|
-
output_str = orjson.dumps(
|
|
559
|
-
output, option=orjson.OPT_INDENT_2
|
|
560
|
-
).decode()
|
|
561
|
-
else:
|
|
562
|
-
output_str = str(output) if output is not None else None
|
|
556
|
+
try:
|
|
557
|
+
tracer.add_agent_attributes_to_span(span)
|
|
563
558
|
set_span_attribute(
|
|
564
|
-
span, AttributeKeys.
|
|
559
|
+
span, AttributeKeys.GEN_AI_PROMPT, safe_serialize(kwargs)
|
|
565
560
|
)
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
)
|
|
561
|
+
model_name = kwargs.get("model", "")
|
|
562
|
+
set_span_attribute(
|
|
563
|
+
span, AttributeKeys.GEN_AI_REQUEST_MODEL, model_name
|
|
564
|
+
)
|
|
565
|
+
except Exception as e:
|
|
566
|
+
judgeval_logger.error(
|
|
567
|
+
f"[openai wrapped_async] Error adding span metadata: {e}"
|
|
568
|
+
)
|
|
569
|
+
|
|
570
|
+
response = await function(*args, **kwargs)
|
|
571
|
+
|
|
572
|
+
try:
|
|
573
|
+
if isinstance(
|
|
574
|
+
response, (OpenAIChatCompletionBase, OpenAIResponse)
|
|
575
|
+
):
|
|
576
|
+
output, usage_data = _format_openai_output(response)
|
|
577
|
+
# Serialize structured data to JSON for span attribute
|
|
578
|
+
if isinstance(output, list):
|
|
579
|
+
output_str = safe_serialize(output)
|
|
580
|
+
else:
|
|
581
|
+
output_str = str(output) if output is not None else None
|
|
588
582
|
set_span_attribute(
|
|
589
|
-
span,
|
|
590
|
-
AttributeKeys.GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS,
|
|
591
|
-
cache_creation,
|
|
583
|
+
span, AttributeKeys.GEN_AI_COMPLETION, output_str
|
|
592
584
|
)
|
|
585
|
+
if usage_data:
|
|
586
|
+
(
|
|
587
|
+
prompt_tokens,
|
|
588
|
+
completion_tokens,
|
|
589
|
+
cache_read,
|
|
590
|
+
cache_creation,
|
|
591
|
+
) = _extract_openai_tokens(usage_data)
|
|
592
|
+
set_span_attribute(
|
|
593
|
+
span,
|
|
594
|
+
AttributeKeys.GEN_AI_USAGE_INPUT_TOKENS,
|
|
595
|
+
prompt_tokens,
|
|
596
|
+
)
|
|
597
|
+
set_span_attribute(
|
|
598
|
+
span,
|
|
599
|
+
AttributeKeys.GEN_AI_USAGE_OUTPUT_TOKENS,
|
|
600
|
+
completion_tokens,
|
|
601
|
+
)
|
|
602
|
+
set_span_attribute(
|
|
603
|
+
span,
|
|
604
|
+
AttributeKeys.GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS,
|
|
605
|
+
cache_read,
|
|
606
|
+
)
|
|
607
|
+
set_span_attribute(
|
|
608
|
+
span,
|
|
609
|
+
AttributeKeys.GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS,
|
|
610
|
+
cache_creation,
|
|
611
|
+
)
|
|
612
|
+
set_span_attribute(
|
|
613
|
+
span,
|
|
614
|
+
AttributeKeys.JUDGMENT_USAGE_METADATA,
|
|
615
|
+
safe_serialize(usage_data),
|
|
616
|
+
)
|
|
593
617
|
set_span_attribute(
|
|
594
618
|
span,
|
|
595
|
-
AttributeKeys.
|
|
596
|
-
|
|
619
|
+
AttributeKeys.GEN_AI_RESPONSE_MODEL,
|
|
620
|
+
getattr(response, "model", model_name),
|
|
597
621
|
)
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
getattr(response, "model", model_name),
|
|
622
|
+
except Exception as e:
|
|
623
|
+
judgeval_logger.error(
|
|
624
|
+
f"[openai wrapped_async] Error adding span metadata: {e}"
|
|
602
625
|
)
|
|
603
|
-
|
|
626
|
+
finally:
|
|
627
|
+
return response
|
|
604
628
|
|
|
605
629
|
return wrapper
|
|
606
630
|
|
|
@@ -19,6 +19,7 @@ from judgeval.tracer.llm.llm_together.config import (
|
|
|
19
19
|
together_AsyncTogether,
|
|
20
20
|
)
|
|
21
21
|
from judgeval.tracer.managers import sync_span_context, async_span_context
|
|
22
|
+
from judgeval.logger import judgeval_logger
|
|
22
23
|
from judgeval.tracer.keys import AttributeKeys
|
|
23
24
|
from judgeval.tracer.utils import set_span_attribute
|
|
24
25
|
from judgeval.utils.serialize import safe_serialize
|
|
@@ -296,73 +297,85 @@ def wrap_together_client(
|
|
|
296
297
|
with sync_span_context(
|
|
297
298
|
tracer, span_name, {AttributeKeys.JUDGMENT_SPAN_KIND: "llm"}
|
|
298
299
|
) as span:
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
300
|
+
try:
|
|
301
|
+
tracer.add_agent_attributes_to_span(span)
|
|
302
|
+
set_span_attribute(
|
|
303
|
+
span, AttributeKeys.GEN_AI_PROMPT, safe_serialize(kwargs)
|
|
304
|
+
)
|
|
305
|
+
model_name = kwargs.get("model", "")
|
|
306
|
+
# Add together_ai/ prefix for server-side cost calculation
|
|
307
|
+
prefixed_model_name = (
|
|
308
|
+
f"together_ai/{model_name}" if model_name else ""
|
|
309
|
+
)
|
|
310
|
+
set_span_attribute(
|
|
311
|
+
span,
|
|
312
|
+
AttributeKeys.GEN_AI_REQUEST_MODEL,
|
|
313
|
+
prefixed_model_name,
|
|
314
|
+
)
|
|
315
|
+
except Exception as e:
|
|
316
|
+
judgeval_logger.error(
|
|
317
|
+
f"[together wrapped] Error adding span metadata: {e}"
|
|
318
|
+
)
|
|
319
|
+
|
|
311
320
|
response = function(*args, **kwargs)
|
|
312
321
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
if
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
322
|
+
try:
|
|
323
|
+
if isinstance(response, TogetherChatCompletion):
|
|
324
|
+
output, usage_data = _format_together_output(response)
|
|
325
|
+
# Serialize structured data to JSON for span attribute
|
|
326
|
+
if output:
|
|
327
|
+
if isinstance(output, list):
|
|
328
|
+
output_str = safe_serialize(output)
|
|
329
|
+
else:
|
|
330
|
+
output_str = str(output)
|
|
331
|
+
set_span_attribute(
|
|
332
|
+
span, AttributeKeys.GEN_AI_COMPLETION, output_str
|
|
333
|
+
)
|
|
334
|
+
if usage_data:
|
|
335
|
+
(
|
|
336
|
+
prompt_tokens,
|
|
337
|
+
completion_tokens,
|
|
338
|
+
cache_read,
|
|
339
|
+
cache_creation,
|
|
340
|
+
) = _extract_together_tokens(usage_data)
|
|
341
|
+
set_span_attribute(
|
|
342
|
+
span,
|
|
343
|
+
AttributeKeys.GEN_AI_USAGE_INPUT_TOKENS,
|
|
344
|
+
prompt_tokens,
|
|
345
|
+
)
|
|
346
|
+
set_span_attribute(
|
|
347
|
+
span,
|
|
348
|
+
AttributeKeys.GEN_AI_USAGE_OUTPUT_TOKENS,
|
|
349
|
+
completion_tokens,
|
|
350
|
+
)
|
|
351
|
+
set_span_attribute(
|
|
352
|
+
span,
|
|
353
|
+
AttributeKeys.GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS,
|
|
354
|
+
cache_read,
|
|
355
|
+
)
|
|
356
|
+
set_span_attribute(
|
|
357
|
+
span,
|
|
358
|
+
AttributeKeys.JUDGMENT_USAGE_METADATA,
|
|
359
|
+
safe_serialize(usage_data),
|
|
360
|
+
)
|
|
361
|
+
# Add together_ai/ prefix to response model for server-side cost calculation
|
|
362
|
+
response_model = getattr(response, "model", model_name)
|
|
363
|
+
prefixed_response_model = (
|
|
364
|
+
f"together_ai/{response_model}"
|
|
365
|
+
if response_model
|
|
366
|
+
else ""
|
|
327
367
|
)
|
|
328
|
-
if usage_data:
|
|
329
|
-
(
|
|
330
|
-
prompt_tokens,
|
|
331
|
-
completion_tokens,
|
|
332
|
-
cache_read,
|
|
333
|
-
cache_creation,
|
|
334
|
-
) = _extract_together_tokens(usage_data)
|
|
335
368
|
set_span_attribute(
|
|
336
369
|
span,
|
|
337
|
-
AttributeKeys.
|
|
338
|
-
|
|
370
|
+
AttributeKeys.GEN_AI_RESPONSE_MODEL,
|
|
371
|
+
prefixed_response_model,
|
|
339
372
|
)
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
completion_tokens,
|
|
344
|
-
)
|
|
345
|
-
set_span_attribute(
|
|
346
|
-
span,
|
|
347
|
-
AttributeKeys.GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS,
|
|
348
|
-
cache_read,
|
|
349
|
-
)
|
|
350
|
-
set_span_attribute(
|
|
351
|
-
span,
|
|
352
|
-
AttributeKeys.JUDGMENT_USAGE_METADATA,
|
|
353
|
-
safe_serialize(usage_data),
|
|
354
|
-
)
|
|
355
|
-
# Add together_ai/ prefix to response model for server-side cost calculation
|
|
356
|
-
response_model = getattr(response, "model", model_name)
|
|
357
|
-
prefixed_response_model = (
|
|
358
|
-
f"together_ai/{response_model}" if response_model else ""
|
|
359
|
-
)
|
|
360
|
-
set_span_attribute(
|
|
361
|
-
span,
|
|
362
|
-
AttributeKeys.GEN_AI_RESPONSE_MODEL,
|
|
363
|
-
prefixed_response_model,
|
|
373
|
+
except Exception as e:
|
|
374
|
+
judgeval_logger.error(
|
|
375
|
+
f"[together wrapped] Error adding span metadata: {e}"
|
|
364
376
|
)
|
|
365
|
-
|
|
377
|
+
finally:
|
|
378
|
+
return response
|
|
366
379
|
|
|
367
380
|
return wrapper
|
|
368
381
|
|
|
@@ -391,73 +404,85 @@ def wrap_together_client(
|
|
|
391
404
|
async with async_span_context(
|
|
392
405
|
tracer, span_name, {AttributeKeys.JUDGMENT_SPAN_KIND: "llm"}
|
|
393
406
|
) as span:
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
407
|
+
try:
|
|
408
|
+
tracer.add_agent_attributes_to_span(span)
|
|
409
|
+
set_span_attribute(
|
|
410
|
+
span, AttributeKeys.GEN_AI_PROMPT, safe_serialize(kwargs)
|
|
411
|
+
)
|
|
412
|
+
model_name = kwargs.get("model", "")
|
|
413
|
+
# Add together_ai/ prefix for server-side cost calculation
|
|
414
|
+
prefixed_model_name = (
|
|
415
|
+
f"together_ai/{model_name}" if model_name else ""
|
|
416
|
+
)
|
|
417
|
+
set_span_attribute(
|
|
418
|
+
span,
|
|
419
|
+
AttributeKeys.GEN_AI_REQUEST_MODEL,
|
|
420
|
+
prefixed_model_name,
|
|
421
|
+
)
|
|
422
|
+
except Exception as e:
|
|
423
|
+
judgeval_logger.error(
|
|
424
|
+
f"[together wrapped_async] Error adding span metadata: {e}"
|
|
425
|
+
)
|
|
426
|
+
|
|
406
427
|
response = await function(*args, **kwargs)
|
|
407
428
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
if
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
429
|
+
try:
|
|
430
|
+
if isinstance(response, TogetherChatCompletion):
|
|
431
|
+
output, usage_data = _format_together_output(response)
|
|
432
|
+
# Serialize structured data to JSON for span attribute
|
|
433
|
+
if output:
|
|
434
|
+
if isinstance(output, list):
|
|
435
|
+
output_str = safe_serialize(output)
|
|
436
|
+
else:
|
|
437
|
+
output_str = str(output)
|
|
438
|
+
set_span_attribute(
|
|
439
|
+
span, AttributeKeys.GEN_AI_COMPLETION, output_str
|
|
440
|
+
)
|
|
441
|
+
if usage_data:
|
|
442
|
+
(
|
|
443
|
+
prompt_tokens,
|
|
444
|
+
completion_tokens,
|
|
445
|
+
cache_read,
|
|
446
|
+
cache_creation,
|
|
447
|
+
) = _extract_together_tokens(usage_data)
|
|
448
|
+
set_span_attribute(
|
|
449
|
+
span,
|
|
450
|
+
AttributeKeys.GEN_AI_USAGE_INPUT_TOKENS,
|
|
451
|
+
prompt_tokens,
|
|
452
|
+
)
|
|
453
|
+
set_span_attribute(
|
|
454
|
+
span,
|
|
455
|
+
AttributeKeys.GEN_AI_USAGE_OUTPUT_TOKENS,
|
|
456
|
+
completion_tokens,
|
|
457
|
+
)
|
|
458
|
+
set_span_attribute(
|
|
459
|
+
span,
|
|
460
|
+
AttributeKeys.GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS,
|
|
461
|
+
cache_read,
|
|
462
|
+
)
|
|
463
|
+
set_span_attribute(
|
|
464
|
+
span,
|
|
465
|
+
AttributeKeys.JUDGMENT_USAGE_METADATA,
|
|
466
|
+
safe_serialize(usage_data),
|
|
467
|
+
)
|
|
468
|
+
# Add together_ai/ prefix to response model for server-side cost calculation
|
|
469
|
+
response_model = getattr(response, "model", model_name)
|
|
470
|
+
prefixed_response_model = (
|
|
471
|
+
f"together_ai/{response_model}"
|
|
472
|
+
if response_model
|
|
473
|
+
else ""
|
|
422
474
|
)
|
|
423
|
-
if usage_data:
|
|
424
|
-
(
|
|
425
|
-
prompt_tokens,
|
|
426
|
-
completion_tokens,
|
|
427
|
-
cache_read,
|
|
428
|
-
cache_creation,
|
|
429
|
-
) = _extract_together_tokens(usage_data)
|
|
430
475
|
set_span_attribute(
|
|
431
476
|
span,
|
|
432
|
-
AttributeKeys.
|
|
433
|
-
|
|
477
|
+
AttributeKeys.GEN_AI_RESPONSE_MODEL,
|
|
478
|
+
prefixed_response_model,
|
|
434
479
|
)
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
completion_tokens,
|
|
439
|
-
)
|
|
440
|
-
set_span_attribute(
|
|
441
|
-
span,
|
|
442
|
-
AttributeKeys.GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS,
|
|
443
|
-
cache_read,
|
|
444
|
-
)
|
|
445
|
-
set_span_attribute(
|
|
446
|
-
span,
|
|
447
|
-
AttributeKeys.JUDGMENT_USAGE_METADATA,
|
|
448
|
-
safe_serialize(usage_data),
|
|
449
|
-
)
|
|
450
|
-
# Add together_ai/ prefix to response model for server-side cost calculation
|
|
451
|
-
response_model = getattr(response, "model", model_name)
|
|
452
|
-
prefixed_response_model = (
|
|
453
|
-
f"together_ai/{response_model}" if response_model else ""
|
|
454
|
-
)
|
|
455
|
-
set_span_attribute(
|
|
456
|
-
span,
|
|
457
|
-
AttributeKeys.GEN_AI_RESPONSE_MODEL,
|
|
458
|
-
prefixed_response_model,
|
|
480
|
+
except Exception as e:
|
|
481
|
+
judgeval_logger.error(
|
|
482
|
+
f"[together wrapped_async] Error adding span metadata: {e}"
|
|
459
483
|
)
|
|
460
|
-
|
|
484
|
+
finally:
|
|
485
|
+
return response
|
|
461
486
|
|
|
462
487
|
return wrapper
|
|
463
488
|
|
judgeval/tracer/utils.py
CHANGED
|
@@ -13,7 +13,7 @@ def set_span_attribute(span: Span, name: str, value: Any):
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
class TraceScorerConfig(BaseModel):
|
|
16
|
-
scorer: TraceAPIScorerConfig
|
|
16
|
+
scorer: TraceAPIScorerConfig | None
|
|
17
17
|
model: Optional[str] = None
|
|
18
18
|
sampling_rate: float = 1.0
|
|
19
19
|
run_condition: Optional[Callable[..., bool]] = None
|
|
@@ -13,7 +13,7 @@ def dont_throw(func: Callable[..., T]) -> Callable[..., T | None]:
|
|
|
13
13
|
try:
|
|
14
14
|
return func(*args, **kwargs)
|
|
15
15
|
except Exception as e:
|
|
16
|
-
judgeval_logger.
|
|
16
|
+
judgeval_logger.warning(
|
|
17
17
|
f"An exception was raised in {func.__name__}", exc_info=e
|
|
18
18
|
)
|
|
19
19
|
pass
|
judgeval/version.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: judgeval
|
|
3
|
-
Version: 0.16.
|
|
3
|
+
Version: 0.16.6
|
|
4
4
|
Summary: Judgeval Package
|
|
5
5
|
Project-URL: Homepage, https://github.com/JudgmentLabs/judgeval
|
|
6
6
|
Project-URL: Issues, https://github.com/JudgmentLabs/judgeval/issues
|
|
@@ -14,7 +14,7 @@ Requires-Dist: boto3>=1.40.11
|
|
|
14
14
|
Requires-Dist: click<8.2.0
|
|
15
15
|
Requires-Dist: dotenv
|
|
16
16
|
Requires-Dist: httpx>=0.28.1
|
|
17
|
-
Requires-Dist: litellm
|
|
17
|
+
Requires-Dist: litellm>=1.75.0
|
|
18
18
|
Requires-Dist: opentelemetry-exporter-otlp>=1.36.0
|
|
19
19
|
Requires-Dist: opentelemetry-sdk>=1.36.0
|
|
20
20
|
Requires-Dist: orjson>=3.9.0
|