Skip to content

Commit

Permalink
total cost of deleted state but no logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jackschedel committed Feb 9, 2024
1 parent 0bc2178 commit 8c1edd4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/components/SettingsMenu/TotalTokenCost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,16 @@ export const TotalTokenCostDisplay = () => {
const totalTokenUsed = useStore((state) => state.totalTokenUsed);

const [totalCost, setTotalCost] = useState<number>(0);
const modelDefs = useStore((state) => state.modelDefs);
const costOfDeleted = useStore((state) => state.costOfDeleted);

useEffect(() => {
let updatedTotalCost = 0;
let updatedTotalCost = costOfDeleted;

Object.entries(totalTokenUsed).forEach(([key, tokenCost]) => {
const model = parseInt(key, 10);
if (!isNaN(model)) {
updatedTotalCost += tokenCostToCost(tokenCost, model);
updatedTotalCost += tokenCostToCost(tokenCost, model, modelDefs);
}
});

Expand Down
9 changes: 9 additions & 0 deletions src/store/config-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface ConfigSlice {
markdownMode: boolean;
countTotalTokens: boolean;
totalTokenUsed: TotalTokenUsed;
costOfDeleted: number;
setOpenConfig: (openConfig: boolean) => void;
setTheme: (theme: Theme) => void;
setAutoTitle: (autoTitle: boolean) => void;
Expand All @@ -34,6 +35,7 @@ export interface ConfigSlice {
setMarkdownMode: (markdownMode: boolean) => void;
setCountTotalTokens: (countTotalTokens: boolean) => void;
setTotalTokenUsed: (totalTokenUsed: TotalTokenUsed) => void;
setCostOfDeleted: (costOfDeleted: number) => void;
}

export const createConfigSlice: StoreSlice<ConfigSlice> = (set) => ({
Expand All @@ -52,6 +54,7 @@ export const createConfigSlice: StoreSlice<ConfigSlice> = (set) => ({
markdownMode: true,
countTotalTokens: false,
totalTokenUsed: {},
costOfDeleted: 0,
setOpenConfig: (openConfig: boolean) => {
set((prev: ConfigSlice) => ({
...prev,
Expand Down Expand Up @@ -142,4 +145,10 @@ export const createConfigSlice: StoreSlice<ConfigSlice> = (set) => ({
totalTokenUsed: totalTokenUsed,
}));
},
setCostOfDeleted: (costOfDeleted: number) => {
set((prev: ConfigSlice) => ({
...prev,
costOfDeleted: costOfDeleted,
}));
},
});

0 comments on commit 8c1edd4

Please sign in to comment.