Elffuss BraidHub

kikocis/continue public

b4db4cbf8943 · 4.3 KiBRawPermalink
1import { ArrowLeftIcon } from "@heroicons/react/24/outline";
2import { useContext, useEffect, useState } from "react";
3import { useNavigate } from "react-router-dom";
4import styled from "styled-components";
5import { table } from "table";
6import { lightGray, vscBackground, vscInputBackground } from "../components";
7import { CopyIconButton } from "../components/gui/CopyIconButton";
8import { IdeMessengerContext } from "../context/IdeMessenger";
9import { useNavigationListener } from "../hooks/useNavigationListener";
10
11const Th = styled.th`
12 padding: 0.5rem;
13 text-align: left;
14 border: 1px solid ${lightGray};
15`;
16
17const Tr = styled.tr`
18 &:hover {
19 background-color: ${vscInputBackground};
20 }
21
22 overflow-wrap: anywhere;
23
24 border: 1px solid ${lightGray};
25`;
26
27const Td = styled.td`
28 padding: 0.5rem;
29 border: 1px solid ${lightGray};
30`;
31
32function generateTable(data: unknown[][]) {
33 return table(data);
34}
35
36function Stats() {
37 useNavigationListener();
38 const navigate = useNavigate();
39 const ideMessenger = useContext(IdeMessengerContext);
40
41 const [days, setDays] = useState<
42 { day: string; promptTokens: number; generatedTokens: number }[]
43 >([]);
44 const [models, setModels] = useState<
45 { model: string; promptTokens: number; generatedTokens: number }[]
46 >([]);
47
48 useEffect(() => {
49 ideMessenger.request("stats/getTokensPerDay", undefined).then((result) => {
50 result.status === "success" && setDays(result.content);
51 });
52 }, []);
53
54 useEffect(() => {
55 ideMessenger
56 .request("stats/getTokensPerModel", undefined)
57 .then((result) => {
58 result.status === "success" && setModels(result.content);
59 });
60 }, []);
61
62 return (
63 <div
64 style={{
65 backgroundColor: vscBackground,
66 }}
67 >
68 <div
69 onClick={() => navigate(-1)}
70 className="sticky top-0 m-0 flex cursor-pointer items-center p-0"
71 style={{
72 borderBottom: `0.5px solid ${lightGray}`,
73 backgroundColor: vscBackground,
74 }}
75 >
76 <ArrowLeftIcon className="ml-4 inline-block h-3 w-3 cursor-pointer" />
77 <span className="m-2 inline-block text-base font-bold">More</span>
78 </div>
79
80 <div className="p-2">
81 <div className="flex items-center gap-2">
82 <h2 className="ml-2">Tokens per Day</h2>
83 <CopyIconButton
84 text={generateTable(
85 ([["Day", "Generated Tokens", "Prompt Tokens"]] as any).concat(
86 days.map((day) => [
87 day.day,
88 day.generatedTokens,
89 day.promptTokens,
90 ]),
91 ),
92 )}
93 />
94 </div>
95 <table className="w-full border-collapse">
96 <thead>
97 <Tr>
98 <Th>Day</Th>
99 <Th>Generated Tokens</Th>
100 <Th>Prompt Tokens</Th>
101 </Tr>
102 </thead>
103 <tbody>
104 {days.map((day) => (
105 <Tr key={day.day} className="">
106 <Td>{day.day}</Td>
107 <Td>{day.generatedTokens.toLocaleString()}</Td>
108 <Td>{day.promptTokens.toLocaleString()}</Td>
109 </Tr>
110 ))}
111 </tbody>
112 </table>
113
114 <div className="flex items-center gap-2">
115 <h2 className="ml-2">Tokens per Model</h2>
116 <CopyIconButton
117 text={generateTable(
118 ([["Model", "Generated Tokens", "Prompt Tokens"]] as any).concat(
119 models.map((model) => [
120 model.model,
121 model.generatedTokens.toLocaleString(),
122 model.promptTokens.toLocaleString(),
123 ]),
124 ),
125 )}
126 />
127 </div>
128 <table className="w-full border-collapse">
129 <thead>
130 <Tr>
131 <Th>Model</Th>
132 <Th>Generated Tokens</Th>
133 <Th>Prompt Tokens</Th>
134 </Tr>
135 </thead>
136 <tbody>
137 {models.map((model) => (
138 <Tr key={model.model} className="">
139 <Td>{model.model}</Td>
140 <Td>{model.generatedTokens.toLocaleString()}</Td>
141 <Td>{model.promptTokens.toLocaleString()}</Td>
142 </Tr>
143 ))}
144 </tbody>
145 </table>
146 </div>
147 </div>
148 );
149}
150
151export default Stats;