Skip to content

Commit

Permalink
remove makeAzurePath
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydzhou committed Jul 5, 2024
1 parent 1c20137 commit 6b1b530
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 34 deletions.
1 change: 0 additions & 1 deletion app/api/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
ServiceProvider,
} from "../constant";
import { isModelAvailableInServer } from "../utils/model";
import { makeAzurePath } from "../azure";

const serverConfig = getServerSideConfig();

Expand Down
9 changes: 0 additions & 9 deletions app/azure.ts

This file was deleted.

36 changes: 12 additions & 24 deletions app/client/platforms/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
} from "@fortaine/fetch-event-source";
import { prettyObject } from "@/app/utils/format";
import { getClientConfig } from "@/app/config/client";
import { makeAzurePath } from "@/app/azure";
import {
getMessageTextContent,
getMessageImages,
Expand Down Expand Up @@ -65,33 +64,31 @@ export class ChatGPTApi implements LLMApi {

let baseUrl = "";

const isAzure = path.includes("deployments");
if (accessStore.useCustomConfig) {
const isAzure = accessStore.provider === ServiceProvider.Azure;

if (isAzure && !accessStore.isValidAzure()) {
throw Error(
"incomplete azure config, please check it in your settings page",
);
}

if (isAzure) {
path = makeAzurePath(path, accessStore.azureApiVersion);
}

baseUrl = isAzure ? accessStore.azureUrl : accessStore.openaiUrl;
}

if (baseUrl.length === 0) {
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("/")) {
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;
}

Expand All @@ -100,15 +97,6 @@ export class ChatGPTApi implements LLMApi {
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) {
return res.choices?.at(0)?.message?.content ?? "";
}
Expand Down Expand Up @@ -171,14 +159,14 @@ export class ChatGPTApi implements LLMApi {
model.name == modelConfig.model &&
model?.provider.providerName == ServiceProvider.Azure,
);
chatPath =
this.getBaseUrl(ApiPath.Azure) +
chatPath = this.path(
Azure.ChatPath(
model?.displayName ?? model.name,
useAccessStore.getState().azureApiVersion,
);
),
);
} else {
chatPath = this.getBaseUrl(ApiPath.OpenAI) + OpenaiPath.ChatPath;
chatPath = this.path(OpenaiPath.ChatPath);
}
const chatPayload = {
method: "POST",
Expand Down

0 comments on commit 6b1b530

Please sign in to comment.