模型配置相关
This commit is contained in:
@@ -240,15 +240,48 @@ const handleCreatePrivateModelAndSetChat = async () => {
|
||||
|
||||
// 基于内置模型创建新模型(继承原模型的所有配置,只替换 apiKey)
|
||||
const builtInModel = builtInModelToClone.value;
|
||||
|
||||
// Parse headMsg to Record<string, string> - it might be stored as string or already as object
|
||||
let headMsgRecord: Record<string, string> = {};
|
||||
if (builtInModel.headMsg && typeof builtInModel.headMsg === 'string') {
|
||||
// Try to parse as JSON first (new format stored as string)
|
||||
try {
|
||||
const parsed = JSON.parse(builtInModel.headMsg);
|
||||
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
||||
Object.entries(parsed).forEach(([k, v]) => {
|
||||
headMsgRecord[k] = String(v);
|
||||
});
|
||||
}
|
||||
} catch {
|
||||
// If JSON parse fails, parse as old format "key1:value1,key2:value2"
|
||||
const pairs = builtInModel.headMsg.split(',');
|
||||
pairs.forEach((pair: string) => {
|
||||
const idx = pair.indexOf(':');
|
||||
if (idx === -1) return;
|
||||
const key = pair.slice(0, idx).trim();
|
||||
const value = pair.slice(idx + 1).trim();
|
||||
if (key) {
|
||||
headMsgRecord[key] = value;
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (builtInModel.headMsg && typeof builtInModel.headMsg === 'object' && !Array.isArray(builtInModel.headMsg)) {
|
||||
// Already an object
|
||||
Object.entries(builtInModel.headMsg).forEach(([k, v]) => {
|
||||
headMsgRecord[k] = String(v);
|
||||
});
|
||||
}
|
||||
|
||||
const createParams = {
|
||||
modelName: apiKeyForm.modelName,
|
||||
modelType: builtInModel.modelType,
|
||||
baseUrl: builtInModel.baseUrl,
|
||||
httpMethod: builtInModel.httpMethod || 'POST',
|
||||
headMsg: builtInModel.headMsg || '',
|
||||
headMsg: headMsgRecord,
|
||||
isPrivate: builtInModel.isPrivate ?? 1,
|
||||
enabled: builtInModel.enabled ?? 1,
|
||||
isChatModel: 1, // 设置为会话模型
|
||||
isAsync: builtInModel.isAsync ?? 0,
|
||||
apiKey: apiKeyForm.apiKey,
|
||||
form: builtInModel.form || {},
|
||||
requestMapping: builtInModel.requestMapping || {},
|
||||
|
||||
Reference in New Issue
Block a user