forked from open-webui/open-webui
		
	fix: replace all instances of prompt:start and prompt:end
This commit is contained in:
		
							parent
							
								
									db817fcf29
								
							
						
					
					
						commit
						fffd42e4d7
					
				
					 1 changed files with 9 additions and 7 deletions
				
			
		|  | @ -473,19 +473,21 @@ export const blobToFile = (blob, fileName) => { | |||
| // {{prompt:start:<length>}} will be replaced with the first <length> characters of the prompt
 | ||||
| // {{prompt:end:<length>}} will be replaced with the last <length> characters of the prompt
 | ||||
| // Character length is used as we don't have the ability to tokenize the prompt
 | ||||
| export const templatePrompt = (template, prompt) => { | ||||
| export const templatePrompt = (template: string, prompt: string) => { | ||||
| 	template = template.replace(/{{prompt}}/g, prompt); | ||||
| 
 | ||||
| 	// Replace {{prompt:start:<length>}} with the first <length> characters of the prompt
 | ||||
| 	const startMatch = template.match(/{{prompt:start:(\d+)}}/); | ||||
| 	if (startMatch) { | ||||
| 	// Replace all instances of {{prompt:start:<length>}} with the first <length> characters of the prompt
 | ||||
| 	const startRegex = /{{prompt:start:(\d+)}}/g; | ||||
| 	let startMatch: RegExpMatchArray | null; | ||||
| 	while ((startMatch = startRegex.exec(template)) !== null) { | ||||
| 		const length = parseInt(startMatch[1]); | ||||
| 		template = template.replace(startMatch[0], prompt.substring(0, length)); | ||||
| 	} | ||||
| 
 | ||||
| 	// Replace {{prompt:end:<length>}} with the last <length> characters of the prompt
 | ||||
| 	const endMatch = template.match(/{{prompt:end:(\d+)}}/); | ||||
| 	if (endMatch) { | ||||
| 	// Replace all instances of {{prompt:end:<length>}} with the last <length> characters of the prompt
 | ||||
| 	const endRegex = /{{prompt:end:(\d+)}}/g; | ||||
| 	let endMatch: RegExpMatchArray | null; | ||||
| 	while ((endMatch = endRegex.exec(template)) !== null) { | ||||
| 		const length = parseInt(endMatch[1]); | ||||
| 		template = template.replace(endMatch[0], prompt.substring(prompt.length - length)); | ||||
| 	} | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jun Siang Cheah
						Jun Siang Cheah