-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a4639a
commit b305541
Showing
2 changed files
with
80 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export function replaceVariables(prompt: any, variables: Object[]) { | ||
let newPrompt = prompt; | ||
for (const key in variables) { | ||
if (variables.hasOwnProperty(key)) { | ||
const value = variables[key]; | ||
newPrompt = newPrompt.replace(`{{${key}}}`, value); | ||
} | ||
} | ||
return newPrompt; | ||
} | ||
|
||
export function validatePrompt(prompt: string) { | ||
const regex = /{{([^}]+)}}/g; | ||
const match = prompt.match(regex); | ||
return !match; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters