diff --git a/src/components/StatusBar.tsx b/src/components/StatusBar.tsx new file mode 100644 index 0000000..9cad18b --- /dev/null +++ b/src/components/StatusBar.tsx @@ -0,0 +1,204 @@ +import { + CubeIcon, + BanknotesIcon, + ChatBubbleLeftEllipsisIcon, + ScissorsIcon, + SwatchIcon, + SparklesIcon, +} from "@heroicons/react/24/outline"; + +import { ChatStore } from "@/types/chatstore"; +import { models } from "@/types/models"; +import { Tr } from "@/translate"; +import { getTotalCost } from "@/utils/totalCost"; + +const StatusBar = (props: { + chatStore: ChatStore; + setShowSettings: (show: boolean) => void; + setShowSearch: (show: boolean) => void; +}) => { + const { chatStore, setShowSettings, setShowSearch } = props; + return ( +
+
+
+
+ + + +
+
    +
  • +

    + + Tokens: {chatStore.totalTokens}/{chatStore.maxTokens} +

    +
  • +
  • +

    + + Cut: + {chatStore.postBeginIndex}/ + {chatStore.history.filter(({ hide }) => !hide).length} +

    +
  • +
  • +

    + + Cost: ${chatStore.cost.toFixed(4)} +

    +
  • +
+
+
+
{ + setShowSettings(true); + }} + > + {/* the long staus bar */} +
+
+
+ +
+
Model
+
{chatStore.model}
+
+ {models[chatStore.model]?.price?.prompt * 1000 * 1000} $/M tokens +
+
+
+
+ +
+
Mode
+
+ {chatStore.streamMode ? Tr("STREAM") : Tr("FETCH")} +
+
STREAM/FETCH
+
+ +
+
+ +
+
Tokens
+
{chatStore.totalTokens}
+
Max: {chatStore.maxTokens}
+
+ +
+
+ +
+
Cut
+
+ {chatStore.postBeginIndex} +
+
+ Max: {chatStore.history.filter(({ hide }) => !hide).length} +
+
+ +
+
+ +
+
Cost
+
+ ${chatStore.cost.toFixed(4)} +
+
+ Accumulated: ${getTotalCost().toFixed(2)} +
+
+
+ + {/* the short status bar */} +
+ {chatStore.totalTokens !== 0 && ( + + Tokens: {chatStore.totalTokens} + + )} + + + {chatStore.model} + +
+
+
+ + +
+
+ ); +}; + +export default StatusBar; diff --git a/src/pages/chatbox.tsx b/src/pages/chatbox.tsx index aac467c..9950c57 100644 --- a/src/pages/chatbox.tsx +++ b/src/pages/chatbox.tsx @@ -1,12 +1,3 @@ -import { - CubeIcon, - BanknotesIcon, - ChatBubbleLeftEllipsisIcon, - ScissorsIcon, - SwatchIcon, - SparklesIcon, -} from "@heroicons/react/24/outline"; - import { IDBPDatabase } from "idb"; import { createRef } from "preact"; import { StateUpdater, useEffect, useState, Dispatch } from "preact/hooks"; @@ -45,6 +36,7 @@ import { autoHeight } from "@/textarea"; import Search from "@/search"; import Templates from "@/components/Templates"; import VersionHint from "@/components/VersionHint"; +import StatusBar from "@/components/StatusBar"; export default function ChatBOX(props: { db: Promise>; @@ -471,192 +463,12 @@ export default function ChatBOX(props: { /> )} -
-
-
-
- - - -
-
    -
  • -

    - - Tokens: {chatStore.totalTokens}/{chatStore.maxTokens} -

    -
  • -
  • -

    - - Cut: - {chatStore.postBeginIndex}/ - {chatStore.history.filter(({ hide }) => !hide).length} -

    -
  • -
  • -

    - - Cost: ${chatStore.cost.toFixed(4)} -

    -
  • -
-
-
-
{ - setShowSettings(true); - }} - > - {/* the long staus bar */} -
-
-
- -
-
Model
-
{chatStore.model}
-
- {models[chatStore.model]?.price?.prompt * 1000 * 1000} $/M - tokens -
-
-
-
- -
-
Mode
-
- {chatStore.streamMode ? Tr("STREAM") : Tr("FETCH")} -
-
STREAM/FETCH
-
+ -
-
- -
-
Tokens
-
- {chatStore.totalTokens} -
-
Max: {chatStore.maxTokens}
-
- -
-
- -
-
Cut
-
- {chatStore.postBeginIndex} -
-
- Max: {chatStore.history.filter(({ hide }) => !hide).length} -
-
- -
-
- -
-
Cost
-
- ${chatStore.cost.toFixed(4)} -
-
- Accumulated: ${getTotalCost().toFixed(2)} -
-
-
- - {/* the short status bar */} -
- {chatStore.totalTokens !== 0 && ( - - Tokens: {chatStore.totalTokens} - - )} - - - {chatStore.model} - -
-
-
- - -
-
{!chatStore.apiKey && (