mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
21 lines
678 B
TypeScript
21 lines
678 B
TypeScript
|
import * as InvokeAI from 'app/invokeai';
|
||
|
import promptToString from './promptToString';
|
||
|
|
||
|
export function getPromptAndNegative(input_prompt: InvokeAI.Prompt) {
|
||
|
let prompt: string = promptToString(input_prompt);
|
||
|
let negativePrompt: string | null = null;
|
||
|
|
||
|
const negativePromptRegExp = new RegExp(/(?<=\[)[^\][]*(?=])/, 'gi');
|
||
|
const negativePromptMatches = [...prompt.matchAll(negativePromptRegExp)];
|
||
|
|
||
|
if (negativePromptMatches && negativePromptMatches.length > 0) {
|
||
|
negativePrompt = negativePromptMatches.join(', ');
|
||
|
prompt = prompt
|
||
|
.replaceAll(negativePromptRegExp, '')
|
||
|
.replaceAll('[]', '')
|
||
|
.trim();
|
||
|
}
|
||
|
|
||
|
return [prompt, negativePrompt];
|
||
|
}
|