braintrust 0.3.14__py3-none-any.whl → 0.4.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.
Files changed (83) hide show
  1. braintrust/__init__.py +4 -0
  2. braintrust/_generated_types.py +1200 -611
  3. braintrust/audit.py +2 -2
  4. braintrust/cli/eval.py +6 -7
  5. braintrust/cli/push.py +11 -11
  6. braintrust/conftest.py +1 -0
  7. braintrust/context.py +12 -17
  8. braintrust/contrib/temporal/__init__.py +16 -27
  9. braintrust/contrib/temporal/test_temporal.py +8 -3
  10. braintrust/devserver/auth.py +8 -8
  11. braintrust/devserver/cache.py +3 -4
  12. braintrust/devserver/cors.py +8 -7
  13. braintrust/devserver/dataset.py +3 -5
  14. braintrust/devserver/eval_hooks.py +7 -6
  15. braintrust/devserver/schemas.py +22 -19
  16. braintrust/devserver/server.py +19 -12
  17. braintrust/devserver/test_cached_login.py +4 -4
  18. braintrust/framework.py +128 -140
  19. braintrust/framework2.py +88 -87
  20. braintrust/functions/invoke.py +93 -53
  21. braintrust/functions/stream.py +3 -2
  22. braintrust/generated_types.py +17 -1
  23. braintrust/git_fields.py +11 -11
  24. braintrust/gitutil.py +2 -3
  25. braintrust/graph_util.py +10 -10
  26. braintrust/id_gen.py +2 -2
  27. braintrust/logger.py +346 -357
  28. braintrust/merge_row_batch.py +10 -9
  29. braintrust/oai.py +107 -24
  30. braintrust/otel/__init__.py +49 -49
  31. braintrust/otel/context.py +16 -30
  32. braintrust/otel/test_distributed_tracing.py +14 -11
  33. braintrust/otel/test_otel_bt_integration.py +32 -31
  34. braintrust/parameters.py +8 -8
  35. braintrust/prompt.py +14 -14
  36. braintrust/prompt_cache/disk_cache.py +5 -4
  37. braintrust/prompt_cache/lru_cache.py +3 -2
  38. braintrust/prompt_cache/prompt_cache.py +13 -14
  39. braintrust/queue.py +4 -4
  40. braintrust/score.py +4 -4
  41. braintrust/serializable_data_class.py +4 -4
  42. braintrust/span_identifier_v1.py +1 -2
  43. braintrust/span_identifier_v2.py +3 -4
  44. braintrust/span_identifier_v3.py +23 -20
  45. braintrust/span_identifier_v4.py +34 -25
  46. braintrust/test_framework.py +16 -6
  47. braintrust/test_helpers.py +5 -5
  48. braintrust/test_id_gen.py +2 -3
  49. braintrust/test_otel.py +61 -53
  50. braintrust/test_queue.py +0 -1
  51. braintrust/test_score.py +1 -3
  52. braintrust/test_span_components.py +29 -44
  53. braintrust/util.py +9 -8
  54. braintrust/version.py +2 -2
  55. braintrust/wrappers/_anthropic_utils.py +4 -4
  56. braintrust/wrappers/agno/__init__.py +3 -4
  57. braintrust/wrappers/agno/agent.py +1 -2
  58. braintrust/wrappers/agno/function_call.py +1 -2
  59. braintrust/wrappers/agno/model.py +1 -2
  60. braintrust/wrappers/agno/team.py +1 -2
  61. braintrust/wrappers/agno/utils.py +12 -12
  62. braintrust/wrappers/anthropic.py +7 -8
  63. braintrust/wrappers/claude_agent_sdk/__init__.py +3 -4
  64. braintrust/wrappers/claude_agent_sdk/_wrapper.py +29 -27
  65. braintrust/wrappers/dspy.py +15 -17
  66. braintrust/wrappers/google_genai/__init__.py +16 -16
  67. braintrust/wrappers/langchain.py +22 -24
  68. braintrust/wrappers/litellm.py +4 -3
  69. braintrust/wrappers/openai.py +15 -15
  70. braintrust/wrappers/pydantic_ai.py +1204 -0
  71. braintrust/wrappers/test_agno.py +0 -1
  72. braintrust/wrappers/test_dspy.py +0 -1
  73. braintrust/wrappers/test_google_genai.py +2 -3
  74. braintrust/wrappers/test_litellm.py +0 -1
  75. braintrust/wrappers/test_oai_attachments.py +322 -0
  76. braintrust/wrappers/test_pydantic_ai_integration.py +1788 -0
  77. braintrust/wrappers/{test_pydantic_ai.py → test_pydantic_ai_wrap_openai.py} +1 -2
  78. {braintrust-0.3.14.dist-info → braintrust-0.4.0.dist-info}/METADATA +3 -2
  79. braintrust-0.4.0.dist-info/RECORD +120 -0
  80. braintrust-0.3.14.dist-info/RECORD +0 -117
  81. {braintrust-0.3.14.dist-info → braintrust-0.4.0.dist-info}/WHEEL +0 -0
  82. {braintrust-0.3.14.dist-info → braintrust-0.4.0.dist-info}/entry_points.txt +0 -0
  83. {braintrust-0.3.14.dist-info → braintrust-0.4.0.dist-info}/top_level.txt +0 -0
braintrust/gitutil.py CHANGED
@@ -4,7 +4,6 @@ import re
4
4
  import subprocess
5
5
  import threading
6
6
  from functools import lru_cache as _cache
7
- from typing import Optional
8
7
 
9
8
  from .git_fields import GitMetadataSettings, RepoInfo
10
9
 
@@ -42,7 +41,7 @@ def _get_base_branch(remote=None):
42
41
  # To speed this up in the short term, we pick from a list of common names
43
42
  # and only fall back to the remote origin if required.
44
43
  COMMON_BASE_BRANCHES = ["main", "master", "develop"]
45
- repo_branches = set(b.name for b in repo.branches)
44
+ repo_branches = {b.name for b in repo.branches}
46
45
  if sum(b in repo_branches for b in COMMON_BASE_BRANCHES) == 1:
47
46
  for b in COMMON_BASE_BRANCHES:
48
47
  if b in repo_branches:
@@ -121,7 +120,7 @@ def truncate_to_byte_limit(input_string, byte_limit=65536):
121
120
  return encoded[:byte_limit].decode("utf-8", errors="ignore")
122
121
 
123
122
 
124
- def get_repo_info(settings: Optional[GitMetadataSettings] = None):
123
+ def get_repo_info(settings: GitMetadataSettings | None = None):
125
124
  if settings is None:
126
125
  settings = GitMetadataSettings()
127
126
 
braintrust/graph_util.py CHANGED
@@ -1,24 +1,24 @@
1
1
  # Generic graph algorithms.
2
2
 
3
3
  import dataclasses
4
- from typing import Dict, List, Optional, Protocol, Set, Tuple
4
+ from typing import Protocol
5
5
 
6
6
 
7
7
  # An UndirectedGraph consists of a set of vertex labels and a set of edges
8
8
  # between vertices.
9
9
  @dataclasses.dataclass
10
10
  class UndirectedGraph:
11
- vertices: Set[int]
12
- edges: Set[Tuple[int, int]]
11
+ vertices: set[int]
12
+ edges: set[tuple[int, int]]
13
13
 
14
14
 
15
15
  # An AdjacencyListGraph is a mapping from vertex label to the list of vertices
16
16
  # where there is a directed edge from the key to the value.
17
- AdjacencyListGraph = Dict[int, Set[int]]
17
+ AdjacencyListGraph = dict[int, set[int]]
18
18
 
19
19
 
20
20
  class FirstVisitF(Protocol):
21
- def __call__(self, vertex: int, *, parent_vertex: Optional[int], **kwargs) -> None:
21
+ def __call__(self, vertex: int, *, parent_vertex: int | None, **kwargs) -> None:
22
22
  """Extras:
23
23
  - parent_vertex: the vertex which spawned the current vertex as its
24
24
  child during the depth-first search. `parent_vertex` is guaranteed
@@ -33,9 +33,9 @@ class LastVisitF(Protocol):
33
33
 
34
34
  def depth_first_search(
35
35
  graph: AdjacencyListGraph,
36
- first_visit_f: Optional[FirstVisitF] = None,
37
- last_visit_f: Optional[LastVisitF] = None,
38
- visitation_order: Optional[List[int]] = None,
36
+ first_visit_f: FirstVisitF | None = None,
37
+ last_visit_f: LastVisitF | None = None,
38
+ visitation_order: list[int] | None = None,
39
39
  ) -> None:
40
40
  """A general depth-first search algorithm over a directed graph. As it
41
41
  traverses the graph, it invokes user-provided hooks when a vertex is *first*
@@ -86,7 +86,7 @@ def depth_first_search(
86
86
  events.append(("first", child, dict(parent_vertex=vertex)))
87
87
 
88
88
 
89
- def undirected_connected_components(graph: UndirectedGraph) -> List[List[int]]:
89
+ def undirected_connected_components(graph: UndirectedGraph) -> list[list[int]]:
90
90
  """Group together all the connected components of an undirected graph.
91
91
  Return each group as a list of vertices.
92
92
  """
@@ -124,7 +124,7 @@ def undirected_connected_components(graph: UndirectedGraph) -> List[List[int]]:
124
124
  return output
125
125
 
126
126
 
127
- def topological_sort(graph: AdjacencyListGraph, visitation_order: Optional[List[int]] = None) -> List[int]:
127
+ def topological_sort(graph: AdjacencyListGraph, visitation_order: list[int] | None = None) -> list[int]:
128
128
  """The topological_sort function accepts a graph as input, with edges from
129
129
  parents to children. It returns an ordering where parents are guaranteed to
130
130
  come before their children.
braintrust/id_gen.py CHANGED
@@ -45,8 +45,8 @@ class UUIDGenerator(IDGenerator):
45
45
 
46
46
 
47
47
  class OTELIDGenerator(IDGenerator):
48
- """ ID generator that generates OpenTelemetry-compatible IDs. We use this to have ids that can
49
- seamlessly flow between Braintrust and OpenTelemetry.
48
+ """ID generator that generates OpenTelemetry-compatible IDs. We use this to have ids that can
49
+ seamlessly flow between Braintrust and OpenTelemetry.
50
50
  """
51
51
 
52
52
  def get_span_id(self):