From 55e8186479bd65dc007041449d78e5860c1e607d Mon Sep 17 00:00:00 2001 From: ecwu Date: Sun, 26 Jan 2025 21:15:34 +0000 Subject: [PATCH] feat: enhance MessageBubble with custom Markdown rendering, update Navbar layout, and integrate Search component in App --- src/components/MessageBubble.tsx | 30 ++++++- src/components/ModeToggle.tsx | 5 +- src/components/navbar.tsx | 132 ++++++++----------------------- src/pages/App.tsx | 7 +- src/pages/Chatbox.tsx | 3 +- 5 files changed, 75 insertions(+), 102 deletions(-) diff --git a/src/components/MessageBubble.tsx b/src/components/MessageBubble.tsx index d2c0d36..3dea99b 100644 --- a/src/components/MessageBubble.tsx +++ b/src/components/MessageBubble.tsx @@ -322,7 +322,35 @@ export default function Message(props: { messageIndex: number }) { ) : chat.role === "tool" ? ( ) : renderMarkdown ? ( - {getMessageText(chat)} +
+ ( + + {children} + + ), + pre: ({ children }) => ( +
+                        {children}
+                      
+ ), + a: ({ href, children }) => ( + + {children} + + ), + }} + > + {getMessageText(chat)} +
+
) : (
{chat.content && diff --git a/src/components/ModeToggle.tsx b/src/components/ModeToggle.tsx index 70cc101..a9b89ca 100644 --- a/src/components/ModeToggle.tsx +++ b/src/components/ModeToggle.tsx @@ -22,7 +22,10 @@ export function ModeToggle() { const { setTheme } = useTheme(); return ( - setTheme(value as Theme)} + defaultValue={useTheme().theme} + > diff --git a/src/components/navbar.tsx b/src/components/navbar.tsx index e379cb5..47740ab 100644 --- a/src/components/navbar.tsx +++ b/src/components/navbar.tsx @@ -32,112 +32,50 @@ import { getTotalCost } from "@/utils/totalCost"; import { Tr } from "@/translate"; import { useContext } from "react"; -import Search from "@/components/Search"; import Settings from "@/components/Settings"; +import APIListMenu from "./ListAPI"; const Navbar: React.FC = () => { const { chatStore, setChatStore } = useContext(AppChatStoreContext); return (
-
-
- - -

{chatStore.model}

-
-
-
- - {chatStore.totalTokens.toString()} - - - - - - -

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

-

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

-

- Cost: ${chatStore.cost?.toFixed(4)} / $ - {getTotalCost().toFixed(2)} -

-
-
-
-
- - - - {" "} - {chatStore.totalTokens} - - {chatStore.cost?.toFixed(4)} - - - - - Max Length: {chatStore.maxTokens} - - - - Price:{" "} - {models[chatStore.model]?.price?.prompt * - 1000 * - 1000}$ / 1M input tokens - - - - Total: {getTotalCost().toFixed( - 2 - )}$ - - - - {chatStore.streamMode ? ( - <> - {Tr("STREAM")}· - {Tr("FETCH")} - - ) : ( - <> - - {Tr("STREAM")} - - ·{Tr("FETCH")} - - )} - - - - { - chatStore.postBeginIndex - } / {chatStore.history.length} - - - - Switch to Model (TODO): - - gpt-4o - gpt-o1 - gpt-o1-mini - gpt-o3 - - - -
-
+
+
+
+ + +

{chatStore.model}

+
+
+
-
- - -
+ + + +
+ +
+
+ +
+
+ + + Generated Tokens: {chatStore.totalTokens.toString()} + +
+
+ + + Cost: ${getTotalCost().toFixed(2)} + +
+
+ +
+
); diff --git a/src/pages/App.tsx b/src/pages/App.tsx index 04c7984..6b22d71 100644 --- a/src/pages/App.tsx +++ b/src/pages/App.tsx @@ -89,6 +89,8 @@ import { import { useToast } from "@/hooks/use-toast"; import { ModeToggle } from "@/components/ModeToggle"; +import Search from "@/components/Search"; + import Navbar from "@/components/navbar"; export function App() { @@ -352,7 +354,10 @@ export function App() { - +
+ + +
diff --git a/src/pages/Chatbox.tsx b/src/pages/Chatbox.tsx index 9f40b6b..fa6ce9a 100644 --- a/src/pages/Chatbox.tsx +++ b/src/pages/Chatbox.tsx @@ -224,7 +224,7 @@ export default function ChatBOX() { token: data.usage?.completion_tokens_details ? data.usage.completion_tokens - data.usage.completion_tokens_details.reasoning_tokens - : (data.usage.completion_tokens ?? calculate_token_length(msg.content)), + : data.usage.completion_tokens ?? calculate_token_length(msg.content), example: false, audio: null, logprobs: data.choices[0]?.logprobs, @@ -414,7 +414,6 @@ export default function ChatBOX() { return ( <> -
{chatStore.history.length === 0 && (