mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-11-16 22:13:47 +08:00
refactor: refactor token counting logic in countTokens function
This commit is contained in:
@@ -19,7 +19,7 @@ import {
|
||||
StoreKey,
|
||||
} from "../constant";
|
||||
import Locale, { getLang } from "../locales";
|
||||
import { isDalle3, safeLocalStorage } from "../utils";
|
||||
import { isDalle3, safeLocalStorage, readFileContent } from "../utils";
|
||||
import { prettyObject } from "../utils/format";
|
||||
import { createPersistStore } from "../utils/store";
|
||||
import { estimateTokenLength } from "../utils/token";
|
||||
@@ -154,23 +154,6 @@ function fillTemplateWith(input: string, modelConfig: ModelConfig) {
|
||||
return output;
|
||||
}
|
||||
|
||||
const readFileContent = async (file: UploadFile): Promise<string> => {
|
||||
try {
|
||||
const response = await fetch(file.url);
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to fetch content from ${file.url}: ${response.statusText}`,
|
||||
);
|
||||
}
|
||||
const content = await response.text();
|
||||
const result = file.name + "\n" + content;
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error("Error reading file content:", error);
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
const DEFAULT_CHAT_STATE = {
|
||||
sessions: [createEmptySession()],
|
||||
currentSessionIndex: 0,
|
||||
|
||||
Reference in New Issue
Block a user