1
1
import { useTranslation } from 'react-i18next'
2
- import { useMemo , useState } from 'react'
2
+ import { useState } from 'react'
3
3
import { openUrl } from '../../utils/index.mjs'
4
4
import {
5
- isSupportBalance ,
6
- isUsingApiKey ,
5
+ isUsingOpenAiApiKey ,
7
6
isUsingAzureOpenAi ,
8
7
isUsingChatGLMApi ,
9
8
isUsingClaude2Api ,
@@ -15,6 +14,7 @@ import {
15
14
Models ,
16
15
ThemeMode ,
17
16
TriggerMode ,
17
+ isUsingMoonshotApi ,
18
18
} from '../../config/index.mjs'
19
19
import Browser from 'webextension-polyfill'
20
20
import { languageList } from '../../config/language.mjs'
@@ -82,10 +82,6 @@ async function checkBilling(apiKey, apiUrl) {
82
82
export function GeneralPart ( { config, updateConfig } ) {
83
83
const { t, i18n } = useTranslation ( )
84
84
const [ balance , setBalance ] = useState ( null )
85
- const [ currentModel , setCurrentModel ] = useState ( null )
86
- const showBalance = useMemo ( ( ) => {
87
- return isSupportBalance ( config )
88
- } , [ config ] )
89
85
90
86
const getBalance = async ( ) => {
91
87
const response = await fetch ( `${ config . customOpenAiApiUrl } /dashboard/billing/credit_grants` , {
@@ -145,20 +141,20 @@ export function GeneralPart({ config, updateConfig }) {
145
141
< span style = "display: flex; gap: 15px;" >
146
142
< select
147
143
style = {
148
- isUsingApiKey ( config ) ||
144
+ isUsingOpenAiApiKey ( config ) ||
149
145
isUsingMultiModeModel ( config ) ||
150
146
isUsingCustomModel ( config ) ||
151
147
isUsingAzureOpenAi ( config ) ||
152
148
isUsingClaude2Api ( config ) ||
153
- isUsingCustomNameOnlyModel ( config )
149
+ isUsingCustomNameOnlyModel ( config ) ||
150
+ isUsingMoonshotApi ( config )
154
151
? 'width: 50%;'
155
152
: undefined
156
153
}
157
154
required
158
155
onChange = { ( e ) => {
159
156
const modelName = e . target . value
160
157
updateConfig ( { modelName : modelName } )
161
- setCurrentModel ( Models [ modelName ] )
162
158
} }
163
159
>
164
160
{ config . activeApiModes . map ( ( modelName ) => {
@@ -200,7 +196,7 @@ export function GeneralPart({ config, updateConfig }) {
200
196
} ) }
201
197
</ select >
202
198
) }
203
- { isUsingApiKey ( config ) && (
199
+ { isUsingOpenAiApiKey ( config ) && (
204
200
< span style = "width: 50%; display: flex; gap: 5px;" >
205
201
< input
206
202
type = "password"
@@ -213,29 +209,23 @@ export function GeneralPart({ config, updateConfig }) {
213
209
/>
214
210
{ config . apiKey . length === 0 ? (
215
211
< a
216
- href = {
217
- currentModel && 'keyGenerateUrl' in currentModel
218
- ? currentModel . keyGenerateUrl
219
- : 'https://platform.openai.com/account/api-keys'
220
- }
212
+ href = "https://platform.openai.com/account/api-keys"
221
213
target = "_blank"
222
214
rel = "nofollow noopener noreferrer"
223
215
>
224
216
< button style = "white-space: nowrap;" type = "button" >
225
217
{ t ( 'Get' ) }
226
218
</ button >
227
219
</ a >
228
- ) : showBalance ? (
229
- balance ? (
230
- < button type = "button" onClick = { getBalance } >
231
- { balance }
232
- </ button >
233
- ) : (
234
- < button type = "button" onClick = { getBalance } >
235
- { t ( 'Balance' ) }
236
- </ button >
237
- )
238
- ) : null }
220
+ ) : balance ? (
221
+ < button type = "button" onClick = { getBalance } >
222
+ { balance }
223
+ </ button >
224
+ ) : (
225
+ < button type = "button" onClick = { getBalance } >
226
+ { t ( 'Balance' ) }
227
+ </ button >
228
+ ) }
239
229
</ span >
240
230
) }
241
231
{ isUsingCustomModel ( config ) && (
@@ -298,6 +288,30 @@ export function GeneralPart({ config, updateConfig }) {
298
288
} }
299
289
/>
300
290
) }
291
+ { isUsingMoonshotApi ( config ) && (
292
+ < span style = "width: 50%; display: flex; gap: 5px;" >
293
+ < input
294
+ type = "password"
295
+ value = { config . moonshotApiKey }
296
+ placeholder = { t ( 'Moonshot API Key' ) }
297
+ onChange = { ( e ) => {
298
+ const apiKey = e . target . value
299
+ updateConfig ( { moonshotApiKey : apiKey } )
300
+ } }
301
+ />
302
+ { config . moonshotApiKey . length === 0 && (
303
+ < a
304
+ href = "https://platform.moonshot.cn/console/api-keys"
305
+ target = "_blank"
306
+ rel = "nofollow noopener noreferrer"
307
+ >
308
+ < button style = "white-space: nowrap;" type = "button" >
309
+ { t ( 'Get' ) }
310
+ </ button >
311
+ </ a >
312
+ ) }
313
+ </ span >
314
+ ) }
301
315
</ span >
302
316
{ isUsingCustomModel ( config ) && (
303
317
< input
0 commit comments