mirror of
https://github.com/promptfoo/promptfoo.git
synced 2023-08-15 01:10:51 +03:00
Set dummy envar for Azure OpenAI
This commit is contained in:
@@ -1 +1,2 @@
|
||||
process.env.OPENAI_API_KEY = 'foo';
|
||||
process.env.AZURE_OPENAI_API_HOST = 'azure.openai.host';
|
||||
|
||||
@@ -17,17 +17,13 @@ interface AzureOpenAiCompletionOptions {
|
||||
class AzureOpenAiGenericProvider implements ApiProvider {
|
||||
deploymentName: string;
|
||||
apiKey?: string;
|
||||
apiHost: string;
|
||||
apiHost?: string;
|
||||
|
||||
constructor(deploymentName: string, apiKey?: string) {
|
||||
this.deploymentName = deploymentName;
|
||||
|
||||
this.apiKey = apiKey || process.env.AZURE_OPENAI_API_KEY;
|
||||
|
||||
if (!process.env.AZURE_OPENAI_API_HOST) {
|
||||
throw new Error('Azure OpenAI API host must be set');
|
||||
}
|
||||
|
||||
this.apiHost = process.env.AZURE_OPENAI_API_HOST;
|
||||
}
|
||||
|
||||
@@ -50,6 +46,9 @@ export class AzureOpenAiEmbeddingProvider extends AzureOpenAiGenericProvider {
|
||||
if (!this.apiKey) {
|
||||
throw new Error('Azure OpenAI API key must be set for similarity comparison');
|
||||
}
|
||||
if (!this.apiHost) {
|
||||
throw new Error('Azure OpenAI API host must be set');
|
||||
}
|
||||
|
||||
const body = {
|
||||
input: text,
|
||||
@@ -125,6 +124,9 @@ export class AzureOpenAiCompletionProvider extends AzureOpenAiGenericProvider {
|
||||
'Azure OpenAI API key is not set. Set AZURE_OPENAI_API_KEY environment variable or pass it as an argument to the constructor.',
|
||||
);
|
||||
}
|
||||
if (!this.apiHost) {
|
||||
throw new Error('Azure OpenAI API host must be set');
|
||||
}
|
||||
|
||||
let stop: string;
|
||||
try {
|
||||
@@ -199,6 +201,9 @@ export class AzureOpenAiChatCompletionProvider extends AzureOpenAiGenericProvide
|
||||
'Azure OpenAI API key is not set. Set AZURE_OPENAI_API_KEY environment variable or pass it as an argument to the constructor.',
|
||||
);
|
||||
}
|
||||
if (!this.apiHost) {
|
||||
throw new Error('Azure OpenAI API host must be set');
|
||||
}
|
||||
|
||||
let messages: { role: string; content: string; name?: string }[];
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user