Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to parse response when requested for JSON-related command #14

Open
swoh816 opened this issue Mar 10, 2024 · 0 comments
Open

Failed to parse response when requested for JSON-related command #14

swoh816 opened this issue Mar 10, 2024 · 0 comments

Comments

@swoh816
Copy link

swoh816 commented Mar 10, 2024

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.

@swoh816 swoh816 changed the title cmdh returns error Failed to parse response when requested for json related command Failed to parse response when requested for json related command Mar 10, 2024
@swoh816 swoh816 changed the title Failed to parse response when requested for json related command Failed to parse response when requested for JSON-related command Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant