Skip to content

Commit

Permalink
Reverted the usage-store (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
tahierhussain authored Jun 3, 2024
1 parent 979b1b0 commit 3f86e97
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useSocketLogsStore } from "../../../store/socket-logs-store";
import { useSocketMessagesStore } from "../../../store/socket-messages-store";
import { useSocketCustomToolStore } from "../../../store/socket-custom-tool";
import { useSessionStore } from "../../../store/session-store";
import { useUsageStore } from "../../../store/usage-store";

function SocketMessages() {
const [logId, setLogId] = useState("");
Expand All @@ -23,6 +24,7 @@ function SocketMessages() {
const socket = useContext(SocketContext);
const { setAlertDetails } = useAlertStore();
const handleException = useExceptionHandler();
const { setLLMTokenUsage } = useUsageStore();

useEffect(() => {
setLogId(sessionDetails?.logEventsId || "");
Expand All @@ -44,6 +46,11 @@ function SocketMessages() {
if (msg?.type === "LOG" && msg?.service === "prompt") {
updateCusToolMessages(msg);
}
if (msg?.type === "LOG" && msg?.service === "usage") {
const remainingTokens =
msg?.max_token_count_set - msg?.added_token_count;
setLLMTokenUsage(Math.max(remainingTokens, 0));
}
} catch (err) {
setAlertDetails(handleException(err, "Failed to process socket message"));
}
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/store/usage-store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { create } from "zustand";

const useUsageStore = create((setState) => ({
llmTokenUsage: null,
setLLMTokenUsage: (data) => {
setState({ llmTokenUsage: data });
},
}));

export { useUsageStore };

0 comments on commit 3f86e97

Please sign in to comment.