diff --git a/apps/sim/app/api/copilot/chat/route.test.ts b/apps/sim/app/api/copilot/chat/route.test.ts index 2f94453a095..71912a60d88 100644 --- a/apps/sim/app/api/copilot/chat/route.test.ts +++ b/apps/sim/app/api/copilot/chat/route.test.ts @@ -224,11 +224,6 @@ describe('Copilot Chat API Route', () => { stream: true, streamToolCalls: true, mode: 'agent', - provider: { - provider: 'anthropic', - model: 'claude-3-haiku-20240307', - apiKey: 'test-sim-agent-key', - }, depth: 0, origin: 'http://localhost:3000', }), @@ -292,11 +287,6 @@ describe('Copilot Chat API Route', () => { stream: true, streamToolCalls: true, mode: 'agent', - provider: { - provider: 'anthropic', - model: 'claude-3-haiku-20240307', - apiKey: 'test-sim-agent-key', - }, depth: 0, origin: 'http://localhost:3000', }), @@ -352,11 +342,6 @@ describe('Copilot Chat API Route', () => { stream: true, streamToolCalls: true, mode: 'agent', - provider: { - provider: 'anthropic', - model: 'claude-3-haiku-20240307', - apiKey: 'test-sim-agent-key', - }, depth: 0, origin: 'http://localhost:3000', }), @@ -452,11 +437,6 @@ describe('Copilot Chat API Route', () => { stream: true, streamToolCalls: true, mode: 'ask', - provider: { - provider: 'anthropic', - model: 'claude-3-haiku-20240307', - apiKey: 'test-sim-agent-key', - }, depth: 0, origin: 'http://localhost:3000', }), diff --git a/apps/sim/app/api/copilot/chat/route.ts b/apps/sim/app/api/copilot/chat/route.ts index 1d47c8ea024..57a7baf3cdd 100644 --- a/apps/sim/app/api/copilot/chat/route.ts +++ b/apps/sim/app/api/copilot/chat/route.ts @@ -401,24 +401,26 @@ export async function POST(req: NextRequest) { } const defaults = getCopilotModel('chat') - const providerToUse = (env.COPILOT_PROVIDER as any) || defaults.provider const modelToUse = env.COPILOT_MODEL || defaults.model - let providerConfig: CopilotProviderConfig - - if (providerToUse === 'azure-openai') { - providerConfig = { - provider: 'azure-openai', - model: modelToUse, - apiKey: env.AZURE_OPENAI_API_KEY, - apiVersion: env.AZURE_OPENAI_API_VERSION, - endpoint: env.AZURE_OPENAI_ENDPOINT, - } - } else { - providerConfig = { - provider: providerToUse, - model: modelToUse, - apiKey: env.COPILOT_API_KEY, + let providerConfig: CopilotProviderConfig | undefined + const providerEnv = env.COPILOT_PROVIDER as any + + if (providerEnv) { + if (providerEnv === 'azure-openai') { + providerConfig = { + provider: 'azure-openai', + model: modelToUse, + apiKey: env.AZURE_OPENAI_API_KEY, + apiVersion: env.AZURE_OPENAI_API_VERSION, + endpoint: env.AZURE_OPENAI_ENDPOINT, + } + } else { + providerConfig = { + provider: providerEnv, + model: modelToUse, + apiKey: env.COPILOT_API_KEY, + } } } @@ -438,7 +440,7 @@ export async function POST(req: NextRequest) { stream: stream, streamToolCalls: true, mode: mode, - provider: providerConfig, + ...(providerConfig ? { provider: providerConfig } : {}), ...(effectiveConversationId ? { conversationId: effectiveConversationId } : {}), ...(typeof effectiveDepth === 'number' ? { depth: effectiveDepth } : {}), ...(typeof effectivePrefetch === 'boolean' ? { prefetch: effectivePrefetch } : {}),