feat: add preset aliyun qwen model switching
This commit is contained in:
@@ -10,6 +10,12 @@ import type {
|
||||
AiProvider,
|
||||
MasterIdentitySummary,
|
||||
} from "@/lib/boss-data";
|
||||
import {
|
||||
ALIYUN_QWEN_CUSTOM_MODEL_VALUE,
|
||||
ALIYUN_QWEN_PRESET_MODELS,
|
||||
resolveAliyunQwenModelSelection,
|
||||
resolveAliyunQwenModelValue,
|
||||
} from "@/lib/ai-account-models";
|
||||
import { formatTimestampLabel } from "@/lib/boss-projections";
|
||||
|
||||
type AccountDraft = {
|
||||
@@ -185,6 +191,45 @@ function AccountField({
|
||||
);
|
||||
}
|
||||
|
||||
function AliyunQwenModelField({
|
||||
value,
|
||||
onChange,
|
||||
}: {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
}) {
|
||||
const selection = resolveAliyunQwenModelSelection(value);
|
||||
const isCustom = selection === ALIYUN_QWEN_CUSTOM_MODEL_VALUE;
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<label className="space-y-1">
|
||||
<div className="text-[12px] text-[#8C8C8C]">模型</div>
|
||||
<select
|
||||
value={selection}
|
||||
onChange={(event) => onChange(resolveAliyunQwenModelValue(event.target.value, value))}
|
||||
className="w-full rounded-xl border border-[#E5E5EA] bg-[#F7F8FA] px-3 py-2 text-[13px] text-[#111111] outline-none"
|
||||
>
|
||||
{ALIYUN_QWEN_PRESET_MODELS.map((model) => (
|
||||
<option key={model} value={model}>
|
||||
{model}
|
||||
</option>
|
||||
))}
|
||||
<option value={ALIYUN_QWEN_CUSTOM_MODEL_VALUE}>自定义模型</option>
|
||||
</select>
|
||||
</label>
|
||||
{isCustom ? (
|
||||
<AccountField
|
||||
label="自定义模型"
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
placeholder="例如:qwen-max"
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function AiAccountsClient({
|
||||
accounts,
|
||||
activeIdentity,
|
||||
@@ -617,12 +662,19 @@ export function AiAccountsClient({
|
||||
onChange={(value) => updateDraft(account.accountId, (current) => ({ ...current, nodeId: value }))}
|
||||
placeholder="例如:mac-studio"
|
||||
/>
|
||||
<AccountField
|
||||
label="模型"
|
||||
value={draft.model}
|
||||
onChange={(value) => updateDraft(account.accountId, (current) => ({ ...current, model: value }))}
|
||||
placeholder="例如:gpt-5.4"
|
||||
/>
|
||||
{draft.provider === "aliyun_qwen_api" ? (
|
||||
<AliyunQwenModelField
|
||||
value={draft.model}
|
||||
onChange={(value) => updateDraft(account.accountId, (current) => ({ ...current, model: value }))}
|
||||
/>
|
||||
) : (
|
||||
<AccountField
|
||||
label="模型"
|
||||
value={draft.model}
|
||||
onChange={(value) => updateDraft(account.accountId, (current) => ({ ...current, model: value }))}
|
||||
placeholder="例如:gpt-5.4"
|
||||
/>
|
||||
)}
|
||||
{draft.provider === "openai_api" || draft.provider === "aliyun_qwen_api" ? (
|
||||
<div className="col-span-2">
|
||||
<AccountField
|
||||
@@ -856,13 +908,11 @@ export function AiAccountsClient({
|
||||
}
|
||||
placeholder="例如:dashscope 账号备注"
|
||||
/>
|
||||
<AccountField
|
||||
label="模型"
|
||||
<AliyunQwenModelField
|
||||
value={aliyunQwenOnboardDraft.model}
|
||||
onChange={(value) =>
|
||||
setAliyunQwenOnboardDraft((current) => ({ ...current, model: value }))
|
||||
}
|
||||
placeholder="例如:qwen3.5-plus"
|
||||
/>
|
||||
<AccountField
|
||||
label="API Key"
|
||||
|
||||
19
src/lib/ai-account-models.ts
Normal file
19
src/lib/ai-account-models.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export const ALIYUN_QWEN_PRESET_MODELS = ["qwen3.5-plus", "qwen3.5-flash"] as const;
|
||||
|
||||
export const ALIYUN_QWEN_CUSTOM_MODEL_VALUE = "__custom__";
|
||||
|
||||
export function isAliyunQwenPresetModel(model: string | null | undefined) {
|
||||
const trimmed = model?.trim() ?? "";
|
||||
return ALIYUN_QWEN_PRESET_MODELS.includes(trimmed as (typeof ALIYUN_QWEN_PRESET_MODELS)[number]);
|
||||
}
|
||||
|
||||
export function resolveAliyunQwenModelSelection(model: string | null | undefined) {
|
||||
return isAliyunQwenPresetModel(model) ? (model?.trim() ?? "") : ALIYUN_QWEN_CUSTOM_MODEL_VALUE;
|
||||
}
|
||||
|
||||
export function resolveAliyunQwenModelValue(selection: string, customModel: string) {
|
||||
if (selection === ALIYUN_QWEN_CUSTOM_MODEL_VALUE) {
|
||||
return customModel.trim();
|
||||
}
|
||||
return selection.trim();
|
||||
}
|
||||
Reference in New Issue
Block a user