修改预设发送时机
This commit is contained in:
+5
-55
@@ -809,10 +809,6 @@ function resetNewConversation({ preserveInput = false } = {}) {
|
|||||||
|
|
||||||
async function newConversation() {
|
async function newConversation() {
|
||||||
if (pending) return;
|
if (pending) return;
|
||||||
if (getPresetPrompt()) {
|
|
||||||
await startPresetConversation();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
resetNewConversation();
|
resetNewConversation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1060,53 +1056,11 @@ async function streamChat(messages, aiBubble) {
|
|||||||
return full;
|
return full;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function startPresetConversation({ preserveInput = false } = {}) {
|
function ensurePresetLoaded() {
|
||||||
|
if (currentConvId || history.length > 0) return;
|
||||||
const preset = getPresetPrompt();
|
const preset = getPresetPrompt();
|
||||||
if (!preset) {
|
if (!preset) return;
|
||||||
resetNewConversation({ preserveInput });
|
history = [{ role: 'system', content: preset, hidden: true }];
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pending = true;
|
|
||||||
setInputDisabled(true);
|
|
||||||
const keepText = preserveInput ? inputBox.value : '';
|
|
||||||
let aiBubble = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
resetNewConversation({ preserveInput });
|
|
||||||
inputBox.value = keepText;
|
|
||||||
autoResize();
|
|
||||||
clearImage();
|
|
||||||
|
|
||||||
const conv = await createConversation();
|
|
||||||
currentConvId = conv.id;
|
|
||||||
await loadConversationList();
|
|
||||||
|
|
||||||
history = [
|
|
||||||
{ role: 'system', content: preset, hidden: true },
|
|
||||||
{
|
|
||||||
role: 'user',
|
|
||||||
content: '请根据以上预先提示词,用简短自然的方式输出开场白,然后等待用户开始聊天。',
|
|
||||||
hidden: true
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
aiBubble = addAIBubble();
|
|
||||||
const full = await streamChat(history, aiBubble);
|
|
||||||
history.push({ role: 'assistant', content: full });
|
|
||||||
scrollToBottom();
|
|
||||||
await loadConversationList();
|
|
||||||
} catch (e) {
|
|
||||||
if (!aiBubble) aiBubble = addAIBubble();
|
|
||||||
aiBubble.txt.innerHTML = `<span class="error-msg">错误: ${escHtml(e.message)}</span>`;
|
|
||||||
aiBubble.bub.classList.remove('typing-cursor');
|
|
||||||
} finally {
|
|
||||||
pending = false;
|
|
||||||
setInputDisabled(false);
|
|
||||||
inputBox.value = keepText;
|
|
||||||
autoResize();
|
|
||||||
inputBox.focus();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── 发送消息 ──────────────────────────────────────────────
|
// ── 发送消息 ──────────────────────────────────────────────
|
||||||
@@ -1115,17 +1069,13 @@ async function sendMessage() {
|
|||||||
const userText = inputBox.value.trim();
|
const userText = inputBox.value.trim();
|
||||||
if (!userText && !imageB64) return;
|
if (!userText && !imageB64) return;
|
||||||
|
|
||||||
if (!currentConvId && history.length === 0 && getPresetPrompt()) {
|
|
||||||
await startPresetConversation({ preserveInput: true });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pending = true;
|
pending = true;
|
||||||
setInputDisabled(true);
|
setInputDisabled(true);
|
||||||
let aiBubble = null;
|
let aiBubble = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!currentConvId) {
|
if (!currentConvId) {
|
||||||
|
ensurePresetLoaded();
|
||||||
const conv = await createConversation();
|
const conv = await createConversation();
|
||||||
currentConvId = conv.id;
|
currentConvId = conv.id;
|
||||||
await loadConversationList();
|
await loadConversationList();
|
||||||
|
|||||||
Reference in New Issue
Block a user