新增字幕提问功能

This commit is contained in:
IndieKKY
2024-03-17 21:17:40 +08:00
parent 0881312025
commit d6d7e17f84
3 changed files with 31 additions and 4 deletions

View File

@@ -2,10 +2,12 @@ import React, {PropsWithChildren, useCallback, useMemo, useState} from 'react'
import {setEnvData, setPage} from '../redux/envReducer' import {setEnvData, setPage} from '../redux/envReducer'
import {useAppDispatch, useAppSelector} from '../hooks/redux' import {useAppDispatch, useAppSelector} from '../hooks/redux'
import { import {
ASK_ENABLED_DEFAULT,
HEADER_HEIGHT, HEADER_HEIGHT,
LANGUAGE_DEFAULT, LANGUAGE_DEFAULT,
LANGUAGES, LANGUAGES,
MODEL_DEFAULT, MODEL_DEFAULT,
MODEL_MAP,
MODELS, MODELS,
PAGE_MAIN, PAGE_MAIN,
PROMPT_DEFAULTS, PROMPT_DEFAULTS,
@@ -59,6 +61,7 @@ const Settings = () => {
const {value: translateEnableValue, onChange: setTranslateEnableValue} = useEventChecked(envData.translateEnable) const {value: translateEnableValue, onChange: setTranslateEnableValue} = useEventChecked(envData.translateEnable)
const {value: summarizeEnableValue, onChange: setSummarizeEnableValue} = useEventChecked(envData.summarizeEnable) const {value: summarizeEnableValue, onChange: setSummarizeEnableValue} = useEventChecked(envData.summarizeEnable)
const {value: searchEnabledValue, onChange: setSearchEnabledValue} = useEventChecked(envData.searchEnabled) const {value: searchEnabledValue, onChange: setSearchEnabledValue} = useEventChecked(envData.searchEnabled)
const {value: askEnabledValue, onChange: setAskEnabledValue} = useEventChecked(envData.askEnabled??ASK_ENABLED_DEFAULT)
const {value: cnSearchEnabledValue, onChange: setCnSearchEnabledValue} = useEventChecked(envData.cnSearchEnabled) const {value: cnSearchEnabledValue, onChange: setCnSearchEnabledValue} = useEventChecked(envData.cnSearchEnabled)
const {value: summarizeFloatValue, onChange: setSummarizeFloatValue} = useEventChecked(envData.summarizeFloat) const {value: summarizeFloatValue, onChange: setSummarizeFloatValue} = useEventChecked(envData.summarizeFloat)
const [apiKeyValue, { onChange: onChangeApiKeyValue }] = useEventTarget({initialValue: envData.apiKey??''}) const [apiKeyValue, { onChange: onChangeApiKeyValue }] = useEventTarget({initialValue: envData.apiKey??''})
@@ -126,10 +129,11 @@ const Settings = () => {
prompts: promptsValue, prompts: promptsValue,
searchEnabled: searchEnabledValue, searchEnabled: searchEnabledValue,
cnSearchEnabled: cnSearchEnabledValue, cnSearchEnabled: cnSearchEnabledValue,
askEnabled: askEnabledValue,
})) }))
dispatch(setPage(PAGE_MAIN)) dispatch(setPage(PAGE_MAIN))
toast.success('保存成功') toast.success('保存成功')
}, [dispatch, aiTypeValue, geminiApiKeyValue, autoExpandValue, apiKeyValue, serverUrlValue, modelValue, translateEnableValue, languageValue, hideOnDisableAutoTranslateValue, themeValue, transDisplayValue, summarizeEnableValue, summarizeFloatValue, summarizeLanguageValue, wordsValue, fetchAmountValue, fontSizeValue, promptsValue, searchEnabledValue, cnSearchEnabledValue]) }, [dispatch, autoExpandValue, aiTypeValue, apiKeyValue, serverUrlValue, modelValue, geminiApiKeyValue, translateEnableValue, languageValue, hideOnDisableAutoTranslateValue, themeValue, transDisplayValue, summarizeEnableValue, summarizeFloatValue, summarizeLanguageValue, wordsValue, fetchAmountValue, fontSizeValue, promptsValue, searchEnabledValue, cnSearchEnabledValue, askEnabledValue])
const onCancel = useCallback(() => { const onCancel = useCallback(() => {
dispatch(setPage(PAGE_MAIN)) dispatch(setPage(PAGE_MAIN))
@@ -237,7 +241,7 @@ const Settings = () => {
<li></li> <li></li>
</ul> </ul>
</div>} </div>}
<FormItem title='模型选择' htmlFor='modelSel' tip='注意,不同模型有不同价格'> <FormItem title='模型选择' htmlFor='modelSel' tip='注意,不同模型有不同价格与token限制'>
<select id='modelSel' className="select select-sm select-bordered" value={modelValue} onChange={onChangeModelValue}> <select id='modelSel' className="select select-sm select-bordered" value={modelValue} onChange={onChangeModelValue}>
{MODELS.map(model => <option key={model.code} value={model.code}>{model.name}</option>)} {MODELS.map(model => <option key={model.code} value={model.code}>{model.name}</option>)}
</select> </select>
@@ -370,6 +374,10 @@ const Settings = () => {
{/* </div> */} {/* </div> */}
</div> </div>
</FormItem> </FormItem>
<div className='desc text-xs'>
<span className='font-semibold font-mono'>{MODEL_MAP[modelValue??MODEL_DEFAULT]?.tokens??'未知'}</span>
</div>
</Section> </Section>
<Section title={<div className='flex items-center'> <Section title={<div className='flex items-center'>
@@ -383,6 +391,15 @@ const Settings = () => {
onChange={setCnSearchEnabledValue}/> onChange={setCnSearchEnabledValue}/>
</FormItem> </FormItem>
</Section> </Section>
<Section title={<div className='flex items-center'>
</div>}>
<FormItem title='启用提问' htmlFor='askEnabled' tip='是否启用字幕提问功能'>
<input id='askEnabled' type='checkbox' className='toggle toggle-primary' checked={askEnabledValue}
onChange={setAskEnabledValue}/>
</FormItem>
<div className='desc text-xs'><span className='font-semibold font-mono'>Enter</span></div>
</Section>
<div className='flex justify-center gap-5'> <div className='flex justify-center gap-5'>
<button className='btn btn-primary btn-sm' onClick={onSave}></button> <button className='btn btn-primary btn-sm' onClick={onSave}></button>
<button className='btn btn-sm' onClick={onCancel}></button> <button className='btn btn-sm' onClick={onCancel}></button>

View File

@@ -143,28 +143,35 @@ 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:2000 export const WORDS_DEFAULT = import.meta.env.VITE_ENV === 'web-dev'?500:10000
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
export const SUMMARIZE_THRESHOLD = 100 export const SUMMARIZE_THRESHOLD = 100
export const SUMMARIZE_LANGUAGE_DEFAULT = 'cn' export const SUMMARIZE_LANGUAGE_DEFAULT = 'cn'
export const SUMMARIZE_ALL_THRESHOLD = 5 export const SUMMARIZE_ALL_THRESHOLD = 5
export const ASK_ENABLED_DEFAULT = true
export const SERVER_URL_OPENAI = 'https://api.openai.com' export const SERVER_URL_OPENAI = 'https://api.openai.com'
export const SERVER_URL_THIRD = 'https://op.kongkongye.com' export const SERVER_URL_THIRD = 'https://op.kongkongye.com'
export const MODELS = [{ export const MODELS = [{
code: 'gpt-3.5-turbo', code: 'gpt-3.5-turbo',
name: 'gpt-3.5-turbo', name: 'gpt-3.5-turbo',
tokens: 16385,
}, { }, {
code: 'gpt-3.5-turbo-0125', code: 'gpt-3.5-turbo-0125',
name: 'gpt-3.5-turbo-0125', name: 'gpt-3.5-turbo-0125',
tokens: 16385,
}, { }, {
code: 'gpt-3.5-turbo-1106', code: 'gpt-3.5-turbo-1106',
name: 'gpt-3.5-turbo-1106', name: 'gpt-3.5-turbo-1106',
tokens: 16385,
}] }]
export const MODEL_DEFAULT = MODELS[0].code export const MODEL_DEFAULT = MODELS[0].code
export const MODEL_MAP: {[key: string]: typeof MODELS[number]} = {}
for (const model of MODELS) {
MODEL_MAP[model.code] = model
}
export const LANGUAGES = [{ export const LANGUAGES = [{
code: 'en', code: 'en',

3
src/typings.d.ts vendored
View File

@@ -26,6 +26,9 @@ interface EnvData {
searchEnabled?: boolean searchEnabled?: boolean
cnSearchEnabled?: boolean cnSearchEnabled?: boolean
// ask
askEnabled?: boolean
prompts?: { prompts?: {
[key: string]: string [key: string]: string
} }