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 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
 | 
			
		||||
        const request: Request = {
 | 
			
		||||
          model: chatSettings.model,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -190,10 +190,14 @@ const profiles:Record<string, ChatSettings> = {
 | 
			
		|||
      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,
 | 
			
		||||
      continuousChat: 'summary',
 | 
			
		||||
      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:
 | 
			
		||||
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. 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*
 | 
			
		||||
[[REMOVE_AFTER_START]]
 | 
			
		||||
Initial setting context:
 | 
			
		||||
User has walked in on [[CHARACTER_NAME]].`,
 | 
			
		||||
      summaryPrompt: summaryPrompts.friend,
 | 
			
		||||
      trainingPrompts: [] // Shhh...
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -87,6 +87,7 @@ const defaults:ChatSettings = {
 | 
			
		|||
  summaryPrompt: '',
 | 
			
		||||
  useSystemPrompt: false,
 | 
			
		||||
  systemPrompt: '',
 | 
			
		||||
  sendSystemPromptLast: false,
 | 
			
		||||
  autoStartSession: false,
 | 
			
		||||
  trainingPrompts: [],
 | 
			
		||||
  hiddenPromptPrefix: '',
 | 
			
		||||
| 
						 | 
				
			
			@ -195,10 +196,16 @@ const systemPromptSettings: ChatSetting[] = [
 | 
			
		|||
        key: 'systemPrompt',
 | 
			
		||||
        name: 'System Prompt',
 | 
			
		||||
        title: 'First prompt to send.',
 | 
			
		||||
        placeholder: 'Enter the first prompt to send here.  You can tell ChatGPT how to act.',
 | 
			
		||||
        placeholder: 'Enter the first prompt to send here. You can tell ChatGPT how to act.',
 | 
			
		||||
        type: 'textarea',
 | 
			
		||||
        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',
 | 
			
		||||
        name: 'Hidden Prompts Prefix',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -96,6 +96,7 @@ export type ChatSettings = {
 | 
			
		|||
    summaryPrompt: string;
 | 
			
		||||
    useSystemPrompt: boolean;
 | 
			
		||||
    systemPrompt: string;
 | 
			
		||||
    sendSystemPromptLast: boolean;
 | 
			
		||||
    autoStartSession: boolean;
 | 
			
		||||
    hiddenPromptPrefix: string;
 | 
			
		||||
    hppContinuePrompt: string; // hiddenPromptPrefix used, optional glue when trying to continue truncated completion
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue