|
@@ -27,7 +27,6 @@ import {
|
|
|
} from "@fortaine/fetch-event-source";
|
|
} from "@fortaine/fetch-event-source";
|
|
|
import { prettyObject } from "@/app/utils/format";
|
|
import { prettyObject } from "@/app/utils/format";
|
|
|
import { getClientConfig } from "@/app/config/client";
|
|
import { getClientConfig } from "@/app/config/client";
|
|
|
-import { makeAzurePath } from "@/app/azure";
|
|
|
|
|
import {
|
|
import {
|
|
|
getMessageTextContent,
|
|
getMessageTextContent,
|
|
|
getMessageImages,
|
|
getMessageImages,
|
|
@@ -65,33 +64,31 @@ export class ChatGPTApi implements LLMApi {
|
|
|
|
|
|
|
|
let baseUrl = "";
|
|
let baseUrl = "";
|
|
|
|
|
|
|
|
|
|
+ const isAzure = path.includes("deployments");
|
|
|
if (accessStore.useCustomConfig) {
|
|
if (accessStore.useCustomConfig) {
|
|
|
- const isAzure = accessStore.provider === ServiceProvider.Azure;
|
|
|
|
|
-
|
|
|
|
|
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",
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (isAzure) {
|
|
|
|
|
- path = makeAzurePath(path, accessStore.azureApiVersion);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
baseUrl = isAzure ? accessStore.azureUrl : accessStore.openaiUrl;
|
|
baseUrl = isAzure ? accessStore.azureUrl : accessStore.openaiUrl;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (baseUrl.length === 0) {
|
|
if (baseUrl.length === 0) {
|
|
|
const isApp = !!getClientConfig()?.isApp;
|
|
const isApp = !!getClientConfig()?.isApp;
|
|
|
- baseUrl = isApp
|
|
|
|
|
- ? DEFAULT_API_HOST + "/proxy" + ApiPath.OpenAI
|
|
|
|
|
- : ApiPath.OpenAI;
|
|
|
|
|
|
|
+ const apiPath = isAzure ? ApiPath.Azure : ApiPath.OpenAI;
|
|
|
|
|
+ baseUrl = isApp ? DEFAULT_API_HOST + "/proxy" + apiPath : apiPath;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (baseUrl.endsWith("/")) {
|
|
if (baseUrl.endsWith("/")) {
|
|
|
baseUrl = baseUrl.slice(0, baseUrl.length - 1);
|
|
baseUrl = baseUrl.slice(0, baseUrl.length - 1);
|
|
|
}
|
|
}
|
|
|
- if (!baseUrl.startsWith("http") && !baseUrl.startsWith(ApiPath.OpenAI)) {
|
|
|
|
|
|
|
+ if (
|
|
|
|
|
+ !baseUrl.startsWith("http") &&
|
|
|
|
|
+ !isAzure &&
|
|
|
|
|
+ !baseUrl.startsWith(ApiPath.OpenAI)
|
|
|
|
|
+ ) {
|
|
|
baseUrl = "https://" + baseUrl;
|
|
baseUrl = "https://" + baseUrl;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -100,15 +97,6 @@ export class ChatGPTApi implements LLMApi {
|
|
|
return [baseUrl, path].join("/");
|
|
return [baseUrl, path].join("/");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- getBaseUrl(apiPath: string) {
|
|
|
|
|
- const isApp = !!getClientConfig()?.isApp;
|
|
|
|
|
- let baseUrl = isApp ? DEFAULT_API_HOST + "/proxy" + apiPath : apiPath;
|
|
|
|
|
- if (baseUrl.endsWith("/")) {
|
|
|
|
|
- baseUrl = baseUrl.slice(0, baseUrl.length - 1);
|
|
|
|
|
- }
|
|
|
|
|
- return baseUrl + "/";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
extractMessage(res: any) {
|
|
extractMessage(res: any) {
|
|
|
return res.choices?.at(0)?.message?.content ?? "";
|
|
return res.choices?.at(0)?.message?.content ?? "";
|
|
|
}
|
|
}
|
|
@@ -171,14 +159,14 @@ 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.getBaseUrl(ApiPath.Azure) +
|
|
|
|
|
|
|
+ chatPath = this.path(
|
|
|
Azure.ChatPath(
|
|
Azure.ChatPath(
|
|
|
model?.displayName ?? model.name,
|
|
model?.displayName ?? model.name,
|
|
|
useAccessStore.getState().azureApiVersion,
|
|
useAccessStore.getState().azureApiVersion,
|
|
|
- );
|
|
|
|
|
|
|
+ ),
|
|
|
|
|
+ );
|
|
|
} else {
|
|
} else {
|
|
|
- chatPath = this.getBaseUrl(ApiPath.OpenAI) + OpenaiPath.ChatPath;
|
|
|
|
|
|
|
+ chatPath = this.path(OpenaiPath.ChatPath);
|
|
|
}
|
|
}
|
|
|
const chatPayload = {
|
|
const chatPayload = {
|
|
|
method: "POST",
|
|
method: "POST",
|