增加模型选择

This commit is contained in:
IndieKKY
2023-06-16 10:41:32 +08:00
parent 8c8d5bf4e1
commit 7c51471d91
6 changed files with 32 additions and 11 deletions

View File

@@ -1,7 +1,7 @@
{ {
"name": "哔哩哔哩字幕列表", "name": "哔哩哔哩字幕列表",
"description": "显示B站视频的字幕列表,可点击跳转与下载字幕,并支持翻译和总结字幕!", "description": "显示B站视频的字幕列表,可点击跳转与下载字幕,并支持翻译和总结字幕!",
"version": "1.7.1", "version": "1.7.2",
"manifest_version": 3, "manifest_version": 3,
"permissions": [ "permissions": [
"storage" "storage"

View File

@@ -1,7 +1,7 @@
{ {
"private": true, "private": true,
"name": "bilibili-subtitle", "name": "bilibili-subtitle",
"version": "1.7.1", "version": "1.7.2",
"type": "module", "type": "module",
"description": "哔哩哔哩字幕列表", "description": "哔哩哔哩字幕列表",
"main": "index.js", "main": "index.js",

View File

@@ -5,6 +5,8 @@ import {
HEADER_HEIGHT, HEADER_HEIGHT,
LANGUAGE_DEFAULT, LANGUAGE_DEFAULT,
LANGUAGES, LANGUAGES,
MODEL_DEFAULT,
MODELS,
PAGE_MAIN, PAGE_MAIN,
PROMPT_DEFAULTS, PROMPT_DEFAULTS,
PROMPT_TYPES, PROMPT_TYPES,
@@ -63,12 +65,13 @@ const Settings = () => {
const [apiKeyValue, { onChange: onChangeApiKeyValue }] = useEventTarget({initialValue: envData.apiKey??''}) const [apiKeyValue, { onChange: onChangeApiKeyValue }] = useEventTarget({initialValue: envData.apiKey??''})
const [serverUrlValue, setServerUrlValue] = useState(envData.serverUrl) const [serverUrlValue, setServerUrlValue] = useState(envData.serverUrl)
const [languageValue, { onChange: onChangeLanguageValue }] = useEventTarget({initialValue: envData.language??LANGUAGE_DEFAULT}) const [languageValue, { onChange: onChangeLanguageValue }] = useEventTarget({initialValue: envData.language??LANGUAGE_DEFAULT})
const [modelValue, { onChange: onChangeModelValue }] = useEventTarget({initialValue: envData.model??MODEL_DEFAULT})
const [summarizeLanguageValue, { onChange: onChangeSummarizeLanguageValue }] = useEventTarget({initialValue: envData.summarizeLanguage??SUMMARIZE_LANGUAGE_DEFAULT}) const [summarizeLanguageValue, { onChange: onChangeSummarizeLanguageValue }] = useEventTarget({initialValue: envData.summarizeLanguage??SUMMARIZE_LANGUAGE_DEFAULT})
const [hideOnDisableAutoTranslateValue, setHideOnDisableAutoTranslateValue] = useState(envData.hideOnDisableAutoTranslate) const [hideOnDisableAutoTranslateValue, setHideOnDisableAutoTranslateValue] = useState(envData.hideOnDisableAutoTranslate)
const [themeValue, setThemeValue] = useState(envData.theme) const [themeValue, setThemeValue] = useState(envData.theme)
const [fontSizeValue, setFontSizeValue] = useState(envData.fontSize) const [fontSizeValue, setFontSizeValue] = useState(envData.fontSize)
const [transDisplayValue, setTransDisplayValue] = useState(envData.transDisplay) const [transDisplayValue, setTransDisplayValue] = useState(envData.transDisplay)
const [wordsValue, setWordsValue] = useState(envData.words??WORDS_DEFAULT) const [wordsValue, setWordsValue] = useState<number | undefined>(envData.words??WORDS_DEFAULT)
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)
@@ -99,6 +102,7 @@ const Settings = () => {
autoExpand: autoExpandValue, autoExpand: autoExpandValue,
apiKey: apiKeyValue, apiKey: apiKeyValue,
serverUrl: serverUrlValue, serverUrl: serverUrlValue,
model: modelValue,
translateEnable: translateEnableValue, translateEnable: translateEnableValue,
language: languageValue, language: languageValue,
hideOnDisableAutoTranslate: hideOnDisableAutoTranslateValue, hideOnDisableAutoTranslate: hideOnDisableAutoTranslateValue,
@@ -114,7 +118,7 @@ const Settings = () => {
})) }))
dispatch(setPage(PAGE_MAIN)) dispatch(setPage(PAGE_MAIN))
toast.success('保存成功') toast.success('保存成功')
}, [promptsValue, fontSizeValue, apiKeyValue, autoExpandValue, dispatch, fetchAmountValue, hideOnDisableAutoTranslateValue, languageValue, serverUrlValue, summarizeEnableValue, summarizeFloatValue, summarizeLanguageValue, themeValue, transDisplayValue, translateEnableValue, wordsValue]) }, [modelValue, promptsValue, fontSizeValue, apiKeyValue, autoExpandValue, dispatch, fetchAmountValue, hideOnDisableAutoTranslateValue, languageValue, serverUrlValue, summarizeEnableValue, summarizeFloatValue, summarizeLanguageValue, themeValue, transDisplayValue, translateEnableValue, wordsValue])
const onCancel = useCallback(() => { const onCancel = useCallback(() => {
dispatch(setPage(PAGE_MAIN)) dispatch(setPage(PAGE_MAIN))
@@ -207,6 +211,11 @@ const Settings = () => {
<li></li> <li></li>
</ul> </ul>
</div>} </div>}
<FormItem title='模型选择' htmlFor='modelSel' tip='注意,不同模型有不同价格'>
<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>)}
</select>
</FormItem>
<div className='flex justify-center'> <div className='flex justify-center'>
<a className='link text-xs' onClick={togglePromptsFold}>{promptsFold?'点击查看提示词':'点击折叠提示词'}</a> <a className='link text-xs' onClick={togglePromptsFold}>{promptsFold?'点击查看提示词':'点击折叠提示词'}</a>
</div> </div>
@@ -284,12 +293,13 @@ const Settings = () => {
{LANGUAGES.map(language => <option key={language.code} value={language.code}>{language.name}</option>)} {LANGUAGES.map(language => <option key={language.code} value={language.code}>{language.name}</option>)}
</select> </select>
</FormItem> </FormItem>
<FormItem title='分段字数'> <FormItem htmlFor='words' title='分段字数' tip='注意,不同模型有不同字数限制'>
<div className='flex-1 flex flex-col'> <div className='flex-1 flex flex-col'>
<input type="range" min={WORDS_MIN} max={WORDS_MAX} step={WORDS_STEP} value={wordsValue} className="range range-primary" onChange={onWordsChange} /> <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)}/>
<div className="w-full flex justify-between text-xs px-2"> {/* <input type="range" min={WORDS_MIN} max={WORDS_MAX} step={WORDS_STEP} value={wordsValue} className="range range-primary" onChange={onWordsChange} /> */}
{wordsList.map(words => <span key={words}>{words}</span>)} {/* <div className="w-full flex justify-between text-xs px-2"> */}
</div> {/* {wordsList.map(words => <span key={words}>{words}</span>)} */}
{/* </div> */}
</div> </div>
</FormItem> </FormItem>
</Section> </Section>

View File

@@ -153,6 +153,15 @@ export const SUMMARIZE_ALL_THRESHOLD = 5
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 = [{
code: 'gpt-3.5-turbo',
name: 'gpt-3.5-turbo',
}, {
code: 'gpt-3.5-turbo-16k',
name: 'gpt-3.5-turbo-16k',
}]
export const MODEL_DEFAULT = MODELS[0].code
export const LANGUAGES = [{ export const LANGUAGES = [{
code: 'en', code: 'en',
name: 'English', name: 'English',

View File

@@ -13,6 +13,7 @@ import {
import { import {
LANGUAGE_DEFAULT, LANGUAGE_DEFAULT,
LANGUAGES_MAP, LANGUAGES_MAP,
MODEL_DEFAULT,
PROMPT_DEFAULTS, PROMPT_DEFAULTS,
PROMPT_TYPE_TRANSLATE, PROMPT_TYPE_TRANSLATE,
SUMMARIZE_LANGUAGE_DEFAULT, SUMMARIZE_LANGUAGE_DEFAULT,
@@ -84,7 +85,7 @@ const useTranslate = () => {
type: 'chatComplete', type: 'chatComplete',
serverUrl: envData.serverUrl, serverUrl: envData.serverUrl,
data: { data: {
model: 'gpt-3.5-turbo', model: envData.model??MODEL_DEFAULT,
messages: [ messages: [
{ {
role: 'user', role: 'user',
@@ -137,7 +138,7 @@ const useTranslate = () => {
type: 'chatComplete', type: 'chatComplete',
serverUrl: envData.serverUrl, serverUrl: envData.serverUrl,
data: { data: {
model: 'gpt-3.5-turbo', model: envData.model??MODEL_DEFAULT,
messages: [ messages: [
{ {
role: 'user', role: 'user',

1
src/typings.d.ts vendored
View File

@@ -3,6 +3,7 @@ interface EnvData {
flagDot?: boolean flagDot?: boolean
apiKey?: string apiKey?: string
serverUrl?: string serverUrl?: string
model?: string
translateEnable?: boolean translateEnable?: boolean
language?: string language?: string
hideOnDisableAutoTranslate?: boolean hideOnDisableAutoTranslate?: boolean