You've already forked bilibili-subtitle
由于gemini兼容了openai格式,因此去除了专门的gemini选项,简化代码
This commit is contained in:
@@ -36,16 +36,3 @@ export const handleChatCompleteTask = async (task: Task) => {
|
|||||||
throw new Error(`${task.resp.error.code as string??''} ${task.resp.error.message as string ??''}`)
|
throw new Error(`${task.resp.error.code as string??''} ${task.resp.error.message as string ??''}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const handleGeminiChatCompleteTask = async (task: Task) => {
|
|
||||||
const data = task.def.data
|
|
||||||
const resp = await fetch('https://generativelanguage.googleapis.com/v1/models/gemini-pro:generateContent', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'x-goog-api-key': task.def.extra.geminiApiKey,
|
|
||||||
},
|
|
||||||
body: JSON.stringify(data),
|
|
||||||
})
|
|
||||||
task.resp = await resp.json()
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {TASK_EXPIRE_TIME} from '../consts/const'
|
import {TASK_EXPIRE_TIME} from '../consts/const'
|
||||||
import {handleChatCompleteTask, handleGeminiChatCompleteTask} from './openaiService'
|
import {handleChatCompleteTask} from './openaiService'
|
||||||
|
|
||||||
export const tasksMap = new Map<string, Task>()
|
export const tasksMap = new Map<string, Task>()
|
||||||
|
|
||||||
@@ -11,9 +11,6 @@ export const handleTask = async (task: Task) => {
|
|||||||
case 'chatComplete':
|
case 'chatComplete':
|
||||||
await handleChatCompleteTask(task)
|
await handleChatCompleteTask(task)
|
||||||
break
|
break
|
||||||
case 'geminiChatComplete':
|
|
||||||
await handleGeminiChatCompleteTask(task)
|
|
||||||
break
|
|
||||||
default:
|
default:
|
||||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||||
throw new Error(`任务类型不支持: ${task.def.type}`)
|
throw new Error(`任务类型不支持: ${task.def.type}`)
|
||||||
|
|||||||
@@ -4,10 +4,8 @@ import { openOptionsPage } from '../utils/chromeUtils'
|
|||||||
|
|
||||||
const ApiKeyReminder: React.FC = () => {
|
const ApiKeyReminder: React.FC = () => {
|
||||||
const apiKey = useAppSelector(state => state.env.envData.apiKey)
|
const apiKey = useAppSelector(state => state.env.envData.apiKey)
|
||||||
const geminiApiKey = useAppSelector(state => state.env.envData.geminiApiKey)
|
|
||||||
const aiType = useAppSelector(state => state.env.envData.aiType)
|
|
||||||
|
|
||||||
if ((aiType === 'gemini' && geminiApiKey) || (aiType !== 'gemini' && apiKey)) {
|
if (apiKey) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const Ask = (props: {
|
|||||||
const {addAskTask} = useTranslate()
|
const {addAskTask} = useTranslate()
|
||||||
|
|
||||||
const onRegenerate = useCallback(() => {
|
const onRegenerate = useCallback(() => {
|
||||||
const apiKey = envData.aiType === 'gemini'?envData.geminiApiKey:envData.apiKey
|
const apiKey = envData.apiKey
|
||||||
if (apiKey) {
|
if (apiKey) {
|
||||||
if (segments != null && segments.length > 0) {
|
if (segments != null && segments.length > 0) {
|
||||||
addAskTask(ask.id, segments[0], ask.question).catch(console.error)
|
addAskTask(ask.id, segments[0], ask.question).catch(console.error)
|
||||||
@@ -26,7 +26,7 @@ const Ask = (props: {
|
|||||||
} else {
|
} else {
|
||||||
toast.error('请先在选项页面设置ApiKey!')
|
toast.error('请先在选项页面设置ApiKey!')
|
||||||
}
|
}
|
||||||
}, [addAskTask, ask.id, ask.question, envData.aiType, envData.apiKey, envData.geminiApiKey, segments])
|
}, [addAskTask, ask.id, ask.question, envData.apiKey, segments])
|
||||||
|
|
||||||
const onAskFold = useCallback(() => {
|
const onAskFold = useCallback(() => {
|
||||||
dispatch(mergeAskInfo({
|
dispatch(mergeAskInfo({
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ const Body = () => {
|
|||||||
}, [dispatch])
|
}, [dispatch])
|
||||||
|
|
||||||
const onSummarizeAll = useCallback(() => {
|
const onSummarizeAll = useCallback(() => {
|
||||||
const apiKey = envData.aiType === 'gemini' ? envData.geminiApiKey : envData.apiKey
|
const apiKey = envData.apiKey
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
toast.error('请先在选项页面设置ApiKey!')
|
toast.error('请先在选项页面设置ApiKey!')
|
||||||
return
|
return
|
||||||
@@ -127,7 +127,7 @@ const Body = () => {
|
|||||||
}
|
}
|
||||||
toast.success(`已添加${segments_.length}个总结任务!`)
|
toast.success(`已添加${segments_.length}个总结任务!`)
|
||||||
}
|
}
|
||||||
}, [addSummarizeTask, curSummaryType, envData.aiType, envData.apiKey, envData.geminiApiKey, segments])
|
}, [addSummarizeTask, curSummaryType, envData.apiKey, segments])
|
||||||
|
|
||||||
const onFoldAll = useCallback(() => {
|
const onFoldAll = useCallback(() => {
|
||||||
dispatch(setFoldAll(!foldAll))
|
dispatch(setFoldAll(!foldAll))
|
||||||
@@ -146,13 +146,13 @@ const Body = () => {
|
|||||||
}, [asks, dispatch, foldAll, segments])
|
}, [asks, dispatch, foldAll, segments])
|
||||||
|
|
||||||
const toggleAutoTranslateCallback = useCallback(() => {
|
const toggleAutoTranslateCallback = useCallback(() => {
|
||||||
const apiKey = envData.aiType === 'gemini' ? envData.geminiApiKey : envData.apiKey
|
const apiKey = envData.apiKey
|
||||||
if (apiKey) {
|
if (apiKey) {
|
||||||
dispatch(setAutoTranslate(!autoTranslate))
|
dispatch(setAutoTranslate(!autoTranslate))
|
||||||
} else {
|
} else {
|
||||||
toast.error('请先在选项页面设置ApiKey!')
|
toast.error('请先在选项页面设置ApiKey!')
|
||||||
}
|
}
|
||||||
}, [autoTranslate, dispatch, envData.aiType, envData.apiKey, envData.geminiApiKey])
|
}, [autoTranslate, dispatch, envData.apiKey])
|
||||||
|
|
||||||
const onEnableAutoScroll = useCallback(() => {
|
const onEnableAutoScroll = useCallback(() => {
|
||||||
dispatch(setAutoScroll(true))
|
dispatch(setAutoScroll(true))
|
||||||
@@ -185,7 +185,7 @@ const Body = () => {
|
|||||||
|
|
||||||
const onAsk = useCallback(() => {
|
const onAsk = useCallback(() => {
|
||||||
if ((envData.askEnabled ?? ASK_ENABLED_DEFAULT) && searchText) {
|
if ((envData.askEnabled ?? ASK_ENABLED_DEFAULT) && searchText) {
|
||||||
const apiKey = envData.aiType === 'gemini' ? envData.geminiApiKey : envData.apiKey
|
const apiKey = envData.apiKey
|
||||||
if (apiKey) {
|
if (apiKey) {
|
||||||
if (segments != null && segments.length > 0) {
|
if (segments != null && segments.length > 0) {
|
||||||
const id = v4()
|
const id = v4()
|
||||||
@@ -201,7 +201,7 @@ const Body = () => {
|
|||||||
toast.error('请先在选项页面设置ApiKey!')
|
toast.error('请先在选项页面设置ApiKey!')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [addAskTask, dispatch, envData.aiType, envData.apiKey, envData.askEnabled, envData.geminiApiKey, searchText, segments])
|
}, [addAskTask, dispatch, envData.apiKey, envData.askEnabled, searchText, segments])
|
||||||
|
|
||||||
// service
|
// service
|
||||||
useKeyService()
|
useKeyService()
|
||||||
|
|||||||
@@ -73,13 +73,13 @@ const Summarize = (props: {
|
|||||||
const {addSummarizeTask} = useTranslate()
|
const {addSummarizeTask} = useTranslate()
|
||||||
|
|
||||||
const onGenerate = useCallback(() => {
|
const onGenerate = useCallback(() => {
|
||||||
const apiKey = envData.aiType === 'gemini'?envData.geminiApiKey:envData.apiKey
|
const apiKey = envData.apiKey
|
||||||
if (apiKey) {
|
if (apiKey) {
|
||||||
addSummarizeTask(curSummaryType, segment).catch(console.error)
|
addSummarizeTask(curSummaryType, segment).catch(console.error)
|
||||||
} else {
|
} else {
|
||||||
toast.error('请先在选项页面设置ApiKey!')
|
toast.error('请先在选项页面设置ApiKey!')
|
||||||
}
|
}
|
||||||
}, [addSummarizeTask, curSummaryType, envData.aiType, envData.apiKey, envData.geminiApiKey, segment])
|
}, [addSummarizeTask, curSummaryType, envData.apiKey, segment])
|
||||||
|
|
||||||
const onCopy = useCallback(() => {
|
const onCopy = useCallback(() => {
|
||||||
if (summary != null) {
|
if (summary != null) {
|
||||||
|
|||||||
@@ -284,7 +284,6 @@ export const MODELS = [{
|
|||||||
code: 'custom',
|
code: 'custom',
|
||||||
name: '自定义',
|
name: '自定义',
|
||||||
}]
|
}]
|
||||||
export const GEMINI_TOKENS = 32768
|
|
||||||
export const MODEL_DEFAULT = MODELS[0].code
|
export const MODEL_DEFAULT = MODELS[0].code
|
||||||
export const MODEL_MAP: {[key: string]: typeof MODELS[number]} = {}
|
export const MODEL_MAP: {[key: string]: typeof MODELS[number]} = {}
|
||||||
for (const model of MODELS) {
|
for (const model of MODELS) {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import {
|
|||||||
setTempData,
|
setTempData,
|
||||||
} from '../redux/envReducer'
|
} from '../redux/envReducer'
|
||||||
import {EventBusContext} from '../Router'
|
import {EventBusContext} from '../Router'
|
||||||
import {EVENT_EXPAND, GEMINI_TOKENS, TOTAL_HEIGHT_MAX, TOTAL_HEIGHT_MIN, WORDS_MIN, WORDS_RATE} from '../consts/const'
|
import {EVENT_EXPAND, TOTAL_HEIGHT_MAX, TOTAL_HEIGHT_MIN, WORDS_MIN, WORDS_RATE} from '../consts/const'
|
||||||
import {useAsyncEffect, useInterval} from 'ahooks'
|
import {useAsyncEffect, useInterval} from 'ahooks'
|
||||||
import {getModelMaxTokens, getWholeText} from '../utils/bizUtil'
|
import {getModelMaxTokens, getWholeText} from '../utils/bizUtil'
|
||||||
import { useMessage } from './useMessageService'
|
import { useMessage } from './useMessageService'
|
||||||
@@ -152,11 +152,7 @@ const useSubtitleService = () => {
|
|||||||
if (envData.summarizeEnable) { // 分段
|
if (envData.summarizeEnable) { // 分段
|
||||||
let size = envData.words
|
let size = envData.words
|
||||||
if (!size) { // 默认
|
if (!size) { // 默认
|
||||||
if (envData.aiType === 'gemini') {
|
size = getModelMaxTokens(envData)*WORDS_RATE
|
||||||
size = GEMINI_TOKENS*WORDS_RATE
|
|
||||||
} else {
|
|
||||||
size = getModelMaxTokens(envData)*WORDS_RATE
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
size = Math.max(size, WORDS_MIN)
|
size = Math.max(size, WORDS_MIN)
|
||||||
|
|
||||||
|
|||||||
@@ -88,24 +88,9 @@ const useTranslate = () => {
|
|||||||
prompt = prompt.replaceAll('{{subtitles}}', lineStr)
|
prompt = prompt.replaceAll('{{subtitles}}', lineStr)
|
||||||
|
|
||||||
const taskDef: TaskDef = {
|
const taskDef: TaskDef = {
|
||||||
type: envData.aiType === 'gemini'?'geminiChatComplete':'chatComplete',
|
type: 'chatComplete',
|
||||||
serverUrl: envData.serverUrl,
|
serverUrl: envData.serverUrl,
|
||||||
data: envData.aiType === 'gemini'
|
data: {
|
||||||
?{
|
|
||||||
contents: [
|
|
||||||
{
|
|
||||||
parts: [
|
|
||||||
{
|
|
||||||
text: prompt
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
generationConfig: {
|
|
||||||
maxOutputTokens: 2048
|
|
||||||
}
|
|
||||||
}
|
|
||||||
:{
|
|
||||||
model: getModel(envData),
|
model: getModel(envData),
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
@@ -120,7 +105,6 @@ const useTranslate = () => {
|
|||||||
extra: {
|
extra: {
|
||||||
type: 'translate',
|
type: 'translate',
|
||||||
apiKey: envData.apiKey,
|
apiKey: envData.apiKey,
|
||||||
geminiApiKey: envData.geminiApiKey,
|
|
||||||
startIdx,
|
startIdx,
|
||||||
size: lines.length,
|
size: lines.length,
|
||||||
}
|
}
|
||||||
@@ -165,24 +149,9 @@ const useTranslate = () => {
|
|||||||
prompt = prompt.replaceAll('{{segment}}', segment.text)
|
prompt = prompt.replaceAll('{{segment}}', segment.text)
|
||||||
|
|
||||||
const taskDef: TaskDef = {
|
const taskDef: TaskDef = {
|
||||||
type: envData.aiType === 'gemini'?'geminiChatComplete':'chatComplete',
|
type: 'chatComplete',
|
||||||
serverUrl: envData.serverUrl,
|
serverUrl: envData.serverUrl,
|
||||||
data: envData.aiType === 'gemini'
|
data: {
|
||||||
?{
|
|
||||||
contents: [
|
|
||||||
{
|
|
||||||
parts: [
|
|
||||||
{
|
|
||||||
text: prompt
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
generationConfig: {
|
|
||||||
maxOutputTokens: 2048
|
|
||||||
}
|
|
||||||
}
|
|
||||||
:{
|
|
||||||
model: getModel(envData),
|
model: getModel(envData),
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
@@ -199,7 +168,6 @@ const useTranslate = () => {
|
|||||||
summaryType: type,
|
summaryType: type,
|
||||||
startIdx: segment.startIdx,
|
startIdx: segment.startIdx,
|
||||||
apiKey: envData.apiKey,
|
apiKey: envData.apiKey,
|
||||||
geminiApiKey: envData.geminiApiKey,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.debug('addSummarizeTask', taskDef)
|
console.debug('addSummarizeTask', taskDef)
|
||||||
@@ -220,24 +188,9 @@ const useTranslate = () => {
|
|||||||
prompt = prompt.replaceAll('{{question}}', question)
|
prompt = prompt.replaceAll('{{question}}', question)
|
||||||
|
|
||||||
const taskDef: TaskDef = {
|
const taskDef: TaskDef = {
|
||||||
type: envData.aiType === 'gemini'?'geminiChatComplete':'chatComplete',
|
type: 'chatComplete',
|
||||||
serverUrl: envData.serverUrl,
|
serverUrl: envData.serverUrl,
|
||||||
data: envData.aiType === 'gemini'
|
data: {
|
||||||
?{
|
|
||||||
contents: [
|
|
||||||
{
|
|
||||||
parts: [
|
|
||||||
{
|
|
||||||
text: prompt
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
generationConfig: {
|
|
||||||
maxOutputTokens: 2048
|
|
||||||
}
|
|
||||||
}
|
|
||||||
:{
|
|
||||||
model: getModel(envData),
|
model: getModel(envData),
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
@@ -253,7 +206,6 @@ const useTranslate = () => {
|
|||||||
type: 'ask',
|
type: 'ask',
|
||||||
// startIdx: segment.startIdx,
|
// startIdx: segment.startIdx,
|
||||||
apiKey: envData.apiKey,
|
apiKey: envData.apiKey,
|
||||||
geminiApiKey: envData.geminiApiKey,
|
|
||||||
askId: id,
|
askId: id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -335,7 +287,7 @@ const useTranslate = () => {
|
|||||||
console.debug('getTask', taskResp.task)
|
console.debug('getTask', taskResp.task)
|
||||||
const task: Task = taskResp.task
|
const task: Task = taskResp.task
|
||||||
const taskType: string | undefined = task.def.extra?.type
|
const taskType: string | undefined = task.def.extra?.type
|
||||||
const content = envData.aiType === 'gemini'?task.resp?.candidates[0]?.content?.parts[0]?.text?.trim():task.resp?.choices?.[0]?.message?.content?.trim()
|
const content = task.resp?.choices?.[0]?.message?.content?.trim()
|
||||||
if (task.status === 'done') {
|
if (task.status === 'done') {
|
||||||
// 异常提示
|
// 异常提示
|
||||||
if (task.error) {
|
if (task.error) {
|
||||||
@@ -355,7 +307,7 @@ const useTranslate = () => {
|
|||||||
} else {
|
} else {
|
||||||
dispatch(delTaskId(taskId))
|
dispatch(delTaskId(taskId))
|
||||||
}
|
}
|
||||||
}, [dispatch, envData.aiType, handleAsk, handleSummarize, handleTranslate, sendExtension])
|
}, [dispatch, handleAsk, handleSummarize, handleTranslate, sendExtension])
|
||||||
|
|
||||||
return {getFetch, getTask, addTask, addSummarizeTask, addAskTask}
|
return {getFetch, getTask, addTask, addSummarizeTask, addAskTask}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import {
|
|||||||
CUSTOM_MODEL_TOKENS,
|
CUSTOM_MODEL_TOKENS,
|
||||||
DEFAULT_SERVER_URL_GEMINI,
|
DEFAULT_SERVER_URL_GEMINI,
|
||||||
DEFAULT_SERVER_URL_OPENAI,
|
DEFAULT_SERVER_URL_OPENAI,
|
||||||
GEMINI_TOKENS,
|
|
||||||
LANGUAGE_DEFAULT,
|
LANGUAGE_DEFAULT,
|
||||||
LANGUAGES,
|
LANGUAGES,
|
||||||
MODEL_DEFAULT,
|
MODEL_DEFAULT,
|
||||||
@@ -80,7 +79,6 @@ const OptionsPage = () => {
|
|||||||
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??''})
|
||||||
const [serverUrlValue, setServerUrlValue] = useState(envData.serverUrl)
|
const [serverUrlValue, setServerUrlValue] = useState(envData.serverUrl)
|
||||||
const [geminiApiKeyValue, { onChange: onChangeGeminiApiKeyValue }] = useEventTarget({initialValue: envData.geminiApiKey??''})
|
|
||||||
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 [modelValue, { onChange: onChangeModelValue }] = useEventTarget({initialValue: envData.model??MODEL_DEFAULT})
|
||||||
const [customModelValue, { onChange: onChangeCustomModelValue }] = useEventTarget({initialValue: envData.customModel})
|
const [customModelValue, { onChange: onChangeCustomModelValue }] = useEventTarget({initialValue: envData.customModel})
|
||||||
@@ -89,7 +87,6 @@ const OptionsPage = () => {
|
|||||||
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 [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)
|
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)
|
||||||
@@ -110,11 +107,8 @@ const OptionsPage = () => {
|
|||||||
return list
|
return list
|
||||||
}, [])
|
}, [])
|
||||||
const apiKeySetted = useMemo(() => {
|
const apiKeySetted = useMemo(() => {
|
||||||
if (aiTypeValue === 'gemini') {
|
|
||||||
return !!geminiApiKeyValue
|
|
||||||
}
|
|
||||||
return !!apiKeyValue
|
return !!apiKeyValue
|
||||||
}, [aiTypeValue, apiKeyValue, geminiApiKeyValue])
|
}, [apiKeyValue])
|
||||||
|
|
||||||
const onChangeHideOnDisableAutoTranslate = useCallback((e: any) => {
|
const onChangeHideOnDisableAutoTranslate = useCallback((e: any) => {
|
||||||
setHideOnDisableAutoTranslateValue(e.target.checked)
|
setHideOnDisableAutoTranslateValue(e.target.checked)
|
||||||
@@ -125,13 +119,11 @@ const OptionsPage = () => {
|
|||||||
sidePanel: sidePanelValue,
|
sidePanel: sidePanelValue,
|
||||||
manualInsert: !autoInsertValue,
|
manualInsert: !autoInsertValue,
|
||||||
autoExpand: autoExpandValue,
|
autoExpand: autoExpandValue,
|
||||||
aiType: aiTypeValue,
|
|
||||||
apiKey: apiKeyValue,
|
apiKey: apiKeyValue,
|
||||||
serverUrl: serverUrlValue,
|
serverUrl: serverUrlValue,
|
||||||
model: modelValue,
|
model: modelValue,
|
||||||
customModel: customModelValue,
|
customModel: customModelValue,
|
||||||
customModelTokens: customModelTokensValue,
|
customModelTokens: customModelTokensValue,
|
||||||
geminiApiKey: geminiApiKeyValue,
|
|
||||||
translateEnable: translateEnableValue,
|
translateEnable: translateEnableValue,
|
||||||
language: languageValue,
|
language: languageValue,
|
||||||
hideOnDisableAutoTranslate: hideOnDisableAutoTranslateValue,
|
hideOnDisableAutoTranslate: hideOnDisableAutoTranslateValue,
|
||||||
@@ -154,7 +146,7 @@ const OptionsPage = () => {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.close()
|
window.close()
|
||||||
}, 3000)
|
}, 3000)
|
||||||
}, [dispatch, sendExtension, sidePanelValue, autoInsertValue, autoExpandValue, aiTypeValue, apiKeyValue, serverUrlValue, modelValue, customModelValue, customModelTokensValue, geminiApiKeyValue, translateEnableValue, languageValue, hideOnDisableAutoTranslateValue, themeValue, transDisplayValue, summarizeEnableValue, summarizeFloatValue, summarizeLanguageValue, wordsValue, fetchAmountValue, fontSizeValue, promptsValue, searchEnabledValue, cnSearchEnabledValue, askEnabledValue])
|
}, [dispatch, sendExtension, sidePanelValue, autoInsertValue, autoExpandValue, apiKeyValue, serverUrlValue, modelValue, customModelValue, customModelTokensValue, translateEnableValue, languageValue, hideOnDisableAutoTranslateValue, themeValue, transDisplayValue, summarizeEnableValue, summarizeFloatValue, summarizeLanguageValue, wordsValue, fetchAmountValue, fontSizeValue, promptsValue, searchEnabledValue, cnSearchEnabledValue, askEnabledValue])
|
||||||
|
|
||||||
const onCancel = useCallback(() => {
|
const onCancel = useCallback(() => {
|
||||||
window.close()
|
window.close()
|
||||||
@@ -200,14 +192,6 @@ const OptionsPage = () => {
|
|||||||
setFontSizeValue('large')
|
setFontSizeValue('large')
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const onSelOpenai = useCallback(() => {
|
|
||||||
setAiTypeValue('openai')
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
const onSelGemini = useCallback(() => {
|
|
||||||
setAiTypeValue('gemini')
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='container mx-auto max-w-3xl p-4'>
|
<div className='container mx-auto max-w-3xl p-4'>
|
||||||
<OptionCard title="通用配置">
|
<OptionCard title="通用配置">
|
||||||
@@ -236,25 +220,19 @@ const OptionsPage = () => {
|
|||||||
<button onClick={onSelFontSize2} className={classNames('btn btn-sm no-animation', fontSizeValue === 'large'?'btn-active':'')}>加大</button>
|
<button onClick={onSelFontSize2} className={classNames('btn btn-sm no-animation', fontSizeValue === 'large'?'btn-active':'')}>加大</button>
|
||||||
</div>
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
<FormItem title='AI类型' tip='OPENAI质量更高'>
|
|
||||||
<div className="btn-group">
|
|
||||||
<button onClick={onSelOpenai} className={classNames('btn btn-sm', (!aiTypeValue || aiTypeValue === 'openai')?'btn-active':'')}>OpenAI</button>
|
|
||||||
<button onClick={onSelGemini} className={classNames('btn btn-sm', aiTypeValue === 'gemini'?'btn-active':'')}>Gemini</button>
|
|
||||||
</div>
|
|
||||||
</FormItem>
|
|
||||||
</OptionCard>
|
</OptionCard>
|
||||||
|
|
||||||
<OptionCard title="AI 配置">
|
<OptionCard title="AI 配置">
|
||||||
{(!aiTypeValue || aiTypeValue === 'openai') && <FormItem title='ApiKey' htmlFor='apiKey'>
|
{<FormItem title='ApiKey' htmlFor='apiKey'>
|
||||||
<input id='apiKey' type='text' className='input input-sm input-bordered w-full' placeholder='sk-xxx'
|
<input id='apiKey' type='text' className='input input-sm input-bordered w-full' placeholder='sk-xxx'
|
||||||
value={apiKeyValue} onChange={onChangeApiKeyValue}/>
|
value={apiKeyValue} onChange={onChangeApiKeyValue}/>
|
||||||
</FormItem>}
|
</FormItem>}
|
||||||
{(!aiTypeValue || aiTypeValue === 'openai') && <FormItem title='服务器' htmlFor='serverUrl'>
|
{<FormItem title='服务器' htmlFor='serverUrl'>
|
||||||
<input id='serverUrl' type='text' className='input input-sm input-bordered w-full'
|
<input id='serverUrl' type='text' className='input input-sm input-bordered w-full'
|
||||||
placeholder={DEFAULT_SERVER_URL_OPENAI} value={serverUrlValue}
|
placeholder={DEFAULT_SERVER_URL_OPENAI} value={serverUrlValue}
|
||||||
onChange={e => setServerUrlValue(e.target.value)}/>
|
onChange={e => setServerUrlValue(e.target.value)}/>
|
||||||
</FormItem>}
|
</FormItem>}
|
||||||
{(!aiTypeValue || aiTypeValue === 'openai') && <div>
|
{<div>
|
||||||
<div className='desc text-sm text-center'>
|
<div className='desc text-sm text-center'>
|
||||||
<div className='flex justify-center font-semibold'>【OpenAI官方地址】</div>
|
<div className='flex justify-center font-semibold'>【OpenAI官方地址】</div>
|
||||||
<div>官方网址:<a className='link link-primary' href='https://platform.openai.com/' target='_blank'
|
<div>官方网址:<a className='link link-primary' href='https://platform.openai.com/' target='_blank'
|
||||||
@@ -279,13 +257,13 @@ const OptionsPage = () => {
|
|||||||
<div className='text-amber-600 flex justify-center items-center'><FaGripfire/>国内可访问,无需🪜<FaGripfire/></div>
|
<div className='text-amber-600 flex justify-center items-center'><FaGripfire/>国内可访问,无需🪜<FaGripfire/></div>
|
||||||
</div>
|
</div>
|
||||||
</div>}
|
</div>}
|
||||||
{(!aiTypeValue || aiTypeValue === 'openai') && <FormItem title='模型选择' htmlFor='modelSel' tip='注意,不同模型有不同价格与token限制'>
|
{<FormItem title='模型选择' htmlFor='modelSel' tip='注意,不同模型有不同价格与token限制'>
|
||||||
<select id='modelSel' className="select select-sm select-bordered" value={modelValue}
|
<select id='modelSel' className="select select-sm select-bordered" value={modelValue}
|
||||||
onChange={onChangeModelValue}>
|
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>
|
||||||
</FormItem>}
|
</FormItem>}
|
||||||
{(!aiTypeValue || aiTypeValue === 'openai') && <div className='desc text-sm'>
|
{<div className='desc text-sm'>
|
||||||
{MODEL_TIP}
|
{MODEL_TIP}
|
||||||
</div>}
|
</div>}
|
||||||
{modelValue === 'custom' && <FormItem title='模型名' htmlFor='customModel'>
|
{modelValue === 'custom' && <FormItem title='模型名' htmlFor='customModel'>
|
||||||
@@ -298,20 +276,6 @@ const OptionsPage = () => {
|
|||||||
value={customModelTokensValue}
|
value={customModelTokensValue}
|
||||||
onChange={e => setCustomModelTokensValue(e.target.value ? parseInt(e.target.value) : undefined)}/>
|
onChange={e => setCustomModelTokensValue(e.target.value ? parseInt(e.target.value) : undefined)}/>
|
||||||
</FormItem>}
|
</FormItem>}
|
||||||
{aiTypeValue === 'gemini' && <FormItem title='ApiKey' htmlFor='geminiApiKey'>
|
|
||||||
<input id='geminiApiKey' type='text' className='input input-sm input-bordered w-full' placeholder='xxx'
|
|
||||||
value={geminiApiKeyValue} onChange={onChangeGeminiApiKeyValue}/>
|
|
||||||
</FormItem>}
|
|
||||||
{aiTypeValue === 'gemini' && <div>
|
|
||||||
<div className='desc text-sm'>
|
|
||||||
<div>官方网址:<a className='link link-primary' href='https://makersuite.google.com/app/apikey'
|
|
||||||
target='_blank'
|
|
||||||
rel="noreferrer">Google AI Studio</a> (目前免费)
|
|
||||||
</div>
|
|
||||||
<div className='text-sm text-error flex items-center'><IoWarning className='text-sm text-warning'/>谷歌模型安全要求比较高,有些视频可能无法生成总结!
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>}
|
|
||||||
</OptionCard>
|
</OptionCard>
|
||||||
|
|
||||||
<OptionCard title={<div className='flex items-center'>
|
<OptionCard title={<div className='flex items-center'>
|
||||||
@@ -379,7 +343,7 @@ const OptionsPage = () => {
|
|||||||
</div>
|
</div>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
<div className='desc text-sm'>
|
<div className='desc text-sm'>
|
||||||
当前选择的模型的分段字数上限是<span className='font-semibold font-mono'>{aiTypeValue === 'gemini'?GEMINI_TOKENS:(MODEL_MAP[modelValue??MODEL_DEFAULT]?.tokens??'未知')}</span>
|
当前选择的模型的分段字数上限是<span className='font-semibold font-mono'>{MODEL_MAP[modelValue??MODEL_DEFAULT]?.tokens??'未知'}</span>
|
||||||
(太接近上限总结会报错)
|
(太接近上限总结会报错)
|
||||||
</div>
|
</div>
|
||||||
</OptionCard>
|
</OptionCard>
|
||||||
|
|||||||
5
src/typings.d.ts
vendored
5
src/typings.d.ts
vendored
@@ -11,15 +11,12 @@ interface EnvData {
|
|||||||
autoExpand?: boolean
|
autoExpand?: boolean
|
||||||
flagDot?: boolean
|
flagDot?: boolean
|
||||||
|
|
||||||
aiType?: 'openai' | 'gemini'
|
|
||||||
// openai
|
// openai
|
||||||
apiKey?: string
|
apiKey?: string
|
||||||
serverUrl?: string
|
serverUrl?: string
|
||||||
model?: string
|
model?: string
|
||||||
customModel?: string
|
customModel?: string
|
||||||
customModelTokens?: number
|
customModelTokens?: number
|
||||||
// gemini
|
|
||||||
geminiApiKey?: string
|
|
||||||
|
|
||||||
translateEnable?: boolean
|
translateEnable?: boolean
|
||||||
language?: string
|
language?: string
|
||||||
@@ -54,7 +51,7 @@ interface TempData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface TaskDef {
|
interface TaskDef {
|
||||||
type: 'chatComplete' | 'geminiChatComplete'
|
type: 'chatComplete'
|
||||||
serverUrl?: string
|
serverUrl?: string
|
||||||
data: any
|
data: any
|
||||||
extra?: any
|
extra?: any
|
||||||
|
|||||||
Reference in New Issue
Block a user