| 21 | } |
| 22 | |
| 23 | function updateMessage(existingId, text, model = null) { |
| 24 | if (!existingId) { |
| 25 | return; |
| 26 | } |
| 27 | update((state) => { |
| 28 | const messages = state.data; |
| 29 | const existingIdIndex = messages.findIndex((m) => m.id === existingId); |
| 30 | if (existingIdIndex === -1) { |
| 31 | return state; |
| 32 | } |
| 33 | messages[existingIdIndex].text += text; |
| 34 | if (model) { |
| 35 | messages[existingIdIndex].model = model; |
| 36 | } |
| 37 | return { ...state, data: messages }; |
| 38 | }); |
| 39 | } |
| 40 | |
| 41 | async function send(question, ragMode = false) { |
| 42 | if (!question.trim().length) { |