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.
@@ -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()