Merge pull request #516 from samhvw8/feat/use-azure-openai

feat: add explicit Azure OpenAI flag
This commit is contained in:
Matt Rubens
2025-01-23 09:25:41 -08:00
committed by GitHub
4 changed files with 17 additions and 1 deletions

View File

@@ -18,7 +18,7 @@ export class OpenAiHandler implements ApiHandler, SingleCompletionHandler {
this.options = options this.options = options
// Azure API shape slightly differs from the core API shape: https://github.com/openai/openai-node?tab=readme-ov-file#microsoft-azure-openai // Azure API shape slightly differs from the core API shape: https://github.com/openai/openai-node?tab=readme-ov-file#microsoft-azure-openai
const urlHost = new URL(this.options.openAiBaseUrl ?? "").host const urlHost = new URL(this.options.openAiBaseUrl ?? "").host
if (urlHost === "azure.com" || urlHost.endsWith(".azure.com")) { if (urlHost === "azure.com" || urlHost.endsWith(".azure.com") || options.openAiUseAzure) {
this.client = new AzureOpenAI({ this.client = new AzureOpenAI({
baseURL: this.options.openAiBaseUrl, baseURL: this.options.openAiBaseUrl,
apiKey: this.options.openAiApiKey, apiKey: this.options.openAiApiKey,

View File

@@ -78,6 +78,7 @@ type GlobalStateKey =
| "openAiBaseUrl" | "openAiBaseUrl"
| "openAiModelId" | "openAiModelId"
| "openAiCustomModelInfo" | "openAiCustomModelInfo"
| "openAiUseAzure"
| "ollamaModelId" | "ollamaModelId"
| "ollamaBaseUrl" | "ollamaBaseUrl"
| "lmStudioModelId" | "lmStudioModelId"
@@ -1217,6 +1218,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
openAiApiKey, openAiApiKey,
openAiModelId, openAiModelId,
openAiCustomModelInfo, openAiCustomModelInfo,
openAiUseAzure,
ollamaModelId, ollamaModelId,
ollamaBaseUrl, ollamaBaseUrl,
lmStudioModelId, lmStudioModelId,
@@ -1251,6 +1253,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
await this.storeSecret("openAiApiKey", openAiApiKey) await this.storeSecret("openAiApiKey", openAiApiKey)
await this.updateGlobalState("openAiModelId", openAiModelId) await this.updateGlobalState("openAiModelId", openAiModelId)
await this.updateGlobalState("openAiCustomModelInfo", openAiCustomModelInfo) await this.updateGlobalState("openAiCustomModelInfo", openAiCustomModelInfo)
await this.updateGlobalState("openAiUseAzure", openAiUseAzure)
await this.updateGlobalState("ollamaModelId", ollamaModelId) await this.updateGlobalState("ollamaModelId", ollamaModelId)
await this.updateGlobalState("ollamaBaseUrl", ollamaBaseUrl) await this.updateGlobalState("ollamaBaseUrl", ollamaBaseUrl)
await this.updateGlobalState("lmStudioModelId", lmStudioModelId) await this.updateGlobalState("lmStudioModelId", lmStudioModelId)
@@ -1868,6 +1871,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
openAiApiKey, openAiApiKey,
openAiModelId, openAiModelId,
openAiCustomModelInfo, openAiCustomModelInfo,
openAiUseAzure,
ollamaModelId, ollamaModelId,
ollamaBaseUrl, ollamaBaseUrl,
lmStudioModelId, lmStudioModelId,
@@ -1932,6 +1936,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
this.getSecret("openAiApiKey") as Promise<string | undefined>, this.getSecret("openAiApiKey") as Promise<string | undefined>,
this.getGlobalState("openAiModelId") as Promise<string | undefined>, this.getGlobalState("openAiModelId") as Promise<string | undefined>,
this.getGlobalState("openAiCustomModelInfo") as Promise<ModelInfo | undefined>, this.getGlobalState("openAiCustomModelInfo") as Promise<ModelInfo | undefined>,
this.getGlobalState("openAiUseAzure") as Promise<boolean | undefined>,
this.getGlobalState("ollamaModelId") as Promise<string | undefined>, this.getGlobalState("ollamaModelId") as Promise<string | undefined>,
this.getGlobalState("ollamaBaseUrl") as Promise<string | undefined>, this.getGlobalState("ollamaBaseUrl") as Promise<string | undefined>,
this.getGlobalState("lmStudioModelId") as Promise<string | undefined>, this.getGlobalState("lmStudioModelId") as Promise<string | undefined>,
@@ -2013,6 +2018,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
openAiApiKey, openAiApiKey,
openAiModelId, openAiModelId,
openAiCustomModelInfo, openAiCustomModelInfo,
openAiUseAzure,
ollamaModelId, ollamaModelId,
ollamaBaseUrl, ollamaBaseUrl,
lmStudioModelId, lmStudioModelId,

View File

@@ -39,6 +39,7 @@ export interface ApiHandlerOptions {
openAiApiKey?: string openAiApiKey?: string
openAiModelId?: string openAiModelId?: string
openAiCustomModelInfo?: ModelInfo openAiCustomModelInfo?: ModelInfo
openAiUseAzure?: boolean
ollamaModelId?: string ollamaModelId?: string
ollamaBaseUrl?: string ollamaBaseUrl?: string
lmStudioModelId?: string lmStudioModelId?: string

View File

@@ -536,6 +536,15 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
Enable streaming Enable streaming
</Checkbox> </Checkbox>
</div> </div>
<Checkbox
checked={apiConfiguration?.openAiUseAzure ?? false}
onChange={(checked: boolean) => {
handleInputChange("openAiUseAzure")({
target: { value: checked },
})
}}>
Use Azure
</Checkbox>
<Checkbox <Checkbox
checked={azureApiVersionSelected} checked={azureApiVersionSelected}
onChange={(checked: boolean) => { onChange={(checked: boolean) => {