Skip to content

Commit 915741b

Browse files
authored
feat(providers): added azure openai (#503)
* added azure openai * fix request params being passed through agent block for azure * remove o1 from azure-openai models list
1 parent ee35533 commit 915741b

File tree

11 files changed

+752
-1
lines changed

11 files changed

+752
-1
lines changed

apps/sim/app/api/providers/route.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export async function POST(request: NextRequest) {
3232
temperature,
3333
maxTokens,
3434
apiKey,
35+
azureEndpoint,
36+
azureApiVersion,
3537
responseFormat,
3638
workflowId,
3739
stream,
@@ -47,6 +49,8 @@ export async function POST(request: NextRequest) {
4749
hasTools: !!tools?.length,
4850
toolCount: tools?.length || 0,
4951
hasApiKey: !!apiKey,
52+
hasAzureEndpoint: !!azureEndpoint,
53+
hasAzureApiVersion: !!azureApiVersion,
5054
hasResponseFormat: !!responseFormat,
5155
workflowId,
5256
stream: !!stream,
@@ -88,6 +92,8 @@ export async function POST(request: NextRequest) {
8892
temperature,
8993
maxTokens,
9094
apiKey: finalApiKey,
95+
azureEndpoint,
96+
azureApiVersion,
9197
responseFormat,
9298
workflowId,
9399
stream,

apps/sim/blocks/blocks/agent.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,31 @@ export const AgentBlock: BlockConfig<AgentResponse> = {
146146
}
147147
: undefined, // Show for all models in non-hosted environments
148148
},
149+
{
150+
id: 'azureEndpoint',
151+
title: 'Azure OpenAI Endpoint',
152+
type: 'short-input',
153+
layout: 'full',
154+
password: true,
155+
placeholder: 'https://your-resource.openai.azure.com',
156+
connectionDroppable: false,
157+
condition: {
158+
field: 'model',
159+
value: ['azure/gpt-4o', 'azure/o3', 'azure/o4-mini', 'azure/gpt-4.1', 'azure/model-router'],
160+
},
161+
},
162+
{
163+
id: 'azureApiVersion',
164+
title: 'Azure API Version',
165+
type: 'short-input',
166+
layout: 'full',
167+
placeholder: '2024-07-01-preview',
168+
connectionDroppable: false,
169+
condition: {
170+
field: 'model',
171+
value: ['azure/gpt-4o', 'azure/o3', 'azure/o4-mini', 'azure/gpt-4.1', 'azure/model-router'],
172+
},
173+
},
149174
{
150175
id: 'tools',
151176
title: 'Tools',
@@ -237,6 +262,8 @@ export const AgentBlock: BlockConfig<AgentResponse> = {
237262
memories: { type: 'json', required: false },
238263
model: { type: 'string', required: true },
239264
apiKey: { type: 'string', required: true },
265+
azureEndpoint: { type: 'string', required: false },
266+
azureApiVersion: { type: 'string', required: false },
240267
responseFormat: {
241268
type: 'json',
242269
required: false,

apps/sim/executor/handlers/agent/agent-handler.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,5 +1232,33 @@ describe('AgentBlockHandler', () => {
12321232
expect(requestBody.messages[1].content).toBe('What is the weather like?')
12331233
expect(requestBody.messages[1]).not.toHaveProperty('conversationId')
12341234
})
1235+
1236+
it('should pass Azure OpenAI parameters through the request pipeline', async () => {
1237+
const inputs = {
1238+
model: 'azure/gpt-4o',
1239+
systemPrompt: 'You are a helpful assistant.',
1240+
userPrompt: 'Hello!',
1241+
apiKey: 'test-azure-api-key',
1242+
azureEndpoint: 'https://my-azure-resource.openai.azure.com',
1243+
azureApiVersion: '2024-07-01-preview',
1244+
temperature: 0.7,
1245+
}
1246+
1247+
mockGetProviderFromModel.mockReturnValue('azure-openai')
1248+
1249+
await handler.execute(mockBlock, inputs, mockContext)
1250+
1251+
expect(mockFetch).toHaveBeenCalledWith(expect.any(String), expect.any(Object))
1252+
1253+
const fetchCall = mockFetch.mock.calls[0]
1254+
const requestBody = JSON.parse(fetchCall[1].body)
1255+
1256+
// Check that Azure parameters are included in the request
1257+
expect(requestBody.azureEndpoint).toBe('https://my-azure-resource.openai.azure.com')
1258+
expect(requestBody.azureApiVersion).toBe('2024-07-01-preview')
1259+
expect(requestBody.provider).toBe('azure-openai')
1260+
expect(requestBody.model).toBe('azure/gpt-4o')
1261+
expect(requestBody.apiKey).toBe('test-azure-api-key')
1262+
})
12351263
})
12361264
})

apps/sim/executor/handlers/agent/agent-handler.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ export class AgentBlockHandler implements BlockHandler {
286286
temperature: inputs.temperature,
287287
maxTokens: inputs.maxTokens,
288288
apiKey: inputs.apiKey,
289+
azureEndpoint: inputs.azureEndpoint,
290+
azureApiVersion: inputs.azureApiVersion,
289291
responseFormat,
290292
workflowId: context.workflowId,
291293
stream: streaming,
@@ -386,6 +388,8 @@ export class AgentBlockHandler implements BlockHandler {
386388
temperature: providerRequest.temperature,
387389
maxTokens: providerRequest.maxTokens,
388390
apiKey: finalApiKey,
391+
azureEndpoint: providerRequest.azureEndpoint,
392+
azureApiVersion: providerRequest.azureApiVersion,
389393
responseFormat: providerRequest.responseFormat,
390394
workflowId: providerRequest.workflowId,
391395
stream: providerRequest.stream,

apps/sim/executor/handlers/agent/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export interface AgentInputs {
88
temperature?: number
99
maxTokens?: number
1010
apiKey?: string
11+
azureEndpoint?: string
12+
azureApiVersion?: string
1113
}
1214

1315
export interface ToolInput {

apps/sim/lib/env.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ export const env = createEnv({
5959
NODE_ENV: z.string().optional(),
6060
GITHUB_TOKEN: z.string().optional(),
6161
ELEVENLABS_API_KEY: z.string().min(1).optional(),
62+
AZURE_OPENAI_ENDPOINT: z.string().url().optional(),
63+
AZURE_OPENAI_API_VERSION: z.string().optional(),
6264

6365
// OAuth blocks (all optional)
6466
GOOGLE_CLIENT_ID: z.string().optional(),

0 commit comments

Comments
 (0)