pgibler / cmdh

Create Linux commands from natural language, in the shell.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Failed to parse response` when requested for JSON-related command

swoh816 opened this issue · comments

When I ask cmdh to return some command that has to do with JSON files, it returns an error Failed to parse response: SyntaxError: Unexpected token + in JSON at position 197. In the following example, I request cmdh to show the command to pretty-print JSON file, and it shows the error:

$ cmdh "Pretty print json file `file.json`"
✔ Retrieving command... Pretty print json file `file.json`
Failed to parse response: SyntaxError: Unexpected token + in JSON at position 197
    at JSON.parse (<anonymous>)
    at parseResponse (file:PATH_TO_CMDH/dist/parseResponse.js:4:27)
    at handlePrompt (file:PATH_TO_CMDH/dist/run.js:68:98)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async run (file:PATH_TO_CMDH/dist/run.js:18:13)
    at async main (file:PATH_TO_CMDH/dist/index.js:7:5)
PATH_TO_CMDH/dist/run.js:68
        const { setupCommands, desiredCommand, nonInteractive, safetyLevel, assistantMessage } = parseResponse(response);
                ^

TypeError: Cannot destructure property 'setupCommands' of 'parseResponse(...)' as it is null.
    at handlePrompt (file:PATH_TO_CMDH/dist/run.js:68:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async run (file:PATH_TO_CMDH/dist/run.js:18:13)
    at async main (file:PATH_TO_CMDH/dist/index.js:7:5)

Node.js v18.19.1

I think the error occurs because the output of cmdh contains some JSON text.

(From Stripe,)
Usually this error is caused when your server returns HTML (which typically begins with or ) instead of JSON.

In real, the error does not occur if I ask cmdh to pretty-print other files, such as HTML, python script, etc.

I configured cmdh with llama2 using Ollama. I think you can reproduce the above error if you send the same request as me to the same model via cmdh.

Thank you very much for the awesome project, this is by far my favourite AI copilot for CLI.