remove makeAzurePath
This commit is contained in:
parent
1c20137b0e
commit
6b1b530443
|
@ -7,7 +7,6 @@ import {
|
||||||
ServiceProvider,
|
ServiceProvider,
|
||||||
} from "../constant";
|
} from "../constant";
|
||||||
import { isModelAvailableInServer } from "../utils/model";
|
import { isModelAvailableInServer } from "../utils/model";
|
||||||
import { makeAzurePath } from "../azure";
|
|
||||||
|
|
||||||
const serverConfig = getServerSideConfig();
|
const serverConfig = getServerSideConfig();
|
||||||
|
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
export function makeAzurePath(path: string, apiVersion: string) {
|
|
||||||
// should omit /v1 prefix
|
|
||||||
path = path.replaceAll("v1/", "");
|
|
||||||
|
|
||||||
// should add api-key to query string
|
|
||||||
path += `${path.includes("?") ? "&" : "?"}api-version=${apiVersion}`;
|
|
||||||
|
|
||||||
return path;
|
|
||||||
}
|
|
|
@ -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
|
const apiPath = isAzure ? ApiPath.Azure : ApiPath.OpenAI;
|
||||||
? DEFAULT_API_HOST + "/proxy" + ApiPath.OpenAI
|
baseUrl = isApp ? DEFAULT_API_HOST + "/proxy" + apiPath : apiPath;
|
||||||
: ApiPath.OpenAI;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 =
|
chatPath = this.path(
|
||||||
this.getBaseUrl(ApiPath.Azure) +
|
|
||||||
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",
|
||||||
|
|
Loading…
Reference in New Issue