diff --git a/index.html b/index.html
index 9cc13ac..20baa8b 100644
--- a/index.html
+++ b/index.html
@@ -66,16 +66,11 @@
if (!!data.reader) addMessageStream(data, response)
}
- function alterTextArea(textArea) {
- textArea.style.height = 'auto';
- textArea.style.height = (textArea.scrollHeight + 2) + 'px';
- }
+ function updateMessage(data, message, updated) {
+ const index = data.messages.indexOf(message)
- function checkSubmit(e, data) {
- if (e.key == 'Enter' && !e.shiftKey && !data.busy) {
- e.preventDefault()
- sendMessage(data, { role: 'user', content: data.content })
- }
+ data.messages[index] = { ...message, ...updated }
+ Messages.update(message.id, updated)
}
function deleteMessage(data, message, drop = false) {
@@ -87,6 +82,20 @@
Messages.remove(message.id, drop)
}
+ //
+
+ function alterTextArea(textArea) {
+ textArea.style.height = 'auto';
+ textArea.style.height = (textArea.scrollHeight + 2) + 'px';
+ }
+
+ function checkSubmit(e, data) {
+ if (e.key == 'Enter' && !e.shiftKey && !data.busy) {
+ e.preventDefault()
+ sendMessage(data, { role: 'user', content: data.content })
+ }
+ }
+
// Profile
function loadProfile(data) {
const profile = Profile.get()
@@ -127,12 +136,13 @@
Alpine.store('modalConnection', false)
Alpine.store('modalCharacter', false)
Alpine.store('modalTune', false)
+ Alpine.store('modalNotes', false)
})
-
+
-
+
Assistant
+
+ keep
+
+
more_vert
@@ -281,20 +304,52 @@
+
+
\ No newline at end of file
diff --git a/script.js b/script.js
index ed8edb7..72cb949 100644
--- a/script.js
+++ b/script.js
@@ -8,25 +8,38 @@ class Messages {
return lastId
}
- static list() {
+ static list(notes=false) {
const messagesString = localStorage.getItem('messages')
if (messagesString === null) return []
- return JSON.parse(messagesString)
+ let messages = JSON.parse(messagesString)
+
+ if(notes) messages = messages.filter(msg => !!msg.pinned)
+ return messages
}
- static update(messages) {
+ static updateAll(messages) {
localStorage.setItem('messages', JSON.stringify(messages))
}
- static add({ content, role }) {
- const message = { id: Messages.#getNextId(), content, role }
+ static add(message) {
+ const added = { id: Messages.#getNextId(), pinned: false, ...message }
let messages = Messages.list()
- messages.push(message)
- Messages.update(messages)
+ messages.push(added)
+ Messages.updateAll(messages)
- return message
+ return added
+ }
+
+ static update(id, message) {
+ let messages = Messages.list()
+
+ const index = messages.findIndex(item => item.id == id)
+ if (index == -1) return
+
+ messages[index] = { ...messages[index], ...message }
+ Messages.updateAll(messages)
}
static remove(id, drop=false) {
@@ -37,7 +50,7 @@ class Messages {
if(drop) messages.splice(index)
else messages.splice(index, 1)
- Messages.update(messages)
+ Messages.updateAll(messages)
}
}
@@ -84,13 +97,24 @@ class Completions {
static async * send() {
const profile = Profile.get()
+ // Messages
let messages = Messages.list()
+
+ messages.unshift({ role: 'system', content: '### Chat history' })
+
if (!!profile.main) messages.unshift({ role: 'system', content: profile.main })
if (!!profile.jailbreak) messages.push({ role: 'system', content: profile.jailbreak })
messages = messages.slice(-profile.max_messages)
- console.log(messages)
+ // Notes
+ let notes = Messages.list(true)
+
+ if (notes.length > 0) {
+ notes.forEach(msg => msg.role = 'system')
+ messages.unshift(...notes)
+ messages.unshift({ role: 'system', content: '### Notes (pinned messages containing important information)' })
+ }
const request = {
messages,
@@ -99,6 +123,8 @@ class Completions {
stream: true
}
+ console.log(request)
+
const url = profile.base_url + 'chat/completions'
const headers = {
"Authorization": `Bearer ${profile.api_key}`,
diff --git a/style.css b/style.css
index ec1518c..fefb5e4 100644
--- a/style.css
+++ b/style.css
@@ -95,4 +95,10 @@ article header{
article header details {
margin-bottom: 0;
+}
+
+
+dialog article main article {
+ border: var(--pico-border-width) solid var(--pico-muted-border-color);
+ /* box-shadow: var(--pico-card-box-shadow) */
}
\ No newline at end of file