반응형
블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 IT 프로젝트에서 사용되는 툴들에 대해 많은 분들과 정보를 공유하고 싶습니다.
솔웅

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리


반응형

오늘 공부할 Code Editing examples 원본 페이지는 아래에 있습니다.

 

https://github.com/openai/openai-cookbook/blob/main/code_editing_examples.md

 

GitHub - openai/openai-cookbook: Examples and guides for using the OpenAI API

Examples and guides for using the OpenAI API. Contribute to openai/openai-cookbook development by creating an account on GitHub.

github.com

 

Code editing example

OpenAI의 edits endpoint는 특별히 코드를 수정하는데 유용합니다.

Completions와 달리 Edits는 두개의 입력값을 받습니다. 수정할 코드와 instruction 입니다.

예를 들어 한 파이썬 함수를 수정하기를 원한다고 합시다. 당신은 그 함수와 'docstring을 추가하라' 같은 지시문을 함께 제공해야 할 것입니다.

 

Example text input to code-davinci-edit-001:

 

def tribonacci(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    elif n == 2:
        return 1
    elif n == 3:
        return 2
    else:
        return tribonacci(n-1) + tribonacci(n-2) + tribonacci(n-3)

Example instruction inputs:

add a docstring
Add typing, using Python 3.9 conventions
improved the runtime
Add a test.
Translate to JavaScript (or Rust or Lisp or any language you like)

자바스크립트로 runtime과 translating을 개선시키고 난 후의 output 예제.

function tribonacci(n) {
  let a = 0;
  let b = 1;
  let c = 1;
  for (let i = 0; i < n; i++) {
    [a, b, c] = [b, c, a + b + c];
  }
  return a;
}

위에서 보는 바와 같이 code-davinci-edit-001은 exponential down을 통해 함수의 실행 시간을 성공적으로 줄였습니다. 그리고 파이썬을 자바스크립트로 변환까지 했습니다.

 

OpenAI Playground에서 code-davinci-edit-001을 사용하여 코드 편집을 실험해 보세요.

OpenAI Playground

 

OpenAI API

An API for accessing new AI models developed by OpenAI

platform.openai.com

 

반응형