Fix runaway name appending on the default AI preset (#1051)

Shallow copy the presets when updating `display:name` so that the
appending of the model name for the default preset doesn't accumulate
every time the tab refreshes.

closes #1040
This commit is contained in:
Evan Simkowitz 2024-10-17 12:53:49 -04:00 committed by GitHub
parent 924d1495a3
commit a90e747f92
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -81,12 +81,12 @@ export class WaveAiModel implements ViewModel {
.filter(([k]) => k.startsWith("ai@"))
.map(([k, v]) => {
const aiPresetKeys = Object.keys(v).filter((k) => k.startsWith("ai:"));
console.log(aiPresetKeys);
v["display:name"] =
const newV = { ...v };
newV["display:name"] =
aiPresetKeys.length == 1 && aiPresetKeys.includes("ai:*")
? `${v["display:name"] ?? "Default"} (${settings["ai:model"]})`
: v["display:name"];
return [k, v];
? `${newV["display:name"] ?? "Default"} (${settings["ai:model"]})`
: newV["display:name"];
return [k, newV];
})
);
});
@ -109,7 +109,7 @@ export class WaveAiModel implements ViewModel {
messages.pop();
set(this.messagesAtom, [...messages]);
});
this.simulateAssistantResponseAtom = atom(null, async (get, set, userMessage: ChatMessageType) => {
this.simulateAssistantResponseAtom = atom(null, async (_, set, userMessage: ChatMessageType) => {
// unused at the moment. can replace the temp() function in the future
const typingMessage: ChatMessageType = {
id: crypto.randomUUID(),
@ -213,7 +213,7 @@ export class WaveAiModel implements ViewModel {
}
async fetchAiData(): Promise<Array<OpenAIPromptMessageType>> {
const { data, fileInfo } = await fetchWaveFile(this.blockId, "aidata");
const { data } = await fetchWaveFile(this.blockId, "aidata");
if (!data) {
return [];
}
@ -318,7 +318,6 @@ export class WaveAiModel implements ViewModel {
content: errMsg,
};
updatedHist.push(errorPrompt);
console.log(updatedHist);
await BlockService.SaveWaveAiData(blockId, updatedHist);
}
setLocked(false);