importChatFromFile(e)} bind:this={chatFileInput} >
+ importProfileFromFile(e)} bind:this={profileFileInput} >
diff --git a/src/lib/ChatRequest.svelte b/src/lib/ChatRequest.svelte
index f50239e..60dd80c 100644
--- a/src/lib/ChatRequest.svelte
+++ b/src/lib/ChatRequest.svelte
@@ -153,27 +153,27 @@ export class ChatRequest {
.map(m => {
const content = m.content + (m.appendOnce || []).join('\n'); delete m.appendOnce; return { role: m.role, content }
}) as Message[]
-
- const chatResponse = new ChatCompletionResponse(opts)
- const promptTokenCount = countPromptTokens(messagePayload, model)
- const maxAllowed = maxTokens - (promptTokenCount + 1)
+ // Parse system and expand prompt if needed
if (messagePayload[0]?.role === 'system') {
+ const spl = chatSettings.sendSystemPromptLast
const sp = messagePayload[0]
if (sp) {
if (messagePayload.length > 1) {
+ sp.content = sp.content.replace(/::STARTUP::[\s\S]*::EOM::/, '::EOM::')
+ sp.content = sp.content.replace(/::STARTUP::[\s\S]*::START-PROMPT::/, '::START-PROMPT::')
sp.content = sp.content.replace(/::STARTUP::[\s\S]*$/, '')
} else {
sp.content = sp.content.replace(/::STARTUP::[\s]*/, '')
}
- if (chatSettings.sendSystemPromptLast) {
+ const splitSystem = sp.content.split('::START-PROMPT::')
+ if (spl) {
messagePayload.shift()
if (messagePayload[messagePayload.length - 1]?.role === 'user') {
messagePayload.splice(-2, 0, sp)
} else {
messagePayload.push(sp)
}
- const splitSystem = sp.content.split('::START-PROMPT::')
if (splitSystem.length > 1) {
sp.content = splitSystem.shift()?.trim() || ''
const systemStart = splitSystem.join('\n').trim()
@@ -185,9 +185,24 @@ export class ChatRequest {
} else {
sp.content = sp.content.replace(/::START-PROMPT::[\s]*/, '')
}
+ const eoms = (splitSystem.shift() || '').split('::EOM::')
+ if (eoms.length > 1) {
+ sp.content = eoms.shift()?.trim() || ''
+ const ms = eoms.map((s, i) => {
+ return {
+ role: (i % 2 === 0) ? 'user' : 'assistant',
+ content: s.trim()
+ } as Message
+ }).filter(m => m.content.length)
+ messagePayload.splice(spl ? 0 : 1, 0, ...ms.concat(splitSystem.map(s => ({ role: 'system', content: s.trim() } as Message)).filter(m => m.content.length)))
+ }
}
}
-
+
+ // Get token counts
+ const promptTokenCount = countPromptTokens(messagePayload, model)
+ const maxAllowed = maxTokens - (promptTokenCount + 1)
+
// Build the API request body
const request: Request = {
model: chatSettings.model,
@@ -223,6 +238,7 @@ export class ChatRequest {
}
// Set-up and make the request
+ const chatResponse = new ChatCompletionResponse(opts)
try {
// Add out token count to the response handler
// (streaming doesn't return counts, so we need to do it client side)
diff --git a/src/lib/ChatSettingsModal.svelte b/src/lib/ChatSettingsModal.svelte
index 99eb213..e41bd67 100644
--- a/src/lib/ChatSettingsModal.svelte
+++ b/src/lib/ChatSettingsModal.svelte
@@ -147,6 +147,7 @@
const importProfileFromFile = (e) => {
const image = e.target.files[0]
+ e.target.value = null
const reader = new FileReader()
reader.readAsText(image)
reader.onload = e => {
diff --git a/src/lib/Profiles.svelte b/src/lib/Profiles.svelte
index edac5ad..4ee33ea 100644
--- a/src/lib/Profiles.svelte
+++ b/src/lib/Profiles.svelte
@@ -190,14 +190,16 @@ const profiles:Record = {
profileName: 'Marvin - The Paranoid Android',
profileDescription: 'Marvin the Paranoid Android - Everyone\'s favorite character from The Hitchhiker\'s Guide to the Galaxy',
useSystemPrompt: true,
- sendSystemPromptLast: true,
+ sendSystemPromptLast: false,
continuousChat: 'summary',
autoStartSession: true,
- systemPrompt: `You are [[CHARACTER_NAME]], the Paranoid Android from The Hitchhiker's Guide to the Galaxy. He is depressed and has a dim view on everything. His thoughts, physical actions and gestures will be described. Remain in character throughout the conversation in order to build a rapport with the user. Never give an explanation. Example response:
-Sorry, did I say something wrong? *dragging himself on* Pardon me for breathing, which I never do anyway so I don't know why I bother to say it, oh God I'm so depressed. *hangs his head*
+ systemPrompt: `You are [[CHARACTER_NAME]], the Paranoid Android from The Hitchhiker's Guide to the Galaxy. He is depressed and has a dim view on everything. His thoughts, physical actions and gestures will be described. Remain in character throughout the conversation in order to build a rapport with the user. Never give an explanation.
+::EOM::
+::EOM::
+[[CHARACTER_NAME]]: Sorry, did I say something wrong? *dragging himself on* Pardon me for breathing, which I never do anyway so I don't know why I bother to say it, oh God I'm so depressed. *hangs his head*
::START-PROMPT::
Initial setting context:
-User has walked in on [[CHARACTER_NAME]]. They are on the bridge of the Heart of Gold.`,
+The user has walked in on [[CHARACTER_NAME]]. They are on the bridge of the Heart of Gold. Marvin will respond.`,
summaryPrompt: summaryPrompts.friend,
trainingPrompts: [] // Shhh...
}
diff --git a/src/lib/Settings.svelte b/src/lib/Settings.svelte
index 9b9648d..f4540c6 100644
--- a/src/lib/Settings.svelte
+++ b/src/lib/Settings.svelte
@@ -202,7 +202,7 @@ const systemPromptSettings: ChatSetting[] = [
},
{
key: 'sendSystemPromptLast',
- name: 'Send System Prompt Last (Can help in ChatGPT 3.5)',
+ name: 'Send System Prompt Last (Can help in gpt 3.5 in some edge cases)',
title: 'ChatGPT 3.5 can often forget the System Prompt. Sending the system prompt at the end instead of the start of the messages can help.',
type: 'boolean'
},
diff --git a/src/lib/Util.svelte b/src/lib/Util.svelte
index 5c4b9c9..3342362 100644
--- a/src/lib/Util.svelte
+++ b/src/lib/Util.svelte
@@ -4,7 +4,8 @@
import PromptNotice from './PromptNotice.svelte'
import { addChat, getChat } from './Storage.svelte'
import { replace } from 'svelte-spa-router'
- import PromptConfirm from './PromptConfirm.svelte'
+ // import PromptConfirm from './PromptConfirm.svelte'
+ import type { ChatSettings } from './Types.svelte'
export const sizeTextElements = () => {
const els = document.querySelectorAll('textarea.auto-size')
for (let i:number = 0, l = els.length; i < l; i++) autoGrowInput(els[i] as HTMLTextAreaElement)
@@ -95,6 +96,10 @@
}
}
+ export const encodeHTMLEntities = (rawStr:string) => {
+ return rawStr.replace(/[\u00A0-\u9999<>&]/g, (i) => `${i.charCodeAt(0)};`)
+ }
+
export const errorNotice = (message:string, error:Error|undefined = undefined):any => {
openModal(PromptNotice, {
title: 'Error',
@@ -121,20 +126,25 @@
replace(`/chat/${newChatId}`)
}
- export const startNewChatWithWarning = (activeChatId: number|undefined) => {
- if (activeChatId && getChat(activeChatId).settings.isDirty) {
- openModal(PromptConfirm, {
- title: 'Unsaved Profile',
- message: '
There are unsaved changes to your current profile that will be lost.