Skip to content

Commit 4d8203a

Browse files
committed
fix(azure): thread provider credentials through guardrails and fix translate missing bedrockAccessKeyId
1 parent 9592010 commit 4d8203a

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed

apps/sim/app/api/guardrails/validate/route.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ export async function POST(request: NextRequest) {
2323
topK,
2424
model,
2525
apiKey,
26+
azureEndpoint,
27+
azureApiVersion,
28+
vertexProject,
29+
vertexLocation,
30+
vertexCredential,
31+
bedrockAccessKeyId,
32+
bedrockSecretKey,
33+
bedrockRegion,
2634
workflowId,
2735
piiEntityTypes,
2836
piiMode,
@@ -110,6 +118,16 @@ export async function POST(request: NextRequest) {
110118
topK,
111119
model,
112120
apiKey,
121+
{
122+
azureEndpoint,
123+
azureApiVersion,
124+
vertexProject,
125+
vertexLocation,
126+
vertexCredential,
127+
bedrockAccessKeyId,
128+
bedrockSecretKey,
129+
bedrockRegion,
130+
},
113131
workflowId,
114132
piiEntityTypes,
115133
piiMode,
@@ -178,6 +196,16 @@ async function executeValidation(
178196
topK: string | undefined,
179197
model: string,
180198
apiKey: string | undefined,
199+
providerCredentials: {
200+
azureEndpoint?: string
201+
azureApiVersion?: string
202+
vertexProject?: string
203+
vertexLocation?: string
204+
vertexCredential?: string
205+
bedrockAccessKeyId?: string
206+
bedrockSecretKey?: string
207+
bedrockRegion?: string
208+
},
181209
workflowId: string | undefined,
182210
piiEntityTypes: string[] | undefined,
183211
piiMode: string | undefined,
@@ -219,6 +247,7 @@ async function executeValidation(
219247
topK: topK ? Number.parseInt(topK) : 10, // Default topK is 10
220248
model: model,
221249
apiKey,
250+
providerCredentials,
222251
workflowId,
223252
requestId,
224253
})

apps/sim/blocks/blocks/translate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ export const TranslateBlock: BlockConfig = {
7676
vertexProject: params.vertexProject,
7777
vertexLocation: params.vertexLocation,
7878
vertexCredential: params.vertexCredential,
79-
bedrockRegion: params.bedrockRegion,
79+
bedrockAccessKeyId: params.bedrockAccessKeyId,
8080
bedrockSecretKey: params.bedrockSecretKey,
81+
bedrockRegion: params.bedrockRegion,
8182
}),
8283
},
8384
},

apps/sim/lib/guardrails/validate_hallucination.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ export interface HallucinationValidationInput {
1919
topK: number // Number of chunks to retrieve, default 10
2020
model: string
2121
apiKey?: string
22+
providerCredentials?: {
23+
azureEndpoint?: string
24+
azureApiVersion?: string
25+
vertexProject?: string
26+
vertexLocation?: string
27+
vertexCredential?: string
28+
bedrockAccessKeyId?: string
29+
bedrockSecretKey?: string
30+
bedrockRegion?: string
31+
}
2232
workflowId?: string
2333
requestId: string
2434
}
@@ -90,6 +100,7 @@ async function scoreHallucinationWithLLM(
90100
ragContext: string[],
91101
model: string,
92102
apiKey: string,
103+
providerCredentials: HallucinationValidationInput['providerCredentials'],
93104
requestId: string
94105
): Promise<{ score: number; reasoning: string }> {
95106
try {
@@ -138,6 +149,7 @@ Evaluate the consistency and provide your score and reasoning in JSON format.`
138149
],
139150
temperature: 0.1, // Low temperature for consistent scoring
140151
apiKey,
152+
...providerCredentials,
141153
})
142154

143155
if (response instanceof ReadableStream || ('stream' in response && 'execution' in response)) {
@@ -184,8 +196,17 @@ Evaluate the consistency and provide your score and reasoning in JSON format.`
184196
export async function validateHallucination(
185197
input: HallucinationValidationInput
186198
): Promise<HallucinationValidationResult> {
187-
const { userInput, knowledgeBaseId, threshold, topK, model, apiKey, workflowId, requestId } =
188-
input
199+
const {
200+
userInput,
201+
knowledgeBaseId,
202+
threshold,
203+
topK,
204+
model,
205+
apiKey,
206+
providerCredentials,
207+
workflowId,
208+
requestId,
209+
} = input
189210

190211
try {
191212
if (!userInput || userInput.trim().length === 0) {
@@ -235,6 +256,7 @@ export async function validateHallucination(
235256
ragContext,
236257
model,
237258
finalApiKey,
259+
providerCredentials,
238260
requestId
239261
)
240262

apps/sim/tools/guardrails/validate.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ export interface GuardrailsValidateInput {
99
topK?: string
1010
model?: string
1111
apiKey?: string
12+
azureEndpoint?: string
13+
azureApiVersion?: string
14+
vertexProject?: string
15+
vertexLocation?: string
16+
vertexCredential?: string
17+
bedrockAccessKeyId?: string
18+
bedrockSecretKey?: string
19+
bedrockRegion?: string
1220
piiEntityTypes?: string[]
1321
piiMode?: string
1422
piiLanguage?: string
@@ -166,6 +174,14 @@ export const guardrailsValidateTool: ToolConfig<GuardrailsValidateInput, Guardra
166174
topK: params.topK,
167175
model: params.model,
168176
apiKey: params.apiKey,
177+
azureEndpoint: params.azureEndpoint,
178+
azureApiVersion: params.azureApiVersion,
179+
vertexProject: params.vertexProject,
180+
vertexLocation: params.vertexLocation,
181+
vertexCredential: params.vertexCredential,
182+
bedrockAccessKeyId: params.bedrockAccessKeyId,
183+
bedrockSecretKey: params.bedrockSecretKey,
184+
bedrockRegion: params.bedrockRegion,
169185
piiEntityTypes: params.piiEntityTypes,
170186
piiMode: params.piiMode,
171187
piiLanguage: params.piiLanguage,

0 commit comments

Comments
 (0)