From 65acc65d5d2382b39eb6a3c75c21ffd7b815425c Mon Sep 17 00:00:00 2001 From: Zhang Minghan Date: Tue, 13 Feb 2024 08:31:19 +0800 Subject: [PATCH] feat: model caching alpha --- adapter/chatgpt/chat.go | 4 +++ app/src/admin/api/system.ts | 7 ++++ app/src/components/Tips.tsx | 2 +- app/src/components/home/ChatSpace.tsx | 1 - app/src/resources/i18n/cn.json | 12 ++++++- app/src/resources/i18n/en.json | 12 ++++++- app/src/resources/i18n/ja.json | 12 ++++++- app/src/routes/admin/System.tsx | 50 +++++++++++++++++++++++++++ channel/system.go | 29 +++++++++++++++- globals/variables.go | 3 ++ 10 files changed, 126 insertions(+), 6 deletions(-) diff --git a/adapter/chatgpt/chat.go b/adapter/chatgpt/chat.go index da5cf3d2..e0408015 100644 --- a/adapter/chatgpt/chat.go +++ b/adapter/chatgpt/chat.go @@ -136,5 +136,9 @@ func (c *ChatInstance) CreateStreamChatRequest(props *ChatProps, callback global return err.Error } + if props.Buffer.IsEmpty() { + return errors.New("no response") + } + return nil } diff --git a/app/src/admin/api/system.ts b/app/src/admin/api/system.ts index 79876d61..3afaaab0 100644 --- a/app/src/admin/api/system.ts +++ b/app/src/admin/api/system.ts @@ -38,6 +38,10 @@ export type SiteState = { }; export type CommonState = { + cache: string[]; + expire: number; + size: number; + article: string[]; generation: string[]; }; @@ -135,5 +139,8 @@ export const initialSystemState: SystemProps = { common: { article: [], generation: [], + cache: [], + expire: 3600, + size: 1, }, }; diff --git a/app/src/components/Tips.tsx b/app/src/components/Tips.tsx index 2a9bd6f2..ffe02851 100644 --- a/app/src/components/Tips.tsx +++ b/app/src/components/Tips.tsx @@ -73,7 +73,7 @@ function Tips({ = { data: T; @@ -543,6 +544,55 @@ function Common({ data, dispatch, onChange }: CompProps) { configParagraph={true} isCollapsed={true} > + + + { + dispatch({ type: "update:common.cache", value }); + }} + list={channelModels} + placeholder={t("admin.system.cachePlaceholder", { + length: (data.cache ?? []).length, + })} + /> + + + + + dispatch({ type: "update:common.expire", value }) + } + min={0} + /> + + + + + dispatch({ type: "update:common.size", value }) + } + min={0} + /> + +