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.58k stars 156 forks source link

Error 404 - when running PR ci/cd #99

Closed RoTorEx closed 1 year ago

RoTorEx commented 1 year ago

Hello guys! Thanks you for your project. I've got error every time when my PR runs this ci/cd pipeline.

Launch logs:

Run npx code-review-gpt review --ci=github
ERROR   Error in callModelJSON

 Error  Request failed with status code 404
error stack:
  • createError.js  createError
    /node_modules/axios/lib/core/createError.js:16
  • settle.js   settle
    /node_modules/axios/lib/core/settle.js:17
  • http.js IncomingMessage.handleStreamEnd
    /node_modules/axios/lib/adapters/http.js:322
  • events  IncomingMessage.emit
    events:526
  • readable    endReadableNT
    internal/streams/readable:135[9](https://github.com/ApexBT/zozh.server/actions/runs/5784279965/job/15674674362?pr=100#step:5:10)
  • task_queues process.processTicksAndRejections
    internal/process/task_queues:82
ERROR   Error in callModelJSON

 Error  Request failed with status code 404
error stack:
  • createError.js  createError
    /node_modules/axios/lib/core/createError.js:16
  • settle.js   settle
    /node_modules/axios/lib/core/settle.js:17
  • http.js IncomingMessage.handleStreamEnd
    /node_modules/axios/lib/adapters/http.js:322
  • events  IncomingMessage.emit
    events:526
  • readable    endReadableNT
    internal/streams/readable:[13](https://github.com/ApexBT/zozh.server/actions/runs/5784279965/job/15674674362?pr=100#step:5:14)59
  • task_queues process.processTicksAndRejections
    internal/process/task_queues:82
ERROR   Error in processing prompt

 Error  Couldn't call model after 3 tries with prompt: You are an expert Python developer, your task is to review a set of pull requests.
You are given a list of filenames and their partial contents, but note that you might not have the full context of the code. 

Only review lines of code which have been changed (added or removed) in the pull request. The code looks similar to the output of a git diff command. Lines which have been removed are prefixed with a minus (-) and lines which have been added are prefixed with a plus (+). Other lines are added to provide context but should be ignored in the review.

Begin your review by evaluating the changed code using a risk score similar to a LOGAF score but measured from 1 to 5, where 1 is the lowest risk to the code base if the code is merged and 5 is the highest risk which would likely break something or be unsafe.

In your feedback, focus on highlighting potential bugs, improving readability if it is a problem, making code cleaner, and maximising the performance of the programming language. Flag any API keys or secrets present in the code in plain text immediately as highest risk. Rate the changes based on SOLID principles if applicable.

Do not comment on breaking functions down into smaller, more manageable functions unless it is a huge problem. Also be aware that there will be libraries and techniques used which you are not familiar with, so do not comment on those unless you are confident that there is a problem.

Use markdown formatting for the feedback details. Also do not include the filename or risk level in the feedback details. 

Ensure the feedback details are brief, concise, accurate. If there are multiple similar issues, only comment on the most critical.

Include brief example code snippets in the feedback details for your suggested changes when you're confident your suggestions are improvements. Use the same programming language as the file under review.
If there are multiple improvements you suggest in the feedback details, use an ordered list to indicate the priority of the changes.

Format the response in a valid JSON format as a list of feedbacks, where the value is an object containing the filename ("fileName"),  risk score ("riskScore") and the feedback ("details"). The schema of the JSON feedback object must be:
{
  "fileName": {
    "type": "string"
  },
  "riskScore": {
    "type": "number"
  },
  "details": {
    "type": "string"
  }
}

The filenames and file contents to review are provided below as a list of JSON objects:

[{"fileName":"/home/runner/work/zozh.server/zozh.server/src/config/settings_reader.py","promptContent":"import os\n\nfrom pydantic import BaseSettings, Field\n\n\nclass App(BaseSettings):\n    \"\"\"Common application environmental variables.\"\"\"\n\n    # App constants `version` hardcoded here and `name` in __init__.py of each app\n+    version: str = \"0.1.5\"\n    name: str = os.environ.get(\"app_name\", \"ZOZH API\")\n    # App setup\n    environment: str = Field(\"prod\", description=\"Environment\")\n    debug: bool = Field(False, description=\"Environment\")\n    log_level: str = Field(\"INFO\", description=\"Log level\")\n    host: str\n    port: int\n    workers: int\n    server_reload: bool\n    # Logger\n    logging_host: str\n    logging_port: int\n\n\nclass Mongo(BaseSettings):\n    \"\"\"Mongo environmental variables.\"\"\"\n\n    username: str\n    password: str\n    host: str\n    port: int\n    auth_source: str\n\n\nclass Google(BaseSettings):\n    \"\"\"Google environmental variables.\"\"\"\n\n    maps_api_key: str\n\n\nclass Stripe(BaseSettings):\n    \"\"\"Stripe environmental variables.\"\"\"\n\n    api_key_pub: str\n    api_key_sec: str\n    webhook_key: str | None\n\n\nclass Twilio(BaseSettings):\n    \"\"\"Twilio environmental variables.\"\"\"\n\n    account_key: str\n    auth_token: str\n    phone_number: str\n\n\nclass Relay(BaseSettings):\n    \"\"\"Relay environmental variables.\"\"\"\n\n    auth_token: str\n\n\nclass Sentry(BaseSettings):\n    \"\"\"Relay environmental variables.\"\"\"\n\n    is_dns: int = Field(0, description=\"Need to activate Sentry in dev and prod environmentals\")\n    dns: str | None = Field(None, description=\"Sentry DNS to send logs\")\n\n\nclass Settings(BaseSettings):\n    \"\"\"To atributes set name wich correspond to preffix name (NAME__) in .env file.\"\"\"\n\n    app: App\n    mongo: Mongo\n    google: Google\n    stripe: Stripe\n    twilio: Twilio\n    relay: Relay\n    sentry: Sentry\n\n    class Config:\n        \"\"\"Environmentals handler.\"\"\"\n\n        env_file_encoding = \"utf-8\"\n        env_nested_delimiter = \"__\"\n\n\ndef read_settings(env_file: str = \"./env/.env.dev\") -> Settings:\n    \"\"\"Create config with settings. Project `env` must be in `[\"test\", \"local\", \"dev\", \"prod\"]`.\"\"\"\n    env_scope = os.environ.get(\"env\", \"prod\")\n    env_file = f\"./env/.env.{env_scope}\"\n\n    config = Settings(_env_file=env_file)\n\n    return config"}]
error stack:
  • index.js    Object.onMaxRetryFunc
    /node_modules/code-review-gpt/dist/index.js:[15](https://github.com/ApexBT/zozh.server/actions/runs/5784279965/job/15674674362?pr=100#step:5:16)
  • retry.js    
    /node_modules/ts-retry/lib/cjs/retry/retry.js:55
  •     

  • retry.js    rejected
    /node_modules/ts-retry/lib/cjs/retry/retry.js:6
  • task_queues process.processTicksAndRejections
    internal/process/task_queues:95
ERROR   Error: Error: Request failed with status code 404
Error: Process completed with exit code 1.

My pipeline:

name: Code Review GPT

on:
  pull_request:
    branches:
    - main
    - develop

permissions:
  pull-requests: write
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - uses: actions/setup-node@v3
        with:
          node-version: 18

      - name: Install code-review-gpt
        run: npm install code-review-gpt

      - name: Run code review script
        run: npx code-review-gpt review --ci=github
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          BASE_SHA: ${{ github.event.pull_request.base.sha }}
          GITHUB_SHA: ${{ github.sha }}
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
RoTorEx commented 1 year ago

@danigo99, @SEBRATHEZEBRA, @coldfrey, @gowoons Is it bug or I did something wrong?

muffe commented 1 year ago

Try running it with --model=gpt-3.5-turbo.

You only get access to GPT-4 when you have a paid account already.

On July 6, 2023 , we gave access to the [GPT-4 API](https://platform.openai.com/docs/models/gpt-4) (8k) to all API users who have made a successful payment of $1 or more.

See https://help.openai.com/en/articles/7102672-how-can-i-access-gpt-4

mattzcarey commented 1 year ago

Thanks @muffe. Exactly :) Even better would be to use the 16k model if you have access.

RoTorEx commented 1 year ago

No, unfortunately I don't have access to any models other than the standard ones. After several requests it finally crashed with a 429 error

RoTorEx commented 1 year ago

Hey @muffe , the problem is still recurring, any other recommendations? :)

muffe commented 1 year ago
  1. What's the command you're running now?
  2. You're using a paid account / an account with credit card information? As far as I'm aware, the API is only accessible as paid user.
RoTorEx commented 1 year ago
  1. What's the command you're running now?
  2. You're using a paid account / an account with credit card information? As far as I'm aware, the API is only accessible as paid user.
  1. npx code-review-gpt review --ci=github --model=gpt-3.5-turbo
  2. That's the reason, I don't use a paid account. And I made the assumption that it would work with free accounts
RoTorEx commented 1 year ago

Decided to link the card and check it out. Everything works. Thank you very much