You've already forked bilibili-subtitle
新增字幕提问功能
This commit is contained in:
@@ -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>
|
||||||
|
@@ -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
3
src/typings.d.ts
vendored
@@ -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
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user