feat: add Azure OpenAI provider support
This commit is contained in:
@@ -357,6 +357,11 @@ export const PROVIDERS = {
|
||||
format: "perplexity-web",
|
||||
authType: "cookie"
|
||||
},
|
||||
azure: {
|
||||
baseUrl: "",
|
||||
format: "openai",
|
||||
headers: {}
|
||||
},
|
||||
};
|
||||
|
||||
export const OLLAMA_LOCAL_DEFAULT_HOST = "http://localhost:11434";
|
||||
|
||||
57
open-sse/executors/azure.js
Normal file
57
open-sse/executors/azure.js
Normal file
@@ -0,0 +1,57 @@
|
||||
import { DefaultExecutor } from "./default.js";
|
||||
|
||||
export class AzureExecutor extends DefaultExecutor {
|
||||
constructor() {
|
||||
super("azure");
|
||||
}
|
||||
|
||||
buildUrl(model, stream, urlIndex = 0, credentials = null) {
|
||||
const azureEndpoint = credentials?.providerSpecificData?.azureEndpoint
|
||||
|| process.env.AZURE_ENDPOINT
|
||||
|| "https://api.openai.com";
|
||||
|
||||
const apiVersion = credentials?.providerSpecificData?.apiVersion
|
||||
|| process.env.AZURE_API_VERSION
|
||||
|| "2024-10-01-preview";
|
||||
|
||||
const deployment = credentials?.providerSpecificData?.deployment
|
||||
|| model
|
||||
|| process.env.AZURE_DEPLOYMENT
|
||||
|| "gpt-4";
|
||||
|
||||
const endpoint = azureEndpoint.replace(/\/$/, "");
|
||||
return `${endpoint}/openai/deployments/${deployment}/chat/completions?api-version=${apiVersion}`;
|
||||
}
|
||||
|
||||
buildHeaders(credentials, stream = true) {
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
...this.config.headers
|
||||
};
|
||||
|
||||
const apiKey = credentials?.apiKey
|
||||
|| credentials?.accessToken
|
||||
|| process.env.OPENAI_API_KEY;
|
||||
|
||||
if (apiKey) {
|
||||
headers["api-key"] = apiKey;
|
||||
}
|
||||
|
||||
const organization = credentials?.providerSpecificData?.organization
|
||||
|| process.env.AZURE_ORGANIZATION;
|
||||
|
||||
if (organization) {
|
||||
headers["OpenAI-Organization"] = organization;
|
||||
}
|
||||
|
||||
if (stream) {
|
||||
headers["Accept"] = "text/event-stream";
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
transformRequest(model, body, stream, credentials) {
|
||||
return body;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { AntigravityExecutor } from "./antigravity.js";
|
||||
import { AzureExecutor } from "./azure.js";
|
||||
import { GeminiCLIExecutor } from "./gemini-cli.js";
|
||||
import { GithubExecutor } from "./github.js";
|
||||
import { IFlowExecutor } from "./iflow.js";
|
||||
@@ -16,6 +17,7 @@ import { DefaultExecutor } from "./default.js";
|
||||
|
||||
const executors = {
|
||||
antigravity: new AntigravityExecutor(),
|
||||
azure: new AzureExecutor(),
|
||||
"gemini-cli": new GeminiCLIExecutor(),
|
||||
github: new GithubExecutor(),
|
||||
iflow: new IFlowExecutor(),
|
||||
@@ -47,6 +49,7 @@ export function hasSpecializedExecutor(provider) {
|
||||
|
||||
export { BaseExecutor } from "./base.js";
|
||||
export { AntigravityExecutor } from "./antigravity.js";
|
||||
export { AzureExecutor } from "./azure.js";
|
||||
export { GeminiCLIExecutor } from "./gemini-cli.js";
|
||||
export { GithubExecutor } from "./github.js";
|
||||
export { IFlowExecutor } from "./iflow.js";
|
||||
|
||||
Reference in New Issue
Block a user