新增字幕提问功能

This commit is contained in:
IndieKKY
2024-03-18 11:36:30 +08:00
parent a86ba9e09f
commit 7a03d37c61
3 changed files with 24 additions and 7 deletions

View File

@@ -3,6 +3,7 @@ import {setEnvData, setPage} from '../redux/envReducer'
import {useAppDispatch, useAppSelector} from '../hooks/redux' import {useAppDispatch, useAppSelector} from '../hooks/redux'
import { import {
ASK_ENABLED_DEFAULT, ASK_ENABLED_DEFAULT,
GEMINI_TOKENS,
HEADER_HEIGHT, HEADER_HEIGHT,
LANGUAGE_DEFAULT, LANGUAGE_DEFAULT,
LANGUAGES, LANGUAGES,
@@ -18,7 +19,7 @@ import {
TRANSLATE_FETCH_MAX, TRANSLATE_FETCH_MAX,
TRANSLATE_FETCH_MIN, TRANSLATE_FETCH_MIN,
TRANSLATE_FETCH_STEP, TRANSLATE_FETCH_STEP,
WORDS_DEFAULT, WORDS_RATE,
} from '../const' } from '../const'
import {IoWarning} from 'react-icons/all' import {IoWarning} from 'react-icons/all'
import classNames from 'classnames' import classNames from 'classnames'
@@ -75,7 +76,7 @@ const Settings = () => {
const [fontSizeValue, setFontSizeValue] = useState(envData.fontSize) const [fontSizeValue, setFontSizeValue] = useState(envData.fontSize)
const [aiTypeValue, setAiTypeValue] = useState(envData.aiType) const [aiTypeValue, setAiTypeValue] = useState(envData.aiType)
const [transDisplayValue, setTransDisplayValue] = useState(envData.transDisplay) const [transDisplayValue, setTransDisplayValue] = useState(envData.transDisplay)
const [wordsValue, setWordsValue] = useState<number | undefined>(envData.words??WORDS_DEFAULT) const [wordsValue, setWordsValue] = useState<number | undefined>(envData.words)
const [fetchAmountValue, setFetchAmountValue] = useState(envData.fetchAmount??TRANSLATE_FETCH_DEFAULT) const [fetchAmountValue, setFetchAmountValue] = useState(envData.fetchAmount??TRANSLATE_FETCH_DEFAULT)
const [moreFold, {toggle: toggleMoreFold}] = useBoolean(true) const [moreFold, {toggle: toggleMoreFold}] = useBoolean(true)
const [promptsFold, {toggle: togglePromptsFold}] = useBoolean(true) const [promptsFold, {toggle: togglePromptsFold}] = useBoolean(true)
@@ -367,7 +368,7 @@ const Settings = () => {
</FormItem> </FormItem>
<FormItem htmlFor='words' title='分段字数' tip='注意,不同模型有不同字数限制'> <FormItem htmlFor='words' title='分段字数' tip='注意,不同模型有不同字数限制'>
<div className='flex-1 flex flex-col'> <div className='flex-1 flex flex-col'>
<input id='words' type='number' className='input input-sm input-bordered w-full' placeholder='默认2000' value={wordsValue} onChange={e => setWordsValue(e.target.value?parseInt(e.target.value):undefined)}/> <input id='words' type='number' className='input input-sm input-bordered w-full' placeholder={`默认为上限x${WORDS_RATE}`} value={wordsValue??''} onChange={e => setWordsValue(e.target.value?parseInt(e.target.value):undefined)}/>
{/* <input type="range" min={WORDS_MIN} max={WORDS_MAX} step={WORDS_STEP} value={wordsValue} className="range range-primary" onChange={onWordsChange} /> */} {/* <input type="range" min={WORDS_MIN} max={WORDS_MAX} step={WORDS_STEP} value={wordsValue} className="range range-primary" onChange={onWordsChange} /> */}
{/* <div className="w-full flex justify-between text-xs px-2"> */} {/* <div className="w-full flex justify-between text-xs px-2"> */}
{/* {wordsList.map(words => <span key={words}>{words}</span>)} */} {/* {wordsList.map(words => <span key={words}>{words}</span>)} */}
@@ -375,7 +376,7 @@ const Settings = () => {
</div> </div>
</FormItem> </FormItem>
<div className='desc text-xs'> <div className='desc text-xs'>
<span className='font-semibold font-mono'>{MODEL_MAP[modelValue??MODEL_DEFAULT]?.tokens??'未知'}</span> <span className='font-semibold font-mono'>{aiTypeValue === 'gemini'?GEMINI_TOKENS:(MODEL_MAP[modelValue??MODEL_DEFAULT]?.tokens??'未知')}</span>
</div> </div>
</Section> </Section>

View File

@@ -160,7 +160,7 @@ export const HEADER_HEIGHT = 44
export const TITLE_HEIGHT = 24 export const TITLE_HEIGHT = 24
export const SEARCH_BAR_HEIGHT = 32 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_MIN = 500
export const WORDS_MAX = 16000 export const WORDS_MAX = 16000
export const WORDS_STEP = 500 export const WORDS_STEP = 500

View File

@@ -14,7 +14,16 @@ import {
setTotalHeight, setTotalHeight,
} from '../redux/envReducer' } from '../redux/envReducer'
import {EventBusContext} from '../Router' 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 {useInterval} from 'ahooks'
import {getWholeText} from '../util/biz_util' import {getWholeText} from '../util/biz_util'
@@ -156,7 +165,14 @@ const useSubtitleService = () => {
const items = data?.body const items = data?.body
if (items != null) { if (items != null) {
if (envData.summarizeEnable) { // 分段 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) size = Math.max(size, WORDS_MIN)
segments = [] segments = []