braintrust 0.4.0__py3-none-any.whl → 0.4.2__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/bt_json.py +178 -19
- braintrust/db_fields.py +1 -0
- braintrust/framework.py +13 -4
- braintrust/logger.py +30 -120
- braintrust/otel/__init__.py +24 -15
- braintrust/test_bt_json.py +644 -0
- braintrust/test_framework.py +81 -0
- braintrust/test_logger.py +245 -107
- braintrust/test_otel.py +118 -26
- braintrust/test_util.py +51 -1
- braintrust/util.py +24 -3
- braintrust/version.py +2 -2
- braintrust/wrappers/google_genai/__init__.py +2 -15
- braintrust/wrappers/litellm.py +43 -0
- braintrust/wrappers/pydantic_ai.py +209 -95
- braintrust/wrappers/test_google_genai.py +62 -1
- braintrust/wrappers/test_litellm.py +73 -0
- braintrust/wrappers/test_pydantic_ai_integration.py +819 -22
- {braintrust-0.4.0.dist-info → braintrust-0.4.2.dist-info}/METADATA +1 -1
- {braintrust-0.4.0.dist-info → braintrust-0.4.2.dist-info}/RECORD +23 -22
- {braintrust-0.4.0.dist-info → braintrust-0.4.2.dist-info}/WHEEL +0 -0
- {braintrust-0.4.0.dist-info → braintrust-0.4.2.dist-info}/entry_points.txt +0 -0
- {braintrust-0.4.0.dist-info → braintrust-0.4.2.dist-info}/top_level.txt +0 -0
|
@@ -702,3 +702,76 @@ async def test_litellm_async_streaming_with_break(memory_logger):
|
|
|
702
702
|
span = spans[0]
|
|
703
703
|
metrics = span["metrics"]
|
|
704
704
|
assert metrics["time_to_first_token"] >= 0
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
@pytest.mark.vcr
|
|
708
|
+
def test_patch_litellm_responses(memory_logger):
|
|
709
|
+
"""Test that patch_litellm() patches responses."""
|
|
710
|
+
from braintrust.wrappers.litellm import patch_litellm, unpatch_litellm
|
|
711
|
+
|
|
712
|
+
assert not memory_logger.pop()
|
|
713
|
+
|
|
714
|
+
patch_litellm()
|
|
715
|
+
try:
|
|
716
|
+
start = time.time()
|
|
717
|
+
# Call litellm.responses directly (not wrapped_litellm.responses)
|
|
718
|
+
response = litellm.responses(
|
|
719
|
+
model=TEST_MODEL,
|
|
720
|
+
input=TEST_PROMPT,
|
|
721
|
+
instructions="Just the number please",
|
|
722
|
+
)
|
|
723
|
+
end = time.time()
|
|
724
|
+
|
|
725
|
+
assert response
|
|
726
|
+
assert response.output
|
|
727
|
+
assert len(response.output) > 0
|
|
728
|
+
content = response.output[0].content[0].text
|
|
729
|
+
assert "24" in content or "twenty-four" in content.lower()
|
|
730
|
+
|
|
731
|
+
# Verify span was created
|
|
732
|
+
spans = memory_logger.pop()
|
|
733
|
+
assert len(spans) == 1
|
|
734
|
+
span = spans[0]
|
|
735
|
+
assert_metrics_are_valid(span["metrics"], start, end)
|
|
736
|
+
assert span["metadata"]["model"] == TEST_MODEL
|
|
737
|
+
assert span["metadata"]["provider"] == "litellm"
|
|
738
|
+
assert TEST_PROMPT in str(span["input"])
|
|
739
|
+
finally:
|
|
740
|
+
unpatch_litellm()
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
@pytest.mark.vcr
|
|
744
|
+
@pytest.mark.asyncio
|
|
745
|
+
async def test_patch_litellm_aresponses(memory_logger):
|
|
746
|
+
"""Test that patch_litellm() patches aresponses."""
|
|
747
|
+
from braintrust.wrappers.litellm import patch_litellm, unpatch_litellm
|
|
748
|
+
|
|
749
|
+
assert not memory_logger.pop()
|
|
750
|
+
|
|
751
|
+
patch_litellm()
|
|
752
|
+
try:
|
|
753
|
+
start = time.time()
|
|
754
|
+
# Call litellm.aresponses directly (not wrapped_litellm.aresponses)
|
|
755
|
+
response = await litellm.aresponses(
|
|
756
|
+
model=TEST_MODEL,
|
|
757
|
+
input=TEST_PROMPT,
|
|
758
|
+
instructions="Just the number please",
|
|
759
|
+
)
|
|
760
|
+
end = time.time()
|
|
761
|
+
|
|
762
|
+
assert response
|
|
763
|
+
assert response.output
|
|
764
|
+
assert len(response.output) > 0
|
|
765
|
+
content = response.output[0].content[0].text
|
|
766
|
+
assert "24" in content or "twenty-four" in content.lower()
|
|
767
|
+
|
|
768
|
+
# Verify span was created
|
|
769
|
+
spans = memory_logger.pop()
|
|
770
|
+
assert len(spans) == 1
|
|
771
|
+
span = spans[0]
|
|
772
|
+
assert_metrics_are_valid(span["metrics"], start, end)
|
|
773
|
+
assert span["metadata"]["model"] == TEST_MODEL
|
|
774
|
+
assert span["metadata"]["provider"] == "litellm"
|
|
775
|
+
assert TEST_PROMPT in str(span["input"])
|
|
776
|
+
finally:
|
|
777
|
+
unpatch_litellm()
|