From d6d7e17f842b405f5e7589e8257feb816751e3c9 Mon Sep 17 00:00:00 2001 From: IndieKKY Date: Sun, 17 Mar 2024 21:17:40 +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 | 21 +++++++++++++++++++-- src/const.tsx | 11 +++++++++-- src/typings.d.ts | 3 +++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/biz/Settings.tsx b/src/biz/Settings.tsx index a002a9c..ff88a7a 100644 --- a/src/biz/Settings.tsx +++ b/src/biz/Settings.tsx @@ -2,10 +2,12 @@ import React, {PropsWithChildren, useCallback, useMemo, useState} from 'react' import {setEnvData, setPage} from '../redux/envReducer' import {useAppDispatch, useAppSelector} from '../hooks/redux' import { + ASK_ENABLED_DEFAULT, HEADER_HEIGHT, LANGUAGE_DEFAULT, LANGUAGES, MODEL_DEFAULT, + MODEL_MAP, MODELS, PAGE_MAIN, PROMPT_DEFAULTS, @@ -59,6 +61,7 @@ const Settings = () => { const {value: translateEnableValue, onChange: setTranslateEnableValue} = useEventChecked(envData.translateEnable) const {value: summarizeEnableValue, onChange: setSummarizeEnableValue} = useEventChecked(envData.summarizeEnable) 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: summarizeFloatValue, onChange: setSummarizeFloatValue} = useEventChecked(envData.summarizeFloat) const [apiKeyValue, { onChange: onChangeApiKeyValue }] = useEventTarget({initialValue: envData.apiKey??''}) @@ -126,10 +129,11 @@ const Settings = () => { prompts: promptsValue, searchEnabled: searchEnabledValue, cnSearchEnabled: cnSearchEnabledValue, + askEnabled: askEnabledValue, })) dispatch(setPage(PAGE_MAIN)) 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(() => { dispatch(setPage(PAGE_MAIN)) @@ -237,7 +241,7 @@ const Settings = () => {
  • 支持其他第三方代理,有问题可加群交流
  • } - + @@ -370,6 +374,10 @@ const Settings = () => { {/* */} +
    + 当前选择的模型的分段字数上限是{MODEL_MAP[modelValue??MODEL_DEFAULT]?.tokens??'未知'} + (太接近上限总结会报错) +
    搜索配置 @@ -383,6 +391,15 @@ const Settings = () => { onChange={setCnSearchEnabledValue}/>
    +
    + 提问配置 + }> + + + +
    在搜索框输入提问内容,然后按Enter即可提问。
    +
    diff --git a/src/const.tsx b/src/const.tsx index c4770ab..179f887 100644 --- a/src/const.tsx +++ b/src/const.tsx @@ -143,28 +143,35 @@ 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:2000 +export const WORDS_DEFAULT = import.meta.env.VITE_ENV === 'web-dev'?500:10000 export const WORDS_MIN = 500 export const WORDS_MAX = 16000 export const WORDS_STEP = 500 export const SUMMARIZE_THRESHOLD = 100 export const SUMMARIZE_LANGUAGE_DEFAULT = 'cn' 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_THIRD = 'https://op.kongkongye.com' export const MODELS = [{ code: 'gpt-3.5-turbo', name: 'gpt-3.5-turbo', + tokens: 16385, }, { code: 'gpt-3.5-turbo-0125', name: 'gpt-3.5-turbo-0125', + tokens: 16385, }, { code: 'gpt-3.5-turbo-1106', name: 'gpt-3.5-turbo-1106', + tokens: 16385, }] 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 = [{ code: 'en', diff --git a/src/typings.d.ts b/src/typings.d.ts index af1cd27..58d5888 100644 --- a/src/typings.d.ts +++ b/src/typings.d.ts @@ -26,6 +26,9 @@ interface EnvData { searchEnabled?: boolean cnSearchEnabled?: boolean + // ask + askEnabled?: boolean + prompts?: { [key: string]: string }