aidar-freeed/ai-codereviewer

404 Not Found on OpenAI API endpoint/Github diff endpoint

Closed this issue · 7 comments

Subject:

OpenAI API endpoint causing workflow break

Issue Description:

When using the ai-codereviewer action, which calls the OpenAI API endpoint https://api.openai.com/v1/chat/completions, a "404 Not Found" error is encountered. This error causes the workflow to break during the "AI Code Review" step.

Error Details:

Run freeedcom/ai-codereviewer@v2.4.1
Error: Error: Request failed with status code 404
    at createError (/home/runner/work/_actions/freeedcom/ai-codereviewer/v2.4.1/webpack:/open-ai-reviewer/node_modules/axios/lib/core/createError.js:16:1)
    at settle (/home/runner/work/_actions/freeedcom/ai-codereviewer/v2.4.1/webpack:/open-ai-reviewer/node_modules/axios/lib/core/settle.js:17:1)
    at IncomingMessage.handleStreamEnd (/home/runner/work/_actions/freeedcom/ai-codereviewer/v2.4.1/webpack:/open-ai-reviewer/node_modules/axios/lib/adapters/http.js:322:1)
    at IncomingMessage.emit (node:events:539:35)
    at endReadableNT (node:internal/streams/readable:1345:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  config: {
    transitional: {
      silentJSONParsing: true,
      forcedJSONParsing: true,
      clarifyTimeoutError: false
    },
    adapter: [Function: httpAdapter],
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    validateStatus: [Function: validateStatus],
    headers: {
      Accept: 'application/json, text/plain, */*',
      'Content-Type': 'application/json',
      'User-Agent': 'OpenAI/NodeJS/3.2.1',
      Authorization: '***',
      'Content-Length': 1669
    },
    method: 'post',
    data: '{"model":"gpt-4","temperature":0.2,"max_tokens":700,"top_p":1,"frequency_penalty":0,"presence_penalty":0,"messages":[{"role":"system","content":"Your task is to review pull requests. Instructions:\\n- Provide the response in following JSON format:  [{\\"lineNumber\\":  <line_number>, \\"reviewComment\\": \\"<review comment>\\"}]\\n- Do not give positive comments or compliments.\\n- Provide comments and suggestions ONLY if there is something to improve, otherwise return an empty array.\\n- Write the comment in GitHub Markdown format.\\n- Use the given description only for the overall context and only comment the code.\\n- IMPORTANT: NEVER suggest adding comments to the code.\\n\\nReview the following code diff in the file \\"vue/src/util/formatting.ts\\" and take the pull request title and description into account when writing the response.\\n  \\nPull request title: chore: test new workflow with a dummy PR\\nPull request description:\\n\\n---\\n\\n---\\n\\nGit diff to review:\\n\\n```diff\\n@@ -14,6 +14,13 @@ export const formatNumberWithDecimals = new Intl.NumberFormat(\'en\', {\\n14    maximumFractionDigits: 2,\\n15  }).format;\\n16  \\n17 +/**\\n18 + * Removes all non-alphanumeric characters from the input string.\\n19 + *\\n20 + * @param {string} inputString - The string to remove non-alphanumeric characters from.\\n21 + * @param {string} replacement - The replacement string for removed characters. Defaults to an empty string.\\n22 + * @returns {string} - The input string with non-alphanumeric characters removed.\\n23 + */\\n24  export const stripNonAlphaNumerics = (inputString: string, replacement: string = \'\'): string => {\\n25    let regex = /[^a-zA-Z0-9_]/g;\\n26  \\n```\\n"}]}',
    url: 'https://api.openai.com/v1/chat/completions'
  },
  request: <ref *1> ClientRequest {
    _events: [Object: null prototype] {
      abort: [Function (anonymous)],
      aborted: [Function (anonymous)],
      connect: [Function (anonymous)],
      error: [Function (anonymous)],
      socket: [Function (anonymous)],
      timeout: [Function (anonymous)],
      prefinish: [Function: requestOnPrefinish]
    },
    _eventsCount: 7,
    _maxListeners: undefined,
    outputData: [],
    outputSize: 0,
    writable: true,
    destroyed: false,
    _last: true,
    chunkedEncoding: false,
    shouldKeepAlive: false,
    maxRequestsOnConnectionReached: false,
    _defaultKeepAlive: true,
    useChunkedEncodingByDefault: true,
    sendDate: false,
    _removedConnection: false,
    _removedContLen: false,
    _removedTE: false,
    _contentLength: null,
    _hasBody: true,
    _trailer: '',
    finished: true,
    _headerSent: true,
    _closed: false,
    socket: TLSSocket {
      _tlsOptions: [Object],
      _secureEstablished: true,
      _securePending: false,
      _newSessionPending: false,
      _controlReleased: true,
      secureConnecting: false,
      _SNICallback: null,
      servername: 'api.openai.com',
      alpnProtocol: false,
      authorized: true,
      authorizationError: null,
      encrypted: true,
      _events: [Object: null prototype],
      _eventsCount: 10,
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: 'api.openai.com',
      _readableState: [ReadableState],
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: undefined,
      _server: null,
      ssl: [TLSWrap],
      _requestCert: true,
      _rejectUnauthorized: true,
      parser: null,
      _httpMessage: [Circular *1],
      [Symbol(res)]: [TLSWrap],
      [Symbol(verified)]: true,
      [Symbol(pendingSession)]: null,
      [Symbol(async_id_symbol)]: 71,
      [Symbol(kHandle)]: [TLSWrap],
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kCapture)]: false,
      [Symbol(kSetNoDelay)]: false,
      [Symbol(kSetKeepAlive)]: true,
      [Symbol(kSetKeepAliveInitialDelay)]: 60,
      [Symbol(kBytesRead)]: 0,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(connect-options)]: [Object],
      [Symbol(RequestTimeout)]: undefined
    },
    _header: 'POST /v1/chat/completions HTTP/1.1\r\n' +
      'Accept: application/json, text/plain, */*\r\n' +
      'Content-Type: application/json\r\n' +
      'User-Agent: OpenAI/NodeJS/3.2.1\r\n' +
      'Authorization: ***' +
      'Content-Length: 1669\r\n' +
      'Host: api.openai.com\r\n' +
      'Connection: close\r\n' +
      '\r\n',
    _keepAliveTimeout: 0,
    _onPendingData: [Function: nop],
    agent: Agent {
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      defaultPort: 443,
      protocol: 'https:',
      options: [Object: null prototype],
      requests: [Object: null prototype] {},
      sockets: [Object: null prototype],
      freeSockets: [Object: null prototype] {},
      keepAliveMsecs: 1000,
      keepAlive: false,
      maxSockets: Infinity,
      maxFreeSockets: 256,
      scheduling: 'lifo',
      maxTotalSockets: Infinity,
      totalSocketCount: 1,
      maxCachedSessions: 100,
      _sessionCache: [Object],
      [Symbol(kCapture)]: false
    },
    socketPath: undefined,
    method: 'POST',
    maxHeaderSize: undefined,
    insecureHTTPParser: undefined,
    path: '/v1/chat/completions',
    _ended: true,
    res: IncomingMessage {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 4,
      _maxListeners: undefined,
      socket: [TLSSocket],
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      rawHeaders: [Array],
      rawTrailers: [],
      aborted: false,
      upgrade: false,
      url: '',
      method: null,
      statusCode: 404,
      statusMessage: 'Not Found',
      client: [TLSSocket],
      _consuming: false,
      _dumped: false,
      req: [Circular *1],
      responseUrl: 'https://api.openai.com/v1/chat/completions',
      redirects: [],
      [Symbol(kCapture)]: false,
      [Symbol(kHeaders)]: [Object],
      [Symbol(kHeadersCount)]: 22,
      [Symbol(kTrailers)]: null,
      [Symbol(kTrailersCount)]: 0,
      [Symbol(RequestTimeout)]: undefined
    },
    aborted: false,
    timeoutCb: null,
    upgradeOrConnect: false,
    parser: null,
    maxHeadersCount: null,
    reusedSocket: false,
    host: 'api.openai.com',
    protocol: 'https:',
    _redirectable: Writable {
      _writableState: [WritableState],
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      _options: [Object],
      _ended: true,
      _ending: true,
      _redirectCount: 0,
      _redirects: [],
      _requestBodyLength: 1669,
      _requestBodyBuffers: [],
      _onNativeResponse: [Function (anonymous)],
      _currentRequest: [Circular *1],
      _currentUrl: 'https://api.openai.com/v1/chat/completions',
      [Symbol(kCapture)]: false
    },
    [Symbol(kCapture)]: false,
    [Symbol(kNeedDrain)]: false,
    [Symbol(corked)]: 0,
    [Symbol(kOutHeaders)]: [Object: null prototype] {
      accept: [Array],
      'content-type': [Array],
      'user-agent': [Array],
      authorization: [Array],
      'content-length': [Array],
      host: [Array]
    }
  },
  response: {
    status: 404,
    statusText: 'Not Found',
    headers: {
      date: 'Thu, 06 Jul 2023 21:20:05 GMT',
      'content-type': 'application/json; charset=utf-8',
      'content-length': '179',
      connection: 'close',
      vary: 'Origin',
      'x-request-id': '1b5d343d36cb9611a9c3c11a84a77241',
      'strict-transport-security': 'max-age=15724800; includeSubDomains',
      'cf-cache-status': 'DYNAMIC',
      server: 'cloudflare',
      'cf-ray': '7e2ae3c08d6c0a8d-IAD',
      'alt-svc': 'h3=":443"; ma=86400'
    },
    config: {
      transitional: [Object],
      adapter: [Function: httpAdapter],
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      validateStatus: [Function: validateStatus],
      headers: [Object],
      method: 'post',
      data: '{"model":"gpt-4","temperature":0.2,"max_tokens":700,"top_p":1,"frequency_penalty":0,"presence_penalty":0,"messages":[{"role":"system","content":"Your task is to review pull requests. Instructions:\\n- Provide the response in following JSON format:  [{\\"lineNumber\\":  <line_number>, \\"reviewComment\\": \\"<review comment>\\"}]\\n- Do not give positive comments or compliments.\\n- Provide comments and suggestions ONLY if there is something to improve, otherwise return an empty array.\\n- Write the comment in GitHub Markdown format.\\n- Use the given description only for the overall context and only comment the code.\\n- IMPORTANT: NEVER suggest adding comments to the code.\\n\\nReview the following code diff in the file \\"vue/src/util/formatting.ts\\" and take the pull request title and description into account when writing the response.\\n  \\nPull request title: chore: test new workflow with a dummy PR\\nPull request description:\\n\\n---\\n\\n---\\n\\nGit diff to review:\\n\\n```diff\\n@@ -14,6 +14,13 @@ export const formatNumberWithDecimals = new Intl.NumberFormat(\'en\', {\\n14    maximumFractionDigits: 2,\\n15  }).format;\\n16  \\n17 +/**\\n18 + * Removes all non-alphanumeric characters from the input string.\\n19 + *\\n20 + * @param {string} inputString - The string to remove non-alphanumeric characters from.\\n21 + * @param {string} replacement - The replacement string for removed characters. Defaults to an empty string.\\n22 + * @returns {string} - The input string with non-alphanumeric characters removed.\\n23 + */\\n24  export const stripNonAlphaNumerics = (inputString: string, replacement: string = \'\'): string => {\\n25    let regex = /[^a-zA-Z0-9_]/g;\\n26  \\n```\\n"}]}',
      url: 'https://api.openai.com/v1/chat/completions'
    },
    request: <ref *1> ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      maxRequestsOnConnectionReached: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: true,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: null,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      _closed: false,
      socket: [TLSSocket],
      _header: 'POST /v1/chat/completions HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'Content-Type: application/json\r\n' +
        'User-Agent: OpenAI/NodeJS/3.2.1\r\n' +
        'Authorization: ***' +
        'Content-Length: 1669\r\n' +
        'Host: api.openai.com\r\n' +
        'Connection: close\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: nop],
      agent: [Agent],
      socketPath: undefined,
      method: 'POST',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      path: '/v1/chat/completions',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'api.openai.com',
      protocol: 'https:',
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    data: { error: [Object] }
  },
  isAxiosError: true,
  toJSON: [Function: toJSON]
}

Steps to Reproduce:

  1. Initiate the workflow process.
  2. Observe the error during the "AI Code Reviewer" step.

Expected Behavior:

The workflow should successfully call the OpenAI API endpoint and complete the "AI Code Review" step without any errors.

Actual Behavior:

The workflow breaks during the "AI Code Review" step due to an error when calling the OpenAI API endpoint.

Additional Information:

  • Workflow version: freeedcom/ai-codereviewer@v2.4.1
  • OpenAI API endpoint: https://api.openai.com/v1/chat/completions

Any help with this issue would be greatly appreciated.

For reference, here's my .yml file:

name: AI Code Reviewer

on:
  pull_request:
    types:
      - opened
      - synchronize
permissions: write-all
jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v3

      - name: AI Code Reviewer
        uses: freeedcom/ai-codereviewer@v2.4.1
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
          exclude: "**/*.json, **/*.md" # Optional: exclude patterns separated by commas

@lfsevergnini model gpt-4 is not really available still. Waitlist can be checked here:

@villesau May I suggest the fix by changing the model only, for the ones still not blessed by OpenAI with access to the model 4?
main.ts:137
model: "gpt-3.5-turbo", //gpt-4 is not available in my account

Feel free to submit a PR that passes the model name as a parameter :)

@teobaiocco just FYI, that seems to no longer be the problem. After I created this issue, OpenAI released gpt-4 to everybody.

image

A wrong model type will definitely throw a 404, but hitting the API using Postman results in a 200 OK. 🤔

Ok, I think I found what the problem is but still don't know how to solve it 🤔

image

My repository is private and it seems that Octokit isn't using the GitHub token to fetch the diff_url from the PR.

@villesau I opened a PR that adds support to private repositories. Feel free to add feedback.

I've already merged this in my fork project so that I don't get blocked, so no need to rush.

Thanks all.

Thanks for the contribution! I merged the changes.