mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-05-04 22:51:08 +00:00
refactor(auth): support multiple model IDs in Alibaba Cloud Standard API authentication
- Updated AuthDialog to handle multiple model IDs, allowing users to input and submit a comma-separated list. - Adjusted related functions to process and validate multiple model IDs. - Enhanced user feedback messages to reflect the changes in model ID handling.
This commit is contained in:
parent
41b5001e54
commit
ddc397360f
3 changed files with 34 additions and 28 deletions
|
|
@ -57,6 +57,8 @@ type ViewLevel =
|
|||
| 'alibaba-standard-model-id-input'
|
||||
| 'custom-info';
|
||||
|
||||
const ALIBABA_STANDARD_MODEL_IDS_PLACEHOLDER = 'qwen3.5-plus,glm-5,kimi-k2.5';
|
||||
|
||||
export function AuthDialog(): React.JSX.Element {
|
||||
const { pendingAuthType, authError } = useUIState();
|
||||
const {
|
||||
|
|
@ -334,21 +336,21 @@ export function AuthDialog(): React.JSX.Element {
|
|||
|
||||
setAlibabaStandardApiKeyError(null);
|
||||
if (!alibabaStandardModelId.trim()) {
|
||||
setAlibabaStandardModelId('qwen3.5-plus');
|
||||
setAlibabaStandardModelId(ALIBABA_STANDARD_MODEL_IDS_PLACEHOLDER);
|
||||
}
|
||||
setViewLevel('alibaba-standard-model-id-input');
|
||||
};
|
||||
|
||||
const handleAlibabaStandardModelSubmit = () => {
|
||||
const trimmedApiKey = alibabaStandardApiKey.trim();
|
||||
const trimmedModelId = alibabaStandardModelId.trim();
|
||||
const trimmedModelIds = alibabaStandardModelId.trim();
|
||||
if (!trimmedApiKey) {
|
||||
setAlibabaStandardApiKeyError(t('API key cannot be empty.'));
|
||||
setViewLevel('alibaba-standard-api-key-input');
|
||||
return;
|
||||
}
|
||||
if (!trimmedModelId) {
|
||||
setAlibabaStandardModelIdError(t('Model ID cannot be empty.'));
|
||||
if (!trimmedModelIds) {
|
||||
setAlibabaStandardModelIdError(t('Model IDs cannot be empty.'));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -356,7 +358,7 @@ export function AuthDialog(): React.JSX.Element {
|
|||
void handleAlibabaStandardSubmit(
|
||||
trimmedApiKey,
|
||||
alibabaStandardRegion,
|
||||
trimmedModelId,
|
||||
trimmedModelIds,
|
||||
);
|
||||
};
|
||||
|
||||
|
|
@ -477,9 +479,6 @@ export function AuthDialog(): React.JSX.Element {
|
|||
|
||||
const renderApiKeyTypeSelectView = () => (
|
||||
<>
|
||||
<Box marginTop={1}>
|
||||
<Text color={theme.text.primary}>{t('Select API Key type')}</Text>
|
||||
</Box>
|
||||
<Box marginTop={1}>
|
||||
<DescriptiveRadioButtonSelect
|
||||
items={apiKeyTypeItems}
|
||||
|
|
@ -504,9 +503,6 @@ export function AuthDialog(): React.JSX.Element {
|
|||
|
||||
const renderAlibabaStandardRegionSelectView = () => (
|
||||
<>
|
||||
<Box marginTop={1}>
|
||||
<Text color={theme.text.primary}>{t('Select region')}</Text>
|
||||
</Box>
|
||||
<Box marginTop={1}>
|
||||
<DescriptiveRadioButtonSelect
|
||||
items={alibabaStandardRegionItems}
|
||||
|
|
@ -567,10 +563,11 @@ export function AuthDialog(): React.JSX.Element {
|
|||
|
||||
const renderAlibabaStandardModelIdInputView = () => (
|
||||
<Box marginTop={1} flexDirection="column">
|
||||
<Text color={theme.text.primary}>{t('Enter model ID')}</Text>
|
||||
<Box marginTop={1}>
|
||||
<Text color={theme.text.secondary}>
|
||||
{t('Examples: qwen3.5-plus, glm-5, kimi-k2.5')}
|
||||
{t(
|
||||
'You can enter multiple model IDs, separated by commas. Examples: qwen3.5-plus,glm-5,kimi-k2.5',
|
||||
)}
|
||||
</Text>
|
||||
</Box>
|
||||
<Box marginTop={1}>
|
||||
|
|
@ -583,7 +580,7 @@ export function AuthDialog(): React.JSX.Element {
|
|||
}
|
||||
}}
|
||||
onSubmit={handleAlibabaStandardModelSubmit}
|
||||
placeholder="qwen3.5-plus"
|
||||
placeholder={ALIBABA_STANDARD_MODEL_IDS_PLACEHOLDER}
|
||||
/>
|
||||
</Box>
|
||||
{alibabaStandardModelIdError && (
|
||||
|
|
@ -640,7 +637,7 @@ export function AuthDialog(): React.JSX.Element {
|
|||
case 'alibaba-standard-api-key-input':
|
||||
return t('Enter Alibaba Cloud Standard API Key');
|
||||
case 'alibaba-standard-model-id-input':
|
||||
return t('Enter Model ID');
|
||||
return t('Enter Model IDs');
|
||||
default:
|
||||
return t('Select Authentication Method');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -431,18 +431,27 @@ export const useAuthCommand = (
|
|||
* Persists key to env.DASHSCOPE_API_KEY and creates a modelProviders.openai entry.
|
||||
*/
|
||||
const handleAlibabaStandardSubmit = useCallback(
|
||||
async (apiKey: string, region: AlibabaStandardRegion, modelId: string) => {
|
||||
async (
|
||||
apiKey: string,
|
||||
region: AlibabaStandardRegion,
|
||||
modelIdsInput: string,
|
||||
) => {
|
||||
try {
|
||||
setIsAuthenticating(true);
|
||||
setAuthError(null);
|
||||
|
||||
const trimmedApiKey = apiKey.trim();
|
||||
const trimmedModelId = modelId.trim();
|
||||
const modelIds = modelIdsInput
|
||||
.split(',')
|
||||
.map((id) => id.trim())
|
||||
.filter(
|
||||
(id, index, array) => id.length > 0 && array.indexOf(id) === index,
|
||||
);
|
||||
if (!trimmedApiKey) {
|
||||
throw new Error(t('API key cannot be empty.'));
|
||||
}
|
||||
if (!trimmedModelId) {
|
||||
throw new Error(t('Model ID cannot be empty.'));
|
||||
if (modelIds.length === 0) {
|
||||
throw new Error(t('Model IDs cannot be empty.'));
|
||||
}
|
||||
|
||||
const baseUrl = ALIBABA_STANDARD_API_KEY_ENDPOINTS[region];
|
||||
|
|
@ -458,12 +467,12 @@ export const useAuthCommand = (
|
|||
);
|
||||
process.env[DASHSCOPE_STANDARD_API_KEY_ENV_KEY] = trimmedApiKey;
|
||||
|
||||
const newConfig: ProviderModelConfig = {
|
||||
id: trimmedModelId,
|
||||
name: `${trimmedModelId} (DashScope Standard)`,
|
||||
const newConfigs: ProviderModelConfig[] = modelIds.map((modelId) => ({
|
||||
id: modelId,
|
||||
name: `[ModelStudio Standard] ${modelId}`,
|
||||
baseUrl,
|
||||
envKey: DASHSCOPE_STANDARD_API_KEY_ENV_KEY,
|
||||
};
|
||||
}));
|
||||
|
||||
const existingConfigs =
|
||||
(
|
||||
|
|
@ -481,7 +490,7 @@ export const useAuthCommand = (
|
|||
),
|
||||
);
|
||||
|
||||
const updatedConfigs = [newConfig, ...nonAlibabaStandardConfigs];
|
||||
const updatedConfigs = [...newConfigs, ...nonAlibabaStandardConfigs];
|
||||
|
||||
settings.setValue(
|
||||
persistScope,
|
||||
|
|
@ -493,7 +502,7 @@ export const useAuthCommand = (
|
|||
'security.auth.selectedType',
|
||||
AuthType.USE_OPENAI,
|
||||
);
|
||||
settings.setValue(persistScope, 'model.name', trimmedModelId);
|
||||
settings.setValue(persistScope, 'model.name', modelIds[0]);
|
||||
|
||||
const updatedModelProviders: ModelProvidersConfig = {
|
||||
...(settings.merged.modelProviders as
|
||||
|
|
@ -515,8 +524,8 @@ export const useAuthCommand = (
|
|||
{
|
||||
type: MessageType.INFO,
|
||||
text: t(
|
||||
'Authenticated successfully with Alibaba Cloud Standard API Key. Settings updated with env.DASHSCOPE_API_KEY and model "{{modelId}}".',
|
||||
{ modelId: trimmedModelId },
|
||||
'Authenticated successfully with Alibaba Cloud Standard API Key. Settings updated with env.DASHSCOPE_API_KEY and {{modelCount}} model(s).',
|
||||
{ modelCount: String(modelIds.length) },
|
||||
),
|
||||
},
|
||||
Date.now(),
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ export interface UIActions {
|
|||
handleAlibabaStandardSubmit: (
|
||||
apiKey: string,
|
||||
region: AlibabaStandardRegion,
|
||||
modelId: string,
|
||||
modelIdsInput: string,
|
||||
) => Promise<void>;
|
||||
setAuthState: (state: AuthState) => void;
|
||||
onAuthError: (error: string | null) => void;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue