-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Adds Azure OpenAI support #769
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
Show all changes
19 commits
Select commit
Hold shift + click to select a range
fb5269d
Adds Azure OpenAI support
thegovind 29bb621
Adds Azure OpenAI support
thegovind 9a311b1
Adds Azure OpenAI support
thegovind 33574d0
Merge branch 'main' into feat/azure-openai
thegovind 7d572a2
Centralizes OpenAI client creation
thegovind 3c8f7b6
Merge branch 'main' into feat/azure-openai
thegovind dc5b88e
Merge branch 'main' into feat/azure-openai
thegovind a4bdb83
Merge branch 'main' into feat/azure-openai
thegovind f015c63
add httpAgent to AOAI
thegovind 862eb1f
Merge branch 'main' into feat/azure-openai
thegovind 3603b8a
fix config file formatting
thegovind a62eee4
Merge remote-tracking branch 'origin/feat/azure-openai' into feat/azu…
thegovind 81bb431
fix trailing openai in the azure uri
thegovind 01dd3ea
Merge remote-tracking branch 'origin/feat/azure-openai' into feat/azu…
thegovind 9092b6d
fix trailing openai in the azure uri
thegovind 6c8bd70
Merge remote-tracking branch 'origin/feat/azure-openai' into feat/azu…
thegovind 03d5f2f
fix trailing openai in the azure uri
thegovind d9d1e0a
Merge remote-tracking branch 'origin/feat/azure-openai' into feat/azu…
thegovind 45f223b
Merge branch 'main' into feat/azure-openai
thegovind 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
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
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,51 @@ | ||
import type { AppConfig } from "./config.js"; | ||
|
||
import { | ||
getBaseUrl, | ||
getApiKey, | ||
AZURE_OPENAI_API_VERSION, | ||
OPENAI_TIMEOUT_MS, | ||
OPENAI_ORGANIZATION, | ||
OPENAI_PROJECT, | ||
} from "./config.js"; | ||
import OpenAI, { AzureOpenAI } from "openai"; | ||
|
||
type OpenAIClientConfig = { | ||
provider: string; | ||
}; | ||
|
||
/** | ||
* Creates an OpenAI client instance based on the provided configuration. | ||
* Handles both standard OpenAI and Azure OpenAI configurations. | ||
* | ||
* @param config The configuration containing provider information | ||
* @returns An instance of either OpenAI or AzureOpenAI client | ||
*/ | ||
export function createOpenAIClient( | ||
config: OpenAIClientConfig | AppConfig, | ||
): OpenAI | AzureOpenAI { | ||
const headers: Record<string, string> = {}; | ||
if (OPENAI_ORGANIZATION) { | ||
headers["OpenAI-Organization"] = OPENAI_ORGANIZATION; | ||
} | ||
if (OPENAI_PROJECT) { | ||
headers["OpenAI-Project"] = OPENAI_PROJECT; | ||
} | ||
|
||
if (config.provider?.toLowerCase() === "azure") { | ||
return new AzureOpenAI({ | ||
apiKey: getApiKey(config.provider), | ||
baseURL: getBaseUrl(config.provider), | ||
apiVersion: AZURE_OPENAI_API_VERSION, | ||
timeout: OPENAI_TIMEOUT_MS, | ||
defaultHeaders: headers, | ||
}); | ||
} | ||
|
||
return new OpenAI({ | ||
apiKey: getApiKey(config.provider), | ||
baseURL: getBaseUrl(config.provider), | ||
timeout: OPENAI_TIMEOUT_MS, | ||
defaultHeaders: headers, | ||
thegovind marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
} |
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
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.