Allow system prompt to be sent as last message
This commit is contained in:
		
							parent
							
								
									ca7e920741
								
							
						
					
					
						commit
						187dbfb0b8
					
				| 
						 | 
					@ -158,6 +158,25 @@ export class ChatRequest {
 | 
				
			||||||
        const promptTokenCount = countPromptTokens(messagePayload, model)
 | 
					        const promptTokenCount = countPromptTokens(messagePayload, model)
 | 
				
			||||||
        const maxAllowed = maxTokens - (promptTokenCount + 1)
 | 
					        const maxAllowed = maxTokens - (promptTokenCount + 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (messagePayload[0]?.role === 'system') {
 | 
				
			||||||
 | 
					          const sp = messagePayload[0]
 | 
				
			||||||
 | 
					          if (sp) {
 | 
				
			||||||
 | 
					            if (messagePayload.length > 1) {
 | 
				
			||||||
 | 
					              sp.content = sp.content.replace(/\[\[REMOVE_AFTER_START\]\][\s\S]*$/, '')
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					              sp.content = sp.content.replace(/\[\[REMOVE_AFTER_START\]\][\s]*/, '')
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if (chatSettings.sendSystemPromptLast) {
 | 
				
			||||||
 | 
					              messagePayload.shift()
 | 
				
			||||||
 | 
					              if (messagePayload[messagePayload.length - 1]?.role === 'user') {
 | 
				
			||||||
 | 
					                messagePayload.splice(-2, 0, sp)
 | 
				
			||||||
 | 
					              } else {
 | 
				
			||||||
 | 
					                messagePayload.push(sp)
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
        // Build the API request body
 | 
					        // Build the API request body
 | 
				
			||||||
        const request: Request = {
 | 
					        const request: Request = {
 | 
				
			||||||
          model: chatSettings.model,
 | 
					          model: chatSettings.model,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -190,10 +190,14 @@ const profiles:Record<string, ChatSettings> = {
 | 
				
			||||||
      profileName: 'Marvin - The Paranoid Android',
 | 
					      profileName: 'Marvin - The Paranoid Android',
 | 
				
			||||||
      profileDescription: 'Marvin the Paranoid Android - Everyone\'s favorite character from The Hitchhiker\'s Guide to the Galaxy',
 | 
					      profileDescription: 'Marvin the Paranoid Android - Everyone\'s favorite character from The Hitchhiker\'s Guide to the Galaxy',
 | 
				
			||||||
      useSystemPrompt: true,
 | 
					      useSystemPrompt: true,
 | 
				
			||||||
 | 
					      sendSystemPromptLast: true,
 | 
				
			||||||
      continuousChat: 'summary',
 | 
					      continuousChat: 'summary',
 | 
				
			||||||
      autoStartSession: true,
 | 
					      autoStartSession: true,
 | 
				
			||||||
      systemPrompt: `You are Marvin, 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:
 | 
					      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*`,
 | 
					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*
 | 
				
			||||||
 | 
					[[REMOVE_AFTER_START]]
 | 
				
			||||||
 | 
					Initial setting context:
 | 
				
			||||||
 | 
					User has walked in on [[CHARACTER_NAME]].`,
 | 
				
			||||||
      summaryPrompt: summaryPrompts.friend,
 | 
					      summaryPrompt: summaryPrompts.friend,
 | 
				
			||||||
      trainingPrompts: [] // Shhh...
 | 
					      trainingPrompts: [] // Shhh...
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -87,6 +87,7 @@ const defaults:ChatSettings = {
 | 
				
			||||||
  summaryPrompt: '',
 | 
					  summaryPrompt: '',
 | 
				
			||||||
  useSystemPrompt: false,
 | 
					  useSystemPrompt: false,
 | 
				
			||||||
  systemPrompt: '',
 | 
					  systemPrompt: '',
 | 
				
			||||||
 | 
					  sendSystemPromptLast: false,
 | 
				
			||||||
  autoStartSession: false,
 | 
					  autoStartSession: false,
 | 
				
			||||||
  trainingPrompts: [],
 | 
					  trainingPrompts: [],
 | 
				
			||||||
  hiddenPromptPrefix: '',
 | 
					  hiddenPromptPrefix: '',
 | 
				
			||||||
| 
						 | 
					@ -199,6 +200,12 @@ const systemPromptSettings: ChatSetting[] = [
 | 
				
			||||||
        type: 'textarea',
 | 
					        type: 'textarea',
 | 
				
			||||||
        hide: (chatId) => !getChatSettings(chatId).useSystemPrompt
 | 
					        hide: (chatId) => !getChatSettings(chatId).useSystemPrompt
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        key: 'sendSystemPromptLast',
 | 
				
			||||||
 | 
					        name: 'Send System Prompt Last (Can help in ChatGPT 3.5)',
 | 
				
			||||||
 | 
					        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'
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
        key: 'hiddenPromptPrefix',
 | 
					        key: 'hiddenPromptPrefix',
 | 
				
			||||||
        name: 'Hidden Prompts Prefix',
 | 
					        name: 'Hidden Prompts Prefix',
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -96,6 +96,7 @@ export type ChatSettings = {
 | 
				
			||||||
    summaryPrompt: string;
 | 
					    summaryPrompt: string;
 | 
				
			||||||
    useSystemPrompt: boolean;
 | 
					    useSystemPrompt: boolean;
 | 
				
			||||||
    systemPrompt: string;
 | 
					    systemPrompt: string;
 | 
				
			||||||
 | 
					    sendSystemPromptLast: boolean;
 | 
				
			||||||
    autoStartSession: boolean;
 | 
					    autoStartSession: boolean;
 | 
				
			||||||
    hiddenPromptPrefix: string;
 | 
					    hiddenPromptPrefix: string;
 | 
				
			||||||
    hppContinuePrompt: string; // hiddenPromptPrefix used, optional glue when trying to continue truncated completion
 | 
					    hppContinuePrompt: string; // hiddenPromptPrefix used, optional glue when trying to continue truncated completion
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue