From 7a03d37c615325bb98f19230153c0af09c43bf65 Mon Sep 17 00:00:00 2001 From: IndieKKY Date: Mon, 18 Mar 2024 11:36:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=AD=97=E5=B9=95=E6=8F=90?= =?UTF-8?q?=E9=97=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/biz/Settings.tsx | 9 +++++---- src/const.tsx | 2 +- src/hooks/useSubtitleService.ts | 20 ++++++++++++++++++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/biz/Settings.tsx b/src/biz/Settings.tsx index 9bbced1..c98d4c9 100644 --- a/src/biz/Settings.tsx +++ b/src/biz/Settings.tsx @@ -3,6 +3,7 @@ import {setEnvData, setPage} from '../redux/envReducer' import {useAppDispatch, useAppSelector} from '../hooks/redux' import { ASK_ENABLED_DEFAULT, + GEMINI_TOKENS, HEADER_HEIGHT, LANGUAGE_DEFAULT, LANGUAGES, @@ -18,7 +19,7 @@ import { TRANSLATE_FETCH_MAX, TRANSLATE_FETCH_MIN, TRANSLATE_FETCH_STEP, - WORDS_DEFAULT, + WORDS_RATE, } from '../const' import {IoWarning} from 'react-icons/all' import classNames from 'classnames' @@ -75,7 +76,7 @@ const Settings = () => { const [fontSizeValue, setFontSizeValue] = useState(envData.fontSize) const [aiTypeValue, setAiTypeValue] = useState(envData.aiType) const [transDisplayValue, setTransDisplayValue] = useState(envData.transDisplay) - const [wordsValue, setWordsValue] = useState(envData.words??WORDS_DEFAULT) + const [wordsValue, setWordsValue] = useState(envData.words) const [fetchAmountValue, setFetchAmountValue] = useState(envData.fetchAmount??TRANSLATE_FETCH_DEFAULT) const [moreFold, {toggle: toggleMoreFold}] = useBoolean(true) const [promptsFold, {toggle: togglePromptsFold}] = useBoolean(true) @@ -367,7 +368,7 @@ const Settings = () => {
- setWordsValue(e.target.value?parseInt(e.target.value):undefined)}/> + setWordsValue(e.target.value?parseInt(e.target.value):undefined)}/> {/* */} {/*
*/} {/* {wordsList.map(words => {words})} */} @@ -375,7 +376,7 @@ const Settings = () => {
- 当前选择的模型的分段字数上限是{MODEL_MAP[modelValue??MODEL_DEFAULT]?.tokens??'未知'} + 当前选择的模型的分段字数上限是{aiTypeValue === 'gemini'?GEMINI_TOKENS:(MODEL_MAP[modelValue??MODEL_DEFAULT]?.tokens??'未知')} (太接近上限总结会报错)
diff --git a/src/const.tsx b/src/const.tsx index c704b6a..d1581c5 100644 --- a/src/const.tsx +++ b/src/const.tsx @@ -160,7 +160,7 @@ export const HEADER_HEIGHT = 44 export const TITLE_HEIGHT = 24 export const SEARCH_BAR_HEIGHT = 32 -export const WORDS_DEFAULT = import.meta.env.VITE_ENV === 'web-dev'?500:10000 +export const WORDS_RATE = 0.75 export const WORDS_MIN = 500 export const WORDS_MAX = 16000 export const WORDS_STEP = 500 diff --git a/src/hooks/useSubtitleService.ts b/src/hooks/useSubtitleService.ts index 04ebd5c..96fc1ed 100644 --- a/src/hooks/useSubtitleService.ts +++ b/src/hooks/useSubtitleService.ts @@ -14,7 +14,16 @@ import { setTotalHeight, } from '../redux/envReducer' import {EventBusContext} from '../Router' -import {EVENT_EXPAND, TOTAL_HEIGHT_MAX, TOTAL_HEIGHT_MIN, WORDS_DEFAULT, WORDS_MIN} from '../const' +import { + EVENT_EXPAND, + GEMINI_TOKENS, + MODEL_DEFAULT, + MODEL_MAP, + TOTAL_HEIGHT_MAX, + TOTAL_HEIGHT_MIN, + WORDS_MIN, + WORDS_RATE +} from '../const' import {useInterval} from 'ahooks' import {getWholeText} from '../util/biz_util' @@ -156,7 +165,14 @@ const useSubtitleService = () => { const items = data?.body if (items != null) { if (envData.summarizeEnable) { // 分段 - let size = envData.words??WORDS_DEFAULT + let size = envData.words + if (!size) { // 默认 + if (envData.aiType === 'gemini') { + size = GEMINI_TOKENS*WORDS_RATE + } else { + size = (MODEL_MAP[envData.model??MODEL_DEFAULT]?.tokens??4000)*WORDS_RATE + } + } size = Math.max(size, WORDS_MIN) segments = []