diff --git a/src/background/index.mjs b/src/background/index.mjs index b0108a1..2fcdb59 100644 --- a/src/background/index.mjs +++ b/src/background/index.mjs @@ -158,7 +158,7 @@ async function executeApi(session, port, config) { port, session.question, session, - config.apiKey, + config.moonshotApiKey, session.modelName, ) } diff --git a/src/config/index.mjs b/src/config/index.mjs index c48bd29..e3884a2 100644 --- a/src/config/index.mjs +++ b/src/config/index.mjs @@ -66,13 +66,11 @@ export const poeWebModelKeys = [ 'poeAiWeb_Llama_2_70b', ] export const moonshotApiModelKeys = ['moonshot_v1_8k', 'moonshot_v1_32k', 'moonshot_v1_128k'] -const moonshotApiKeyGenerateUrl = 'https://platform.moonshot.cn/console/api-keys' /** * @typedef {object} Model * @property {string} value * @property {string} desc - * @property {string} [keyGenerateUrl] */ /** * @type {Object.} @@ -143,17 +141,14 @@ export const Models = { moonshot_v1_8k: { value: 'moonshot-v1-8k', desc: 'Moonshot (8k)', - keyGenerateUrl: moonshotApiKeyGenerateUrl, }, moonshot_v1_32k: { value: 'moonshot-v1-32k', desc: 'Moonshot (32k)', - keyGenerateUrl: moonshotApiKeyGenerateUrl, }, moonshot_v1_128k: { value: 'moonshot-v1-128k', desc: 'Moonshot (128k)', - keyGenerateUrl: moonshotApiKeyGenerateUrl, }, } @@ -199,6 +194,7 @@ export const defaultConfig = { claudeApiKey: '', chatglmApiKey: '', + moonshotApiKey: '', customApiKey: '', @@ -309,11 +305,10 @@ export function getNavigatorLanguage() { return navigator.language.substring(0, 2) } -export function isUsingApiKey(configOrSession) { +export function isUsingOpenAiApiKey(configOrSession) { return ( gptApiModelKeys.includes(configOrSession.modelName) || - chatgptApiModelKeys.includes(configOrSession.modelName) || - moonshotApiModelKeys.includes(configOrSession.modelName) + chatgptApiModelKeys.includes(configOrSession.modelName) ) } @@ -329,6 +324,10 @@ export function isUsingChatGLMApi(configOrSession) { return chatglmApiModelKeys.includes(configOrSession.modelName) } +export function isUsingMoonshotApi(configOrSession) { + return moonshotApiModelKeys.includes(configOrSession.modelName) +} + export function isUsingCustomNameOnlyModel(configOrSession) { return configOrSession.modelName === 'poeAiWebCustom' } @@ -344,13 +343,6 @@ export function isUsingGithubThirdPartyApi(configOrSession) { return githubThirdPartyApiModelKeys.includes(configOrSession.modelName) } -export function isSupportBalance(configOrSession) { - return ( - gptApiModelKeys.includes(configOrSession.modelName) || - chatgptApiModelKeys.includes(configOrSession.modelName) - ) -} - export async function getPreferredLanguageKey() { const config = await getUserConfig() if (config.preferredLanguage === 'auto') return config.userLanguage diff --git a/src/popup/sections/GeneralPart.jsx b/src/popup/sections/GeneralPart.jsx index 39624d5..0dfa5fd 100644 --- a/src/popup/sections/GeneralPart.jsx +++ b/src/popup/sections/GeneralPart.jsx @@ -1,9 +1,8 @@ import { useTranslation } from 'react-i18next' -import { useMemo, useState } from 'react' +import { useState } from 'react' import { openUrl } from '../../utils/index.mjs' import { - isSupportBalance, - isUsingApiKey, + isUsingOpenAiApiKey, isUsingAzureOpenAi, isUsingChatGLMApi, isUsingClaude2Api, @@ -15,6 +14,7 @@ import { Models, ThemeMode, TriggerMode, + isUsingMoonshotApi, } from '../../config/index.mjs' import Browser from 'webextension-polyfill' import { languageList } from '../../config/language.mjs' @@ -82,10 +82,6 @@ async function checkBilling(apiKey, apiUrl) { export function GeneralPart({ config, updateConfig }) { const { t, i18n } = useTranslation() const [balance, setBalance] = useState(null) - const [currentModel, setCurrentModel] = useState(null) - const showBalance = useMemo(() => { - return isSupportBalance(config) - }, [config]) const getBalance = async () => { const response = await fetch(`${config.customOpenAiApiUrl}/dashboard/billing/credit_grants`, { @@ -145,12 +141,13 @@ export function GeneralPart({ config, updateConfig }) { )} - {isUsingApiKey(config) && ( + {isUsingOpenAiApiKey(config) && ( {config.apiKey.length === 0 ? ( @@ -225,17 +217,15 @@ export function GeneralPart({ config, updateConfig }) { {t('Get')} - ) : showBalance ? ( - balance ? ( - - ) : ( - - ) - ) : null} + ) : balance ? ( + + ) : ( + + )} )} {isUsingCustomModel(config) && ( @@ -298,6 +288,30 @@ export function GeneralPart({ config, updateConfig }) { }} /> )} + {isUsingMoonshotApi(config) && ( + + { + const apiKey = e.target.value + updateConfig({ moonshotApiKey: apiKey }) + }} + /> + {config.moonshotApiKey.length === 0 && ( + + + + )} + + )} {isUsingCustomModel(config) && (