mattzcarey / code-review-gpt

Code review powered by LLMs (OpenAI GPT4, Sonnet 3.5) & Embeddings ⚑️ Improve code quality and catch bugs before you break production πŸš€ Lives in your Github/GitLab/Azure DevOps CI
https://oriontools.ai
MIT License
1.55k stars 153 forks source link

Error parsing JSON response from the model: ```json #331

Closed francisbilham11 closed 2 months ago

francisbilham11 commented 4 months ago

Current Behavior:

Running on GitHub Actions passes and comments πŸ‘πŸΌπŸ”πŸš« on the PR even when it's riddled with errors. When looking at the logs, I can see these errors were indeed picked up but they were not output properly as json. the error message is as below:

ERROR   Error parsing JSON response from the model: ```json

Expected Behavior:

Expected that the GitHub Actions workflow produces a meaningful comment on the PR listing the errors

Steps To Reproduce:

Here is the workflow:

name: Code Review GPT

on:
  pull_request:
    branches: [main]

jobs:
  run_code_review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Code Review GPT
        uses: mattzcarey/code-review-gpt@v0.1.4-alpha
        with:
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
          MODEL: 'gpt-3.5-turbo'
          GITHUB_TOKEN: ${{ github.token }}

Environment:

Anything else:

Here's a snippet of the logs:

ERROR   Error parsing JSON response from the model: ```json
[
    {
        "fileName": "/home/runner/work/francis-pd/francis-pd/db_connect.py",
        "riskScore": 5,
        "details": "API keys and credentials are hard-coded in the code. This is a severe security risk. These should not be exposed in plain text. Consider using environment variables or a secure storage solution."
    },
    {
        "fileName": "/home/runner/work/francis-pd/francis-pd/db_connect.py",
        "riskScore": 4,
        "details": "There is a SQL injection vulnerability in the 'update_item' function. User input should not be directly interpolated into SQL queries. Use parameterized queries to prevent SQL injection attacks."
    },
    {
        "fileName": "/home/runner/work/francis-pd/francis-pd/db_connect.py",
        "riskScore": 3,
        "details": "The 'list_duplicator' function seems to be inefficient for duplicating items. Consider using list comprehension or other more efficient methods for duplicating items."
    }
]

SyntaxError Unexpected token ` in JSON at position 0 error stack: β€’

β€’ index.js Ge /node_modules/code-review-gpt/dist/index.js:16 β€’ index.js maxTry /node_modules/code-review-gpt/dist/index.js:16 β€’ task_queues process.processTicksAndRejections internal/process/task_queues:95 ERROR Error in callModelJSON

mattzcarey commented 2 months ago

fixed with update to 0.1.7