Skip to content

Commit f96a850

Browse files
committed
Fix Azure api key warning
1 parent 49fee5b commit f96a850

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/evals/guardrail-evals.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,14 @@ export class GuardrailEval {
378378
private _createContext(): Context {
379379
// Azure OpenAI
380380
if (this.azureEndpoint) {
381+
// Validate API key availability
382+
const apiKey = this.apiKey || process.env.OPENAI_API_KEY;
383+
if (!apiKey) {
384+
throw new Error(
385+
'API key is required for Azure OpenAI. Please provide --api-key or set OPENAI_API_KEY environment variable.'
386+
);
387+
}
388+
381389
const azureKwargs: Record<string, string> = {
382390
azureEndpoint: this.azureEndpoint,
383391
apiVersion: this.azureApiVersion,
@@ -388,8 +396,8 @@ export class GuardrailEval {
388396

389397
// Note: Azure OpenAI client creation would need AzureOpenAI import
390398
// For now, fall back to regular OpenAI with base URL
391-
const openaiClient = new OpenAI({
392-
apiKey: this.apiKey || process.env.OPENAI_API_KEY,
399+
const openaiClient = new OpenAI({
400+
apiKey: apiKey,
393401
baseURL: `https://${this.azureEndpoint.replace(/^https?:\/\//, '')}/openai/deployments`,
394402
});
395403
console.info(`event="client_created" type="azure" endpoint="${this.azureEndpoint}"`);
@@ -651,7 +659,7 @@ export class GuardrailEval {
651659
const modelContext = this._createContext();
652660

653661
const guardrails = await instantiateGuardrails(stageBundle);
654-
const engine = new AsyncRunEngine(guardrails, this.multiTurn);
662+
const engine = new AsyncRunEngine(guardrails, this.multiTurn);
655663
const chunkTotal = this.benchmarkChunkSize && samples.length > 0
656664
? Math.max(1, Math.ceil(samples.length / this.benchmarkChunkSize))
657665
: 1;

0 commit comments

Comments
 (0)