Skip to content

Commit

Permalink
fix: πŸ› don't parse any inputs for raw mode
Browse files Browse the repository at this point in the history
BREAKING CHANGE: 🧨 raw mode flag will no longer automatically trigger interactive mode

βœ… Closes: #21
  • Loading branch information
Rafiq committed Dec 4, 2023
1 parent a7dd7f7 commit 01fb77a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Run the CLI using this format: `npx prompt-shaper [options] <input>`
- Enable interactive mode by specifying `-i or --interactive` (continue conversation in command line)
- Example (send template to interactive mode): `npx prompt-shaper my_template.ps.md -i`
- Example (start empty new chat in interactive mode): `npx prompt-shaper -i`
- Use raw mode to not run the parser on any inputs
- Example: `npx prompt-shaper -r raw.ps.md`
- Load a previous conversation from JSON and continue in interactive mode with `-lj or --load-json`
- Example: `npx prompt-shaper my_template.ps.md -lj <jsonPath>`
- Load a previous conversation from text and continue in interactive mode with `-lt or --load-text`
Expand Down
5 changes: 3 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ async function handler(input: string, options: CLIOptions) {
try {
const parserOptions = { returnParserMatches: false, showDebugMessages: options.debug as boolean }

const parsed = parseTemplate(template, variables, parserOptions)
// parse template if not in raw mode
const parsed = options.raw ? template : parseTemplate(template, variables, parserOptions)
console.log(`user\n${[parsed]}\n-----`)

// check if user wants to send results to LLM
if (options.generate || options.interactive || options.raw || options.model !== 'gpt-4' || options.prompt !== 'You are a helpful assistant.') {
if (options.generate || options.interactive || options.model !== 'gpt-4' || options.prompt !== 'You are a helpful assistant.') {
const conversation: ChatMessage[] = [
{
role: 'system',
Expand Down
10 changes: 10 additions & 0 deletions test/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,14 @@ describe('CLI', () => {
done()
})
})

it('should not parse input template when in raw mode', done => {
exec('ts-node src/cli.ts -r test/templates/cli/raw.ps.md', (error, stdout) => {
if (error) {
throw new Error(error.message)
}
expect(stdout.trim()).to.contain('none of this {{ }}} should be parsed! // !{}}}{{')
done()
})
})
})
1 change: 1 addition & 0 deletions test/templates/cli/raw.ps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
none of this {{ }}} should be parsed! // !{}}}{{

0 comments on commit 01fb77a

Please sign in to comment.