Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ If you want to disable parse settings from url, set this to 1.

To control custom models, use `+` to add a custom model, use `-` to hide a model, use `name:displayName` to customize model name, separated by comma.

### `SUMMARIZATION_MODEL` (optional)

Specify the model for summarization.
If it is not set, the summarization model will be decided on whether `CUSTOM_MODELS` is set or not
- If `CUSTOM_MODELS` is not set, `gpt-3.5-turbo` will be used for summarization.
- If `CUSTOM_MODELS` is set, the model used for current session will be used.

## Requirements

NodeJS >= 18, Docker >= 20
Expand Down
7 changes: 7 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ Azure Api 版本,你可以在这里找到:[Azure 文档](https://learn.micro

用来控制模型列表,使用 `+` 增加一个模型,使用 `-` 来隐藏一个模型,使用 `模型名:展示名` 来自定义模型的展示名,用英文逗号隔开。

### `SUMMARIZATION_MODEL` (可选)

指定会话摘要的模型,例如`gpt-4`。
如果不设置,会话摘要模型将根据如下条件决定
- 如果`CUSTOM_MODELS`未设置,默认使用`gpt-3.5-turbo`。
- 如果`CUSTOM_MODELS`设置了,默认使用当前会话模型。

## 开发

点击下方按钮,开始二次开发:
Expand Down
1 change: 1 addition & 0 deletions app/api/config/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const DANGER_CONFIG = {
hideBalanceQuery: serverConfig.hideBalanceQuery,
disableFastLink: serverConfig.disableFastLink,
customModels: serverConfig.customModels,
summarizationModel: serverConfig.summarizationModel,
};

declare global {
Expand Down
21 changes: 20 additions & 1 deletion app/config/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import md5 from "spark-md5";
import { DEFAULT_MODELS } from "../constant";
import { DEFAULT_MODELS, SUMMARIZE_MODEL } from "../constant";

declare global {
namespace NodeJS {
Expand All @@ -21,6 +21,7 @@ declare global {
ENABLE_BALANCE_QUERY?: string; // allow user to query balance or not
DISABLE_FAST_LINK?: string; // disallow parse settings from url or not
CUSTOM_MODELS?: string; // to control custom models
SUMMARIZATION_MODEL?: string; // allow user to use custom model for summarization

// azure only
AZURE_URL?: string; // https://{azure-url}/openai/deployments/{deploy-name}
Expand All @@ -43,6 +44,23 @@ const ACCESS_CODES = (function getAccessCodes(): Set<string> {
}
})();

const SUMMARIZATION_MODEL = (function getSummarizeModel(): string {
// 1. return env{SUMMARIZATION_MODEL} if it is set
if (process.env.SUMMARIZATION_MODEL) {
return process.env.SUMMARIZATION_MODEL;
}

// 2. return "gpt-3.5-turbo"
// if both env{SUMMARIZATION_MODEL} and env{CUSTOM_MODELS} are not set
if (!process.env.CUSTOM_MODELS) {
return SUMMARIZE_MODEL;
}

// 3. return "" to let client use session model
// if env{SUMMARIZATION_MODEL} is not set but env{CUSTOM_MODELS} is set
return "";
})();

export const getServerSideConfig = () => {
if (typeof process === "undefined") {
throw Error(
Expand Down Expand Up @@ -84,5 +102,6 @@ export const getServerSideConfig = () => {
hideBalanceQuery: !process.env.ENABLE_BALANCE_QUERY,
disableFastLink: !!process.env.DISABLE_FAST_LINK,
customModels,
summarizationModel: SUMMARIZATION_MODEL,
};
};
1 change: 1 addition & 0 deletions app/store/access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const DEFAULT_ACCESS_STATE = {
disableGPT4: false,
disableFastLink: false,
customModels: "",
summarizationModel: "",
};

export const useAccessStore = createPersistStore(
Expand Down
6 changes: 3 additions & 3 deletions app/store/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import {
DEFAULT_SYSTEM_TEMPLATE,
KnowledgeCutOffDate,
StoreKey,
SUMMARIZE_MODEL,
} from "../constant";
import { api, RequestMessage } from "../client/api";
import { ChatControllerPool } from "../client/controller";
import { prettyObject } from "../utils/format";
import { estimateTokenLength } from "../utils/token";
import { nanoid } from "nanoid";
import { createPersistStore } from "../utils/store";
import { useAccessStore } from "../store";

export type ChatMessage = RequestMessage & {
date: string;
Expand Down Expand Up @@ -81,8 +81,8 @@ function createEmptySession(): ChatSession {
}

function getSummarizeModel(currentModel: string) {
// if it is using gpt-* models, force to use 3.5 to summarize
return currentModel.startsWith("gpt") ? SUMMARIZE_MODEL : currentModel;
// use current model if summarizationModel is not set on the server side
return useAccessStore.getState().summarizationModel || currentModel;
}

function countMessages(msgs: ChatMessage[]) {
Expand Down