-
Notifications
You must be signed in to change notification settings - Fork 63
Move from legacy proxy to gateway #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Erin McNulty (erin2722)
wants to merge
6
commits into
main
Choose a base branch
from
move-to-gateway
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+132
−48
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,16 @@ | |
| from dataclasses import dataclass | ||
| from typing import Any, Optional, Protocol, TypedDict, TypeVar, Union, cast, runtime_checkable | ||
|
|
||
| PROXY_URL = "https://api.braintrust.dev/v1/proxy" | ||
| GATEWAY_URL = "https://gateway.braintrust.dev" | ||
|
|
||
|
|
||
| def _gateway_url() -> str: | ||
| return os.environ.get("BRAINTRUST_AI_GATEWAY_URL", "").strip() or GATEWAY_URL | ||
|
|
||
|
|
||
| def _is_gateway_url(base_url: str) -> bool: | ||
| normalized_base_url = base_url.rstrip("/") | ||
| return normalized_base_url == GATEWAY_URL or normalized_base_url == _gateway_url().rstrip("/") | ||
|
|
||
|
|
||
| class DefaultModelConfig(TypedDict, total=False): | ||
|
|
@@ -195,7 +204,9 @@ def __post_init__(self): | |
| if not has_customization and not isinstance(self.openai, NamedWrapper): | ||
| self.openai = wrap_openai(self.openai) | ||
|
|
||
| self._is_wrapped = isinstance(self.openai, NamedWrapper) | ||
| self._is_wrapped = isinstance(self.openai, NamedWrapper) or ( | ||
| not has_customization and wrap_openai.__module__.startswith("braintrust.") | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. drive-by, the test was broken |
||
| ) | ||
|
|
||
| openai_module = get_openai_module() | ||
|
|
||
|
|
@@ -425,7 +436,7 @@ def init( | |
| models for different evaluation types. Only the specified models are updated; | ||
| others remain unchanged. | ||
|
|
||
| When using non-OpenAI providers via the Braintrust proxy, set this to the | ||
| When using non-OpenAI providers via the Braintrust Gateway, set this to the | ||
| appropriate model string (e.g., "claude-3-5-sonnet-20241022"). | ||
|
|
||
| Example: | ||
|
|
@@ -442,7 +453,7 @@ def init( | |
| init( | ||
| client=OpenAI( | ||
| api_key=os.environ["BRAINTRUST_API_KEY"], | ||
| base_url="https://api.braintrust.dev/v1/proxy", | ||
| base_url=os.getenv("BRAINTRUST_AI_GATEWAY_URL") or "https://gateway.braintrust.dev", | ||
| ), | ||
| default_model={ | ||
| "completion": "claude-3-5-sonnet-20241022", | ||
|
|
@@ -514,7 +525,8 @@ def prepare_openai( | |
| Deprecated: Use the `client` argument and set the `openai`. | ||
|
|
||
| base_url (str, optional): Base URL for API requests. If not provided, will | ||
| use OPENAI_BASE_URL from environment or fall back to PROXY_URL. | ||
| use OPENAI_BASE_URL from environment or fall back to BRAINTRUST_AI_GATEWAY_URL | ||
| or GATEWAY_URL. | ||
| Deprecated: Use the `client` argument and set the `openai`. | ||
|
|
||
| Returns: | ||
|
|
@@ -553,11 +565,14 @@ def prepare_openai( | |
| ) | ||
| warned_deprecated_api_key_base_url = True | ||
|
|
||
| if base_url is None: | ||
| base_url = os.environ.get("OPENAI_BASE_URL") or _gateway_url() | ||
| # prepare the default openai sdk, if not provided | ||
| if api_key is None: | ||
| api_key = os.environ.get("OPENAI_API_KEY") or os.environ.get("BRAINTRUST_API_KEY") | ||
| if base_url is None: | ||
| base_url = os.environ.get("OPENAI_BASE_URL", PROXY_URL) | ||
| if _is_gateway_url(base_url): | ||
| api_key = os.environ.get("BRAINTRUST_API_KEY") or os.environ.get("OPENAI_API_KEY") | ||
| else: | ||
| api_key = os.environ.get("OPENAI_API_KEY") or os.environ.get("BRAINTRUST_API_KEY") | ||
|
|
||
| if hasattr(openai_module, "OpenAI"): | ||
| openai_module = cast(OpenAIV1Module, openai_module) | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/braintrustdata/autoevals/pull/191/changes#r3337093260