braintrust 0.3.15__py3-none-any.whl → 0.4.1__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.
- braintrust/_generated_types.py +737 -672
- braintrust/audit.py +2 -2
- braintrust/bt_json.py +178 -19
- braintrust/cli/eval.py +6 -7
- braintrust/cli/push.py +11 -11
- braintrust/context.py +12 -17
- braintrust/contrib/temporal/__init__.py +16 -27
- braintrust/contrib/temporal/test_temporal.py +8 -3
- braintrust/devserver/auth.py +8 -8
- braintrust/devserver/cache.py +3 -4
- braintrust/devserver/cors.py +8 -7
- braintrust/devserver/dataset.py +3 -5
- braintrust/devserver/eval_hooks.py +7 -6
- braintrust/devserver/schemas.py +22 -19
- braintrust/devserver/server.py +19 -12
- braintrust/devserver/test_cached_login.py +4 -4
- braintrust/framework.py +139 -142
- braintrust/framework2.py +88 -87
- braintrust/functions/invoke.py +66 -59
- braintrust/functions/stream.py +3 -2
- braintrust/generated_types.py +3 -1
- braintrust/git_fields.py +11 -11
- braintrust/gitutil.py +2 -3
- braintrust/graph_util.py +10 -10
- braintrust/id_gen.py +2 -2
- braintrust/logger.py +373 -471
- braintrust/merge_row_batch.py +10 -9
- braintrust/oai.py +21 -20
- braintrust/otel/__init__.py +49 -49
- braintrust/otel/context.py +16 -30
- braintrust/otel/test_distributed_tracing.py +14 -11
- braintrust/otel/test_otel_bt_integration.py +32 -31
- braintrust/parameters.py +8 -8
- braintrust/prompt.py +14 -14
- braintrust/prompt_cache/disk_cache.py +5 -4
- braintrust/prompt_cache/lru_cache.py +3 -2
- braintrust/prompt_cache/prompt_cache.py +13 -14
- braintrust/queue.py +4 -4
- braintrust/score.py +4 -4
- braintrust/serializable_data_class.py +4 -4
- braintrust/span_identifier_v1.py +1 -2
- braintrust/span_identifier_v2.py +3 -4
- braintrust/span_identifier_v3.py +23 -20
- braintrust/span_identifier_v4.py +34 -25
- braintrust/test_bt_json.py +644 -0
- braintrust/test_framework.py +72 -6
- braintrust/test_helpers.py +5 -5
- braintrust/test_id_gen.py +2 -3
- braintrust/test_logger.py +211 -107
- braintrust/test_otel.py +61 -53
- braintrust/test_queue.py +0 -1
- braintrust/test_score.py +1 -3
- braintrust/test_span_components.py +29 -44
- braintrust/util.py +9 -8
- braintrust/version.py +2 -2
- braintrust/wrappers/_anthropic_utils.py +4 -4
- braintrust/wrappers/agno/__init__.py +3 -4
- braintrust/wrappers/agno/agent.py +1 -2
- braintrust/wrappers/agno/function_call.py +1 -2
- braintrust/wrappers/agno/model.py +1 -2
- braintrust/wrappers/agno/team.py +1 -2
- braintrust/wrappers/agno/utils.py +12 -12
- braintrust/wrappers/anthropic.py +7 -8
- braintrust/wrappers/claude_agent_sdk/__init__.py +3 -4
- braintrust/wrappers/claude_agent_sdk/_wrapper.py +29 -27
- braintrust/wrappers/dspy.py +15 -17
- braintrust/wrappers/google_genai/__init__.py +17 -30
- braintrust/wrappers/langchain.py +22 -24
- braintrust/wrappers/litellm.py +4 -3
- braintrust/wrappers/openai.py +15 -15
- braintrust/wrappers/pydantic_ai.py +225 -110
- braintrust/wrappers/test_agno.py +0 -1
- braintrust/wrappers/test_dspy.py +0 -1
- braintrust/wrappers/test_google_genai.py +64 -4
- braintrust/wrappers/test_litellm.py +0 -1
- braintrust/wrappers/test_pydantic_ai_integration.py +819 -22
- {braintrust-0.3.15.dist-info → braintrust-0.4.1.dist-info}/METADATA +3 -2
- braintrust-0.4.1.dist-info/RECORD +121 -0
- braintrust-0.3.15.dist-info/RECORD +0 -120
- {braintrust-0.3.15.dist-info → braintrust-0.4.1.dist-info}/WHEEL +0 -0
- {braintrust-0.3.15.dist-info → braintrust-0.4.1.dist-info}/entry_points.txt +0 -0
- {braintrust-0.3.15.dist-info → braintrust-0.4.1.dist-info}/top_level.txt +0 -0
braintrust/wrappers/test_agno.py
CHANGED
braintrust/wrappers/test_dspy.py
CHANGED
|
@@ -2,12 +2,11 @@ import time
|
|
|
2
2
|
from pathlib import Path
|
|
3
3
|
|
|
4
4
|
import pytest
|
|
5
|
-
from google.genai import types
|
|
6
|
-
from google.genai.client import Client
|
|
7
|
-
|
|
8
5
|
from braintrust import logger
|
|
9
6
|
from braintrust.test_helpers import init_test_logger
|
|
10
7
|
from braintrust.wrappers.google_genai import setup_genai
|
|
8
|
+
from google.genai import types
|
|
9
|
+
from google.genai.client import Client
|
|
11
10
|
|
|
12
11
|
PROJECT_NAME = "test-genai-app"
|
|
13
12
|
MODEL = "gemini-2.0-flash-001"
|
|
@@ -548,7 +547,6 @@ def test_error_handling(memory_logger):
|
|
|
548
547
|
assert log["error"]
|
|
549
548
|
|
|
550
549
|
|
|
551
|
-
# Test 9: Stop Sequences
|
|
552
550
|
@pytest.mark.vcr
|
|
553
551
|
def test_stop_sequences(memory_logger):
|
|
554
552
|
"""Test stop sequences parameter."""
|
|
@@ -572,3 +570,65 @@ def test_stop_sequences(memory_logger):
|
|
|
572
570
|
assert len(spans) == 1
|
|
573
571
|
span = spans[0]
|
|
574
572
|
assert span["metadata"]["model"] == MODEL
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
def test_attachment_in_config(memory_logger):
|
|
576
|
+
"""Test that attachments in config are preserved through serialization."""
|
|
577
|
+
from braintrust.bt_json import bt_safe_deep_copy
|
|
578
|
+
from braintrust.logger import Attachment
|
|
579
|
+
|
|
580
|
+
attachment = Attachment(data=b"config data", filename="config.txt", content_type="text/plain")
|
|
581
|
+
|
|
582
|
+
# Simulate config with attachment
|
|
583
|
+
config = {"temperature": 0.5, "context_file": attachment, "max_output_tokens": 100}
|
|
584
|
+
|
|
585
|
+
# Test bt_safe_deep_copy preserves attachment
|
|
586
|
+
copied = bt_safe_deep_copy(config)
|
|
587
|
+
assert copied["context_file"] is attachment
|
|
588
|
+
assert copied["temperature"] == 0.5
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
def test_nested_attachments_in_contents(memory_logger):
|
|
592
|
+
"""Test that nested attachments in contents are preserved."""
|
|
593
|
+
from braintrust.bt_json import bt_safe_deep_copy
|
|
594
|
+
from braintrust.logger import Attachment, ExternalAttachment
|
|
595
|
+
|
|
596
|
+
attachment1 = Attachment(data=b"file1", filename="file1.txt", content_type="text/plain")
|
|
597
|
+
attachment2 = ExternalAttachment(url="s3://bucket/file2.pdf", filename="file2.pdf", content_type="application/pdf")
|
|
598
|
+
|
|
599
|
+
# Simulate contents with nested attachments
|
|
600
|
+
contents = [
|
|
601
|
+
{"role": "user", "parts": [{"text": "Check these files"}, {"file": attachment1}]},
|
|
602
|
+
{"role": "model", "parts": [{"text": "Analyzed"}, {"result_file": attachment2}]},
|
|
603
|
+
]
|
|
604
|
+
|
|
605
|
+
copied = bt_safe_deep_copy(contents)
|
|
606
|
+
|
|
607
|
+
# Verify attachments preserved
|
|
608
|
+
assert copied[0]["parts"][1]["file"] is attachment1
|
|
609
|
+
assert copied[1]["parts"][1]["result_file"] is attachment2
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
def test_attachment_with_pydantic_model(memory_logger):
|
|
613
|
+
"""Test that attachments work alongside Pydantic model serialization."""
|
|
614
|
+
from braintrust.bt_json import bt_safe_deep_copy
|
|
615
|
+
from braintrust.logger import Attachment
|
|
616
|
+
from pydantic import BaseModel
|
|
617
|
+
|
|
618
|
+
class TestModel(BaseModel):
|
|
619
|
+
name: str
|
|
620
|
+
value: int
|
|
621
|
+
|
|
622
|
+
attachment = Attachment(data=b"model data", filename="model.txt", content_type="text/plain")
|
|
623
|
+
|
|
624
|
+
# Structure with both Pydantic model and attachment
|
|
625
|
+
data = {"model_config": TestModel(name="test", value=42), "context_file": attachment}
|
|
626
|
+
|
|
627
|
+
copied = bt_safe_deep_copy(data)
|
|
628
|
+
|
|
629
|
+
# Pydantic model should be converted to dict
|
|
630
|
+
assert isinstance(copied["model_config"], dict)
|
|
631
|
+
assert copied["model_config"]["name"] == "test"
|
|
632
|
+
|
|
633
|
+
# Attachment should be preserved
|
|
634
|
+
assert copied["context_file"] is attachment
|