mirror of
https://github.com/wassname/chatGPTBox.git
synced 2026-06-27 20:20:58 +08:00
improve moonshot api support (#623)
This commit is contained in:
@@ -158,7 +158,7 @@ async function executeApi(session, port, config) {
|
||||
port,
|
||||
session.question,
|
||||
session,
|
||||
config.apiKey,
|
||||
config.moonshotApiKey,
|
||||
session.modelName,
|
||||
)
|
||||
}
|
||||
|
||||
+7
-15
@@ -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.<string,Model>}
|
||||
@@ -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
|
||||
|
||||
@@ -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 }) {
|
||||
<span style="display: flex; gap: 15px;">
|
||||
<select
|
||||
style={
|
||||
isUsingApiKey(config) ||
|
||||
isUsingOpenAiApiKey(config) ||
|
||||
isUsingMultiModeModel(config) ||
|
||||
isUsingCustomModel(config) ||
|
||||
isUsingAzureOpenAi(config) ||
|
||||
isUsingClaude2Api(config) ||
|
||||
isUsingCustomNameOnlyModel(config)
|
||||
isUsingCustomNameOnlyModel(config) ||
|
||||
isUsingMoonshotApi(config)
|
||||
? 'width: 50%;'
|
||||
: undefined
|
||||
}
|
||||
@@ -158,7 +155,6 @@ export function GeneralPart({ config, updateConfig }) {
|
||||
onChange={(e) => {
|
||||
const modelName = e.target.value
|
||||
updateConfig({ modelName: modelName })
|
||||
setCurrentModel(Models[modelName])
|
||||
}}
|
||||
>
|
||||
{config.activeApiModes.map((modelName) => {
|
||||
@@ -200,7 +196,7 @@ export function GeneralPart({ config, updateConfig }) {
|
||||
})}
|
||||
</select>
|
||||
)}
|
||||
{isUsingApiKey(config) && (
|
||||
{isUsingOpenAiApiKey(config) && (
|
||||
<span style="width: 50%; display: flex; gap: 5px;">
|
||||
<input
|
||||
type="password"
|
||||
@@ -213,11 +209,7 @@ export function GeneralPart({ config, updateConfig }) {
|
||||
/>
|
||||
{config.apiKey.length === 0 ? (
|
||||
<a
|
||||
href={
|
||||
currentModel && 'keyGenerateUrl' in currentModel
|
||||
? currentModel.keyGenerateUrl
|
||||
: 'https://platform.openai.com/account/api-keys'
|
||||
}
|
||||
href="https://platform.openai.com/account/api-keys"
|
||||
target="_blank"
|
||||
rel="nofollow noopener noreferrer"
|
||||
>
|
||||
@@ -225,17 +217,15 @@ export function GeneralPart({ config, updateConfig }) {
|
||||
{t('Get')}
|
||||
</button>
|
||||
</a>
|
||||
) : showBalance ? (
|
||||
balance ? (
|
||||
<button type="button" onClick={getBalance}>
|
||||
{balance}
|
||||
</button>
|
||||
) : (
|
||||
<button type="button" onClick={getBalance}>
|
||||
{t('Balance')}
|
||||
</button>
|
||||
)
|
||||
) : null}
|
||||
) : balance ? (
|
||||
<button type="button" onClick={getBalance}>
|
||||
{balance}
|
||||
</button>
|
||||
) : (
|
||||
<button type="button" onClick={getBalance}>
|
||||
{t('Balance')}
|
||||
</button>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
{isUsingCustomModel(config) && (
|
||||
@@ -298,6 +288,30 @@ export function GeneralPart({ config, updateConfig }) {
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{isUsingMoonshotApi(config) && (
|
||||
<span style="width: 50%; display: flex; gap: 5px;">
|
||||
<input
|
||||
type="password"
|
||||
value={config.moonshotApiKey}
|
||||
placeholder={t('Moonshot API Key')}
|
||||
onChange={(e) => {
|
||||
const apiKey = e.target.value
|
||||
updateConfig({ moonshotApiKey: apiKey })
|
||||
}}
|
||||
/>
|
||||
{config.moonshotApiKey.length === 0 && (
|
||||
<a
|
||||
href="https://platform.moonshot.cn/console/api-keys"
|
||||
target="_blank"
|
||||
rel="nofollow noopener noreferrer"
|
||||
>
|
||||
<button style="white-space: nowrap;" type="button">
|
||||
{t('Get')}
|
||||
</button>
|
||||
</a>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
{isUsingCustomModel(config) && (
|
||||
<input
|
||||
|
||||
Reference in New Issue
Block a user