From ce3633d69e12670c24217244f88a3e4860aff94c Mon Sep 17 00:00:00 2001 From: iskandarsulaili Date: Fri, 21 Nov 2025 07:06:52 +0800 Subject: [PATCH] refactor: Conditionally include Gemini thinking level and refine Azure provider model info retrieval, client initialization, and usage chunk handling. --- src/api/providers/azure.ts | 34 ++++++++++++++++++++++------------ src/api/transform/reasoning.ts | 5 ++++- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/api/providers/azure.ts b/src/api/providers/azure.ts index a5dab910d8..d0b904330d 100644 --- a/src/api/providers/azure.ts +++ b/src/api/providers/azure.ts @@ -48,12 +48,10 @@ export class AzureHandler extends BaseProvider implements SingleCompletionHandle const { default: AnthropicFoundry } = await import("@anthropic-ai/foundry-sdk") const baseURL = this.options.azureBaseUrl || "https://your-endpoint.services.ai.azure.com/anthropic/" const apiKey = this.options.azureApiKey || this.options.apiKey || "not-provided" - const apiVersion = this.options.azureApiVersion || "2023-06-01" this.claudeClient = new AnthropicFoundry({ apiKey, baseURL, - apiVersion, }) } catch (error) { throw new Error("Failed to initialize Azure Claude client: " + (error as Error).message) @@ -285,12 +283,14 @@ export class AzureHandler extends BaseProvider implements SingleCompletionHandle } if (chunk.usage) { + // Azure OpenAI may include cache usage properties + const usage = chunk.usage as any yield { type: "usage", inputTokens: chunk.usage.prompt_tokens || 0, outputTokens: chunk.usage.completion_tokens || 0, - cacheWriteTokens: chunk.usage.cache_creation_input_tokens || undefined, - cacheReadTokens: chunk.usage.cache_read_input_tokens || undefined, + cacheWriteTokens: usage.cache_creation_input_tokens || undefined, + cacheReadTokens: usage.cache_read_input_tokens || undefined, } } } @@ -305,14 +305,24 @@ export class AzureHandler extends BaseProvider implements SingleCompletionHandle const id = modelId && modelId in azureModels ? (modelId as AzureModelId) : azureDefaultModelId const info: ModelInfo = azureModels[id] - const params = getModelParams({ - format: this.isClaudeModel(id) ? "anthropic" : "openai", - modelId: id, - model: info, - settings: this.options, - }) - - return { id, info, ...params } + // Handle Claude and GPT models separately to maintain type safety + if (this.isClaudeModel(id)) { + const params = getModelParams({ + format: "anthropic", + modelId: id, + model: info, + settings: this.options, + }) + return { id, info, ...params } + } else { + const params = getModelParams({ + format: "openai", + modelId: id, + model: info, + settings: this.options, + }) + return { id, info, ...params } + } } async completePrompt(prompt: string): Promise { diff --git a/src/api/transform/reasoning.ts b/src/api/transform/reasoning.ts index 07b3f80333..3f097f5af6 100644 --- a/src/api/transform/reasoning.ts +++ b/src/api/transform/reasoning.ts @@ -135,5 +135,8 @@ export const getGeminiReasoning = ({ return undefined } - return { thinkingLevel: selectedEffort, includeThoughts: true } + return { + includeThoughts: true, + ...(selectedEffort === "low" || selectedEffort === "high" ? { thinkingLevel: selectedEffort } : {}), + } as GeminiReasoningParams }