From eb8dad700c2733177a2f84e1e8352ec3dd595ab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tianzhou=20=28=E5=A4=A9=E8=88=9F=29?= Date: Wed, 31 May 2023 18:51:42 +0800 Subject: [PATCH] chore: optimize token UX (#117) * chore: replace supabase with neon as the sample database consolidate * chore: optimize token UX --- src/components/ConnectionSidebar.tsx | 20 +++++++++++++------- src/components/kit/Checkbox.tsx | 4 ++-- src/locales/en.json | 2 +- src/locales/es.json | 2 +- src/locales/zh.json | 2 +- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/components/ConnectionSidebar.tsx b/src/components/ConnectionSidebar.tsx index b7aca7f..e3da739 100644 --- a/src/components/ConnectionSidebar.tsx +++ b/src/components/ConnectionSidebar.tsx @@ -9,7 +9,7 @@ import Icon from "./Icon"; import DarkModeSwitch from "./DarkModeSwitch"; import ConnectionList from "./Sidebar/ConnectionList"; import QuotaView from "./QuotaView"; -import { countTextTokens, hasFeature } from "../utils"; +import { countTextTokens, getModel, hasFeature } from "../utils"; import SettingAvatarIcon from "./SettingAvatarIcon"; import Checkbox from "./kit/Checkbox"; @@ -33,6 +33,7 @@ const ConnectionSidebar = () => { conversationStore.getConversationById(conversationStore.currentConversationId)?.selectedSchemaName || ""; const tableSchemaLoadingState = useLoading(); const currentConversation = conversationStore.getConversationById(conversationStore.currentConversationId); + const maxToken = getModel(settingStore.setting.openAIApiConfig?.model || "").max_token; const [totalToken, setTotalToken] = useState(0); useEffect(() => { updateHasSchemaProperty( @@ -193,7 +194,7 @@ const ConnectionSidebar = () => { {databaseList.length > 0 && (
{ return { @@ -243,10 +244,15 @@ const ConnectionSidebar = () => { ))}
-
-
- {t("connection.total-token")} {totalToken} -
+
+ {currentConnectionCtx && ( +
+
{t("connection.total-token")}
+
+ {totalToken}/{maxToken} +
+
+ )} {!settingStore.setting.openAIApiConfig?.key && hasFeature("quota") && (
diff --git a/src/components/kit/Checkbox.tsx b/src/components/kit/Checkbox.tsx index d292b8e..f64abe6 100644 --- a/src/components/kit/Checkbox.tsx +++ b/src/components/kit/Checkbox.tsx @@ -11,7 +11,7 @@ const Checkbox = (props: CheckboxProps & { children?: ReactNode }) => { const { value, label, onValueChange, children } = props; return (
-
+
onValueChange(label, value)} @@ -22,7 +22,7 @@ const Checkbox = (props: CheckboxProps & { children?: ReactNode }) => { -