Set dummy envar for Azure OpenAI

This commit is contained in:
Ian Webster
2023-07-14 10:26:53 -07:00
parent 60fee7260b
commit 97bbbaccfe
2 changed files with 11 additions and 5 deletions

View File

@@ -1 +1,2 @@
process.env.OPENAI_API_KEY = 'foo';
process.env.AZURE_OPENAI_API_HOST = 'azure.openai.host';

View File

@@ -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 {