Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions apps/sim/app/api/copilot/chat/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}),
Expand Down Expand Up @@ -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',
}),
Expand Down Expand Up @@ -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',
}),
Expand Down Expand Up @@ -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',
}),
Expand Down
36 changes: 19 additions & 17 deletions apps/sim/app/api/copilot/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Type assertion to any bypasses TypeScript safety. Consider defining a union type of valid provider values or using proper type checking.

Context Used: Context - Avoid using type assertions to 'any' in TypeScript. Instead, ensure proper type definitions are used to maintain type safety. (link)


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,
}
}
}

Expand All @@ -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 } : {}),
Expand Down