Skip to content

Commit e0780bf

Browse files
authored
ref(google_genai): Use new integrations API (#144)
1 parent 183dbb0 commit e0780bf

24 files changed

Lines changed: 386 additions & 272 deletions

py/noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def test_anthropic(session, version):
187187
def test_google_genai(session, version):
188188
_install_test_deps(session)
189189
_install(session, "google-genai", version)
190-
_run_tests(session, f"{WRAPPER_DIR}/test_google_genai.py")
190+
_run_tests(session, f"{INTEGRATION_DIR}/google_genai/test_google_genai.py")
191191
_run_core_tests(session)
192192

193193

py/src/braintrust/auto.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
import logging
88
from contextlib import contextmanager
99

10-
from braintrust.integrations import ADKIntegration, AgnoIntegration, AnthropicIntegration, ClaudeAgentSDKIntegration
10+
from braintrust.integrations import (
11+
ADKIntegration,
12+
AgnoIntegration,
13+
AnthropicIntegration,
14+
ClaudeAgentSDKIntegration,
15+
GoogleGenAIIntegration,
16+
)
1117

1218

1319
__all__ = ["auto_instrument"]
@@ -113,7 +119,7 @@ def auto_instrument(
113119
if pydantic_ai:
114120
results["pydantic_ai"] = _instrument_pydantic_ai()
115121
if google_genai:
116-
results["google_genai"] = _instrument_google_genai()
122+
results["google_genai"] = _instrument_integration(GoogleGenAIIntegration)
117123
if agno:
118124
results["agno"] = _instrument_integration(AgnoIntegration)
119125
if claude_agent_sdk:
@@ -156,14 +162,6 @@ def _instrument_pydantic_ai() -> bool:
156162
return False
157163

158164

159-
def _instrument_google_genai() -> bool:
160-
with _try_patch():
161-
from braintrust.wrappers.google_genai import setup_genai
162-
163-
return setup_genai()
164-
return False
165-
166-
167165
def _instrument_dspy() -> bool:
168166
with _try_patch():
169167
from braintrust.wrappers.dspy import patch_dspy

py/src/braintrust/integrations/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
from .agno import AgnoIntegration
33
from .anthropic import AnthropicIntegration
44
from .claude_agent_sdk import ClaudeAgentSDKIntegration
5+
from .google_genai import GoogleGenAIIntegration
56

67

7-
__all__ = ["ADKIntegration", "AgnoIntegration", "AnthropicIntegration", "ClaudeAgentSDKIntegration"]
8+
__all__ = [
9+
"ADKIntegration",
10+
"AgnoIntegration",
11+
"AnthropicIntegration",
12+
"ClaudeAgentSDKIntegration",
13+
"GoogleGenAIIntegration",
14+
]
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""Braintrust integration for Google GenAI."""
2+
3+
import logging
4+
5+
from braintrust.logger import NOOP_SPAN, current_span, init_logger
6+
7+
from .integration import GoogleGenAIIntegration
8+
9+
10+
logger = logging.getLogger(__name__)
11+
12+
__all__ = [
13+
"GoogleGenAIIntegration",
14+
"setup_genai",
15+
]
16+
17+
18+
def setup_genai(
19+
api_key: str | None = None,
20+
project_id: str | None = None,
21+
project_name: str | None = None,
22+
) -> bool:
23+
"""Setup Braintrust integration with Google GenAI.
24+
25+
Will automatically patch Google GenAI models for automatic tracing.
26+
27+
Args:
28+
api_key: Braintrust API key.
29+
project_id: Braintrust project ID.
30+
project_name: Braintrust project name.
31+
32+
Returns:
33+
True if setup was successful, False if google-genai is not installed.
34+
"""
35+
span = current_span()
36+
if span == NOOP_SPAN:
37+
init_logger(project=project_name, api_key=api_key, project_id=project_id)
38+
39+
return GoogleGenAIIntegration.setup()

py/src/braintrust/wrappers/cassettes/test_basic_completion[stream].yaml renamed to py/src/braintrust/integrations/google_genai/cassettes/test_basic_completion[stream].yaml

File renamed without changes.

py/src/braintrust/wrappers/cassettes/test_basic_completion[sync].yaml renamed to py/src/braintrust/integrations/google_genai/cassettes/test_basic_completion[sync].yaml

File renamed without changes.

py/src/braintrust/wrappers/cassettes/test_basic_completion_async[async].yaml renamed to py/src/braintrust/integrations/google_genai/cassettes/test_basic_completion_async[async].yaml

File renamed without changes.

py/src/braintrust/wrappers/cassettes/test_basic_completion_async[async_stream].yaml renamed to py/src/braintrust/integrations/google_genai/cassettes/test_basic_completion_async[async_stream].yaml

File renamed without changes.

py/src/braintrust/wrappers/cassettes/test_embed_content.yaml renamed to py/src/braintrust/integrations/google_genai/cassettes/test_embed_content.yaml

File renamed without changes.

py/src/braintrust/wrappers/cassettes/test_embed_content_async.yaml renamed to py/src/braintrust/integrations/google_genai/cassettes/test_embed_content_async.yaml

File renamed without changes.

0 commit comments

Comments
 (0)