Update openai.ts

This commit is contained in:
Richard C Lim 2025-02-02 03:39:27 -05:00 committed by GitHub
parent 1c4970b5bc
commit 7594379e54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -86,20 +86,22 @@ export class ChatGPTApi implements LLMApi {
let baseUrl = ""; let baseUrl = "";
const isAzure = path.includes("deployments"); const isAzure = path.includes("deployments");
if (accessStore.useCustomConfig) {
if (isAzure && !accessStore.isValidAzure()) { if (isAzure && !accessStore.isValidAzure()) {
throw Error( throw Error(
"incomplete azure config, please check it in your settings page", "incomplete azure config, please check it in your settings page",
); );
} }
baseUrl = isAzure ? accessStore.azureUrl : accessStore.openaiUrl;
}
if (baseUrl.length === 0) { if (baseUrl.length === 0) {
const isApp = !!getClientConfig()?.isApp; const isApp = !!getClientConfig()?.isApp;
const apiPath = ApiPath.Azure; const apiPath = isAzure ? ApiPath.Azure : ApiPath.OpenAI;
// const apiPath = isAzure ? ApiPath.Azure : ApiPath.OpenAI; baseUrl = isApp ? OPENAI_BASE_URL : apiPath;
// baseUrl = isApp ? OPENAI_BASE_URL : apiPath; }
}
};
if (baseUrl.endsWith("/")) { if (baseUrl.endsWith("/")) {
baseUrl = baseUrl.slice(0, baseUrl.length - 1); baseUrl = baseUrl.slice(0, baseUrl.length - 1);
@ -270,15 +272,16 @@ export class ChatGPTApi implements LLMApi {
model.name === modelConfig.model && model.name === modelConfig.model &&
model?.provider?.providerName === ServiceProvider.Azure, model?.provider?.providerName === ServiceProvider.Azure,
); );
chatPath = this.path( chatPath = this.path(
(isDalle3 ? Azure.ImagePath : Azure.ChatPath)( (isDalle3 ? Azure.ImagePath : Azure.ChatPath)(
(model?.displayName ?? model?.name) as string, (model?.displayName ?? model?.name) as string,
useCustomConfig ? useAccessStore.getState().azureApiVersion : "", useCustomConfig ? useAccessStore.getState().azureApiVersion : "",
), ),
); );
} } else {
if (!modelConfig.providerName === ServiceProvider.Azure) { chatPath = this.path(
throw Error("ModelConfig is not the same as Azure); isDalle3 ? OpenaiPath.ImagePath : OpenaiPath.ChatPath,
);
} }
if (shouldStream) { if (shouldStream) {
let index = -1; let index = -1;