Skip to content

๐Ÿ’ก How To? Chat GPT ๋ฆฌ๋ทฐ์–ด ๋„์ž…ํ•˜๊ธฐ

KyungMin Lee edited this page Aug 29, 2024 · 3 revisions

์„ ํƒํ•˜๊ธฐ

GitHub MarketPlace๋ฅผ ํƒ์ƒ‰ํ•˜๋ฉด ๋งŽ์€ AI ์ฝ”๋“œ ๋ฆฌ๋ทฐ์–ด๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค.

1. ChatGPT CodeReviewer

ChatGPT CodeReviewer - GitHub Marketplace

์„ค์ •์ด ๊ฐ„ํŽธํ•˜๊ณ , ํ•œ๊ตญ์–ด๋„ ์ง€์›ํ•ด์ค€๋‹ค.

์•„๋ž˜ ์ฝ”๋“œ์™€ ๊ฐ™์ด

  • top_p
  • temperature
  • maxtoken

์€ default ๊ฐ’์ด ์žˆ์–ด ์ œ์™ธํ•œ๋‹ค

https://github.com/anc95/ChatGPT-CodeReview/blob/main/src/chat.ts

import { ChatGPTAPI } from 'chatgpt';
export class Chat {
  private chatAPI: ChatGPTAPI;

  constructor(apikey: string) {
    this.chatAPI = new ChatGPTAPI({
      apiKey: apikey,
      apiBaseUrl:
        process.env.OPENAI_API_ENDPOINT || 'https://api.openai.com/v1',
      completionParams: {
        model: process.env.MODEL || 'gpt-3.5-turbo',
        temperature: +(process.env.temperature || 0) || 1,
        top_p: +(process.env.top_p || 0) || 1,
        max_tokens: process.env.max_tokens
          ? +process.env.max_tokens
          : undefined,
      },
    });
  }

  private generatePrompt = (patch: string) => {
    const answerLanguage = process.env.LANGUAGE
      ? `Answer me in ${process.env.LANGUAGE},`
      : '';

    const prompt =
      process.env.PROMPT ||
        'Below is a code patch, please help me do a brief code review on it. Any bug risks and/or improvement suggestions are welcome:';

    return `${prompt}, ${answerLanguage}:
    ${patch}
    `;
  };

  public codeReview = async (patch: string) => {
    if (!patch) {
      return '';
    }

    console.time('code-review cost');
    const prompt = this.generatePrompt(patch);

    const res = await this.chatAPI.sendMessage(prompt);

    console.timeEnd('code-review cost');
    return res.text;
  };
}

์šฐ๋ฆฌ๊ฐ€ ์‚ฌ์šฉํ•  4o mini์˜ ๊ธฐ๋ณธ ์ตœ๋Œ€ ์ถœ๋ ฅ ํ† ํฐ์ด 16,384 ๋ฐ–์— ๋˜์ง€ ์•Š์•„ undefined ์ƒํƒœ๋กœ ๋‘˜ ์˜ˆ์ •

image

๊ฐ„ํ˜น ๋„ˆ๋ฌด ๋งŽ์€ ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ์žกํ˜€ ๋ฆฌ๋ทฐ๋กœ ๋„˜์–ด๊ฐˆ ๊ฒƒ์„ ๋Œ€๋น„.

AI์˜ Context - Window๊ฐ€ 128,000 tokens ๋กœ ๋„‰๋„‰ํ•˜๊ธด ํ•˜์ง€๋งŒ

MAX_PATCH_LENGTH ๊ฐ’๋งŒ 10,000์œผ๋กœ ์ œํ•œํ•ด์„œ ์‚ฌ์šฉ

ํ”„๋กฌํ”„ํŠธ ๊ฐœ์„ ๊ณผ ์ง„ํ–‰์ƒํ™ฉ์„ ์ •ํ™•ํžˆ ํŒ๋‹จํ•˜๊ธฐ ์œ„ํ•ด debug mode ํ™œ์„ฑํ™”

์ฝ”๋“œ ๋ณ€๊ฒฝ์„ ์˜ํ•ด fork ํ•˜๊ณ  forkํ•œ ๋ ˆํฌ๋กœ ๋ณ€๊ฒฝ

name: Code Review

permissions:
  contents: read
  pull-requests: write

on:
  pull_request:
    types: [opened, reopened, synchronize]
    branches:
      - dev

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: LuizyHub/ChatGPT-CodeReview@main
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
          LANGUAGE: Korean
          OPENAI_API_ENDPOINT: https://api.openai.com/v1
          DEBUG: true
          MODEL: gpt-4o-mini
          MAX_PATCH_LENGTH: 10000

๋„์ž…

https://github.com/woowa-techcamp-2024/Team5-Guys/pull/11

ํ›„๊ธฐ

https://github.com/woowa-techcamp-2024/Team5-Guys/pull/35

  • AI๊ฐ€ ์ „์ฒด context๋ฅผ ๊ฐ€์ง€๊ณ  ๋ฆฌ๋ทฐ๋ฅผ ์ง„ํ–‰ํ•˜์ง€ ์•Š๋Š”๋‹ค
  • ๋ณ€ํ™”๊ฐ„ ๋‹จ์ผ ํŒŒ์ผ๋งŒ ๋ณด๊ณ  ๋ฆฌ๋ทฐํ•˜๊ธฐ ํ•˜๊ธฐ๋•Œ๋ฌธ์— ์ „์ฒด PR์˜ ์ •๋ณด๋ฅผ ๋ชจ๋ฅด๊ณ  ๋ง์„ ๋งŽ์ดํ•œ๋‹ค
  • Too Much Talkโ€ฆ

2. Code Review GPT

[Code Review GPT - GitHub Marketplace](https://github.com/marketplace/actions/code-review-gpt

๊ธฐ๋ณธ์ ์œผ๋กœ Conventional Commit์„ ๋”ฐ๋ฅด๊ณ  Star์ˆ˜๋ฅผ ๋ณด์•„ ์ธ๊ธฐ์™€ ์‚ฌ์šฉ์ž๊ฐ€ ๊ฝค ์žˆ๋Š”๊ฒƒ์œผ๋กœ ๋ณด์ธ๋‹ค

๋‹ค๋งŒ, ์„ค์ •์— ์šฉ์ดํ•˜์ง€ ๋ชปํ•˜๊ณ  ํ•œ๊ตญ์–ด ๋ฆฌ๋ทฐ๋Š” ์–ด๋ ค์›Œ ๋ณด์ธ๋‹ค

์„ค์ •ํ• ๊ฒƒ

  • MODEL
  • OPENAI_API_KEY
  • GITHUB_TOKEN

Prompt

https://github.com/mattzcarey/code-review-gpt/blob/main/packages/code-review-gpt/src/review/prompt/prompts.ts

You are an expert {Language} 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:

ํ”„๋กฌํ”„ํŠธ์™€ ๋™์ž‘์„ ์‚ดํ”ผ๋ฉด, ๋ณ€ํ™”์— ๋Œ€ํ•ด ์ง์ ‘ ์œ„ํ—˜๋„์™€ ๋ถ„์„์„ ๋ฐ›๊ณ , ์œ„ํ—˜๋„๋ฅผ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•ด์„œ ํ•˜๋‚˜์˜ ๋ฆฌ๋ทฐ๋ฅผ ๋‚จ๊ฒจ์ค€๋‹ค.

์ง์ ‘ ํ•œ๊ตญ์–ด ์ง€์›์€ ์•ˆ๋˜์ง€๋งŒ, ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋ณ€๊ฒฝํ•ด์„œ ํ•œ๊ตญ์–ด ๋‹ต๋ณ€์„ ๋งŒ๋“ค ์ˆ˜ ์žˆ์„ ๊ฒƒ์œผ๋กœ ๋ณด์ธ๋‹ค.

๋„์ž…

ํ›„๊ธฐ

ํŒŒ์ผ์— ๋Œ€ํ•ด ์ข…ํ•ฉ์ ์ธ ๋ฆฌ๋ทฐ๋ฅผ ํ•œ ์ ์€ ์ „์— ๋น„ํ•ด ํ›จ์‹  ๊ธ์ •์ 

ํ•˜์ง€๋งŒ, ์—ฌ์ „ํžˆ ๋ณ€๊ฒฝ๋œ ํŒŒ์ผ์— ๋Œ€ํ•œ context๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๊ธฐ๋•Œ๋ฌธ์— ๋ฆฌ๋ทฐ๋Š” ํ•œ์ •์ ์ด๋‹ค.

์ฝ”๋“œ ๋ณ€๊ฒฝ ์ด๋ ฅ์— ๋Œ€ํ•œ context๊ฐ€ ์žˆ์œผ๋ฉด ์ข‹๊ฒ ์ง€๋งŒ, ํ˜„์‹ค์ ์œผ๋กœ ๋งŽ์ด ์–ด๋ ค์šธ ๊ฒƒ ๊ฐ™๋‹ค.

๐Ÿงซ ํŒ€ ๋ฌธํ™”

โš™๏ธ ๊ตฌ์„ฑ

๐Ÿ”จ ๊ฐœ๋ฐœ ์œ„ํ‚ค

๐Ÿž Bug Report

๐Ÿงช Test Logs

Clone this wiki locally