Repository navigation
feat: support named data-residency endpoints #2393
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
Merged
Merged
Changes from all commits
Commits
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| schema_version: 1 | ||
| generation_id: 9d640a0f-6abd-44f8-aaa0-df24b003656d | ||
| generation_id: 2e672b14-22c2-4e3e-b20d-2cdd0d719583 | ||
| openapi_spec_hash: dd725fb7d43ceec7fb2de6f8713d14b6 | ||
| openapi_transformed_spec_hash: 10930179c5f116288e24e0c6fda46559 | ||
| config_hash: 28f37c225c55c75547d4feb84ee71044 | ||
| codegen_sha: cfe310550a1bec7192f8673528a957c35703f034 | ||
| config_hash: 85382dd94c503b5d225adc7636a77c9f | ||
| codegen_sha: 2ee3a8abe63e13ed0fc033198d9b99b51d168ad3 |
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 |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // File generated from our OpenAPI spec by Castiron. See CONTRIBUTING.md for details. | ||
|
|
||
| import { OpenAIError } from '../core/error'; | ||
| import { hasOwn } from './utils/values'; | ||
|
|
||
| /** OpenAI endpoint regions selectable without specifying a full base URL. */ | ||
| export type DataResidency = 'global' | 'us' | 'eu' | 'ae'; | ||
|
|
||
| const endpoints = new Map<DataResidency, string>([ | ||
| ['global', 'https://api.openai.com/v1'], | ||
| ['us', 'https://us.api.openai.com/v1'], | ||
| ['eu', 'https://eu.api.openai.com/v1'], | ||
| ['ae', 'https://ae.api.openai.com/v1'], | ||
| ]); | ||
|
|
||
| /** Resolves an explicit residency selection before client options are inherited. */ | ||
| export function resolveDataResidency(options: { | ||
| /** Residency shorthand; null and undefined preserve ordinary URL resolution. */ | ||
| dataResidency?: DataResidency | null | undefined; | ||
| /** Explicit API root, mutually exclusive with a residency selection. */ | ||
| baseURL?: string | null | undefined; | ||
| }): string | undefined { | ||
| if (options.dataResidency === null || options.dataResidency === undefined) { | ||
| return undefined; | ||
| } | ||
| if (hasOwn(options, 'baseURL')) { | ||
| throw new OpenAIError('The `dataResidency` and `baseURL` options are mutually exclusive.'); | ||
| } | ||
| const endpoint = endpoints.get(options.dataResidency); | ||
| if (endpoint === undefined) { | ||
| throw new OpenAIError('Invalid `dataResidency`; expected one of: global, us, eu, ae.'); | ||
| } | ||
| return endpoint; | ||
| } | ||
|
|
||
| /** Prevents legacy provider clients from selecting an OpenAI endpoint. */ | ||
| export function assertNoDataResidency( | ||
| dataResidency: DataResidency | null | undefined, | ||
| clientName: string, | ||
| ): void { | ||
| if (dataResidency !== null && dataResidency !== undefined) { | ||
| throw new OpenAIError(`${clientName} does not support \`dataResidency\`.`); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.