((res, rej) => {
+ setUploading(true);
+ const imagesData: string[] = [];
+ compressImage(file, 256 * 1024)
+ .then((dataUrl) => {
+ imagesData.push(dataUrl);
+ setUploading(false);
+ res(imagesData);
+ })
+ .catch((e) => {
+ setUploading(false);
+ rej(e);
+ });
+ })),
+ );
+ const imagesLength = images.length;
+
+ if (imagesLength > 3) {
+ images.splice(3, imagesLength - 3);
+ }
+ setAttachImages(images);
+ }
+ }
+ }
+ },
+ [attachImages, chatStore],
+ );
+
async function uploadImage() {
const images: string[] = [];
images.push(...attachImages);
@@ -1211,6 +1274,10 @@ function _Chat() {
{Locale.Chat.SubTitle(session.messages.length)}
+
+ 当天使用:
+ {localStorage.getItem("current_day_token") ?? 0}
+
@@ -1589,6 +1656,7 @@ function _Chat() {
onKeyDown={onInputKeyDown}
onFocus={scrollToBottom}
onClick={scrollToBottom}
+ onPaste={handlePaste}
rows={inputRows}
autoFocus={autoFocus}
style={{
@@ -1643,8 +1711,45 @@ function _Chat() {
);
}
+function getCurrentDayToken(sessions: ChatSession[]): number {
+ try {
+ const currentTime = new Date();
+ const startOfTheDayInTimeZone = new Date(
+ currentTime.getFullYear(),
+ currentTime.getMonth(),
+ currentTime.getDate(),
+ 0,
+ 0,
+ 0,
+ );
+ const current_day_message = sessions
+ .reduce((acc, item) => {
+ // @ts-ignore
+ return acc.concat(item.messages);
+ }, [])
+ .filter((item1) => {
+ // @ts-ignore
+ const dateToCheck = new Date(item1.date);
+ return startOfTheDayInTimeZone < dateToCheck;
+ });
+ const all_current_day_content = current_day_message
+ // @ts-ignore
+ .map((item) => item.content)
+ .join(" ");
+ // 获取会话之后,再整合content,
+ return getTokenLength(all_current_day_content);
+ } catch (e) {
+ return 0;
+ }
+}
+
export function Chat() {
const chatStore = useChatStore();
const sessionIndex = chatStore.currentSessionIndex;
+ // 这里计先计算一下当天总token数。
+ localStorage.setItem(
+ "current_day_token",
+ String(getCurrentDayToken(chatStore.sessions)),
+ );
return <_Chat key={sessionIndex}>;
}
diff --git a/app/utils/token.ts b/app/utils/token.ts
index 1e803408c..6ff0f5df2 100644
--- a/app/utils/token.ts
+++ b/app/utils/token.ts
@@ -23,19 +23,19 @@ export function estimateTokenLength(input: string): number {
// import { get_encoding } from "tiktoken";
-export function getTokenLength(input: string): number {
- // const { get_encoding } = require( "tiktoken" );
- // const encoding = get_encoding("cl100k_base");
-
- const { Tiktoken } = require("tiktoken/lite");
- const cl100k_base = require("tiktoken/encoders/cl100k_base.json");
- const encoding = new Tiktoken(
- cl100k_base.bpe_ranks,
- cl100k_base.special_tokens,
- cl100k_base.pat_str,
- );
- const tokenLength = encoding.encode(input).length;
- // console.log('[TOKEN],=========', input, tokenLength)
-
- return tokenLength;
-}
+// export function getTokenLength(input: string): number {
+// // const { get_encoding } = require( "tiktoken" );
+// // const encoding = get_encoding("cl100k_base");
+//
+// const { Tiktoken } = require("tiktoken/lite");
+// const cl100k_base = require("tiktoken/encoders/cl100k_base.json");
+// const encoding = new Tiktoken(
+// cl100k_base.bpe_ranks,
+// cl100k_base.special_tokens,
+// cl100k_base.pat_str,
+// );
+// const tokenLength = encoding.encode(input).length;
+// // console.log('[TOKEN],=========', input, tokenLength)
+//
+// return tokenLength;
+// }
diff --git a/lib/auth_list.ts b/lib/auth_list.ts
index 27d7616cc..c28ea6df2 100644
--- a/lib/auth_list.ts
+++ b/lib/auth_list.ts
@@ -4,7 +4,8 @@ export const DENY_LIST: string[] = [
]
export const ADMIN_LIST: string[] = [
"司金辉", "sijinhui", "sijinhui@qq.com",
- "yuchuan", "于川"
+ "yuchuan", "于川",
+ "jujujujuju",
]
diff --git a/lib/utils.ts b/lib/utils.ts
index f43cf2645..c2c0e3fad 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -1,9 +1,13 @@
-// import { clsx, type ClassValue } from "clsx";
-import { twMerge } from "tailwind-merge";
-// export function cn(...inputs: ClassValue[]) {
-// return twMerge(clsx(inputs));
-// }
+import {get_encoding} from "tiktoken";
+
+
+export function getTokenLength(input: string): number {
+ const encoding = get_encoding("cl100k_base");
+ // console.log('tokens: ', input, encoding.countTokens())
+ return encoding.encode(input).length;
+}
+
export async function fetcher(
input: RequestInfo,
init?: RequestInit,
diff --git a/public/grinning-face.webp b/public/grinning-face.webp
new file mode 100644
index 000000000..6e350846a
Binary files /dev/null and b/public/grinning-face.webp differ