diff --git a/node-zerox/src/models/index.ts b/node-zerox/src/models/index.ts index 193042e8..479f7dd3 100644 --- a/node-zerox/src/models/index.ts +++ b/node-zerox/src/models/index.ts @@ -42,7 +42,7 @@ const isGoogleCredentials = ( const isOpenAICredentials = ( credentials: any ): credentials is OpenAICredentials => { - return credentials && typeof credentials.apiKey === "string"; + return credentials && typeof credentials.apiKey === "string" && credentials.baseUrl; }; export const createModel = ({ diff --git a/node-zerox/src/models/openAI.ts b/node-zerox/src/models/openAI.ts index a2b65ec2..1b5bf053 100644 --- a/node-zerox/src/models/openAI.ts +++ b/node-zerox/src/models/openAI.ts @@ -22,6 +22,7 @@ import fs from "fs-extra"; export default class OpenAIModel implements ModelInterface { private apiKey: string; private model: string; + private baseUrl: string; private llmParams?: Partial; constructor( @@ -30,6 +31,7 @@ export default class OpenAIModel implements ModelInterface { llmParams?: Partial ) { this.apiKey = credentials.apiKey; + this.baseUrl = credentials.baseUrl ?? 'https://api.openai.com/v1' this.model = model; this.llmParams = llmParams; } @@ -121,7 +123,7 @@ export default class OpenAIModel implements ModelInterface { try { const response = await axios.post( - "https://api.openai.com/v1/chat/completions", + `${this.baseUrl}/chat/completions`, { messages, model: this.model, diff --git a/node-zerox/src/types.ts b/node-zerox/src/types.ts index 2f466863..3f7f3a1b 100644 --- a/node-zerox/src/types.ts +++ b/node-zerox/src/types.ts @@ -70,6 +70,7 @@ export interface GoogleCredentials { } export interface OpenAICredentials { + baseUrl: string; apiKey: string; }