refac: many model chat
This commit is contained in:
@@ -562,7 +562,7 @@
|
||||
content: userPrompt,
|
||||
files: _files.length > 0 ? _files : undefined,
|
||||
timestamp: Math.floor(Date.now() / 1000), // Unix epoch
|
||||
models: selectedModels.filter((m, mIdx) => selectedModels.indexOf(m) === mIdx)
|
||||
models: selectedModels
|
||||
};
|
||||
|
||||
// Add message to history and Set currentId to messageId
|
||||
@@ -582,7 +582,11 @@
|
||||
return _responses;
|
||||
};
|
||||
|
||||
const sendPrompt = async (prompt, parentId, { modelId = null, newChat = false } = {}) => {
|
||||
const sendPrompt = async (
|
||||
prompt,
|
||||
parentId,
|
||||
{ modelId = null, modelIdx = null, newChat = false } = {}
|
||||
) => {
|
||||
let _responses = [];
|
||||
|
||||
// If modelId is provided, use it, else use selected model
|
||||
@@ -594,7 +598,7 @@
|
||||
|
||||
// Create response messages for each selected model
|
||||
const responseMessageIds = {};
|
||||
for (const modelId of selectedModelIds) {
|
||||
for (const [_modelIdx, modelId] of selectedModelIds.entries()) {
|
||||
const model = $models.filter((m) => m.id === modelId).at(0);
|
||||
|
||||
if (model) {
|
||||
@@ -607,6 +611,7 @@
|
||||
content: '',
|
||||
model: model.id,
|
||||
modelName: model.name ?? model.id,
|
||||
modelIdx: modelIdx ? modelIdx : _modelIdx,
|
||||
userContext: null,
|
||||
timestamp: Math.floor(Date.now() / 1000) // Unix epoch
|
||||
};
|
||||
@@ -623,7 +628,7 @@
|
||||
];
|
||||
}
|
||||
|
||||
responseMessageIds[modelId] = responseMessageId;
|
||||
responseMessageIds[`${modelId}-${modelIdx ? modelIdx : _modelIdx}`] = responseMessageId;
|
||||
}
|
||||
}
|
||||
await tick();
|
||||
@@ -655,7 +660,7 @@
|
||||
const _chatId = JSON.parse(JSON.stringify($chatId));
|
||||
|
||||
await Promise.all(
|
||||
selectedModelIds.map(async (modelId) => {
|
||||
selectedModelIds.map(async (modelId, _modelIdx) => {
|
||||
console.log('modelId', modelId);
|
||||
const model = $models.filter((m) => m.id === modelId).at(0);
|
||||
|
||||
@@ -673,7 +678,8 @@
|
||||
);
|
||||
}
|
||||
|
||||
let responseMessageId = responseMessageIds[modelId];
|
||||
let responseMessageId =
|
||||
responseMessageIds[`${modelId}-${modelIdx ? modelIdx : _modelIdx}`];
|
||||
let responseMessage = history.messages[responseMessageId];
|
||||
|
||||
let userContext = null;
|
||||
@@ -1350,7 +1356,10 @@
|
||||
} else {
|
||||
// If there are multiple models selected, use the model of the response message for regeneration
|
||||
// e.g. many model chat
|
||||
await sendPrompt(userPrompt, userMessage.id, { modelId: message.model });
|
||||
await sendPrompt(userPrompt, userMessage.id, {
|
||||
modelId: message.model,
|
||||
modelIdx: message.modelIdx
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user