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

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리

'Open AI/GUIDES'에 해당되는 글 12

  1. 2023.01.09 Guide - Code completion
  2. 2023.01.09 Guide - Text completion

Guide - Code completion

2023. 1. 9. 08:01 | Posted by 솔웅


반응형

Code completion 

Limited beta

Learn how to generate or manipulate code

Introduction

The Codex model series is a descendant of our GPT-3 series that's been trained on both natural language and billions of lines of code. It's most capable in Python and proficient in over a dozen languages including JavaScript, Go, Perl, PHP, Ruby, Swift, TypeScript, SQL, and even Shell. During this initial limited beta period, Codex usage is free. Learn more.

 

Codex 모델 시리즈는 자연어와 수십억 줄의 코드에 대해 훈련된 GPT-3 시리즈의 후손입니다. Python에서 가장 유능하며 JavaScript, Go, Perl, PHP, Ruby, Swift, TypeScript, SQL 및 Shell을 포함한 12개 이상의 언어에 능숙합니다. 이 초기 제한 베타 기간 동안 Codex 사용은 무료입니다. 더 알아보기.

 

You can use Codex for a variety of tasks including:

  • Turn comments into code
  • Complete your next line or function in context
  • Bring knowledge to you, such as finding a useful library or API call for an application
  • Add comments
  • Rewrite code for efficiency

다음과 같은 다양한 작업에 Codex를 사용할 수 있습니다.
* 주석을 코드로 변환
* 컨텍스트에서 다음 라인 또는 기능을 완료하십시오.
* 유용한 라이브러리 찾기 또는 응용 프로그램에 대한 API 호출과 같은 지식 제공
* 주석 추가
* 효율성을 위해 코드 재작성

 

To see Codex in action, check out our Codex JavaScript Sandbox or our other demo videos.

 

Codex가 작동하는 모습을 보려면 Codex JavaScript Sandbox 또는 다른 데모 비디오를 확인하십시오.

 

 

Quickstart

To start using Codex yourself, try opening these examples in the Playground.  

 

Codex를 직접 사용하려면 플레이그라운드에서 이 예제를 열어보십시오.

 

Saying "Hello" (Python)

"""
Ask the user for their name and say "Hello"
"""
Open in Playground

Create random names (Python)

"""
1. Create a list of first names
2. Create a list of last names
3. Combine them randomly into a list of 100 full names
"""
Open in Playground

Create a MySQL query (Python)

"""
Table customers, columns = [CustomerId, FirstName, LastName, Company, Address, City, State, Country, PostalCode, Phone, Fax, Email, SupportRepId]
Create a MySQL query for all customers in Texas named Jane
"""
query =
Open in Playground

Explaining code (JavaScript)

// Function 1
var fullNames = [];
for (var i = 0; i < 50; i++) {
  fullNames.push(names[Math.floor(Math.random() * names.length)]
    + " " + lastNames[Math.floor(Math.random() * lastNames.length)]);
}

// What does Function 1 do?
Open in Playground

More examples

Visit our examples library to explore more prompts designed for Codex.

 

Codex용으로 설계된 더 많은 프롬프트를 탐색하려면 예제 라이브러리를 방문하십시오.

 

Best practices

Start with a comment, data or code. You can experiment using one of the Codex models in our playground (styling instructions as comments when needed.)

To get Codex to create a useful completion it's helpful to think about what information a programmer would need to perform a task. This could simply be a clear comment or the data needed to write a useful function, like the names of variables or what class a function handles.

 

주석, 데이터 또는 코드로 시작하십시오. 플레이그라운드에서 Codex 모델 중 하나를 사용하여 실험할 수 있습니다(필요한 경우 주석으로 스타일 지정 지침).
Codex가 유용한 코드 완성을 만들려면 프로그래머가 작업을 수행하는 데 어떤 정보가 필요한지 생각하는 것이 좋습니다. 이것은 단순히 명확한 주석이거나 변수 이름이나 함수가 처리하는 클래스와 같이 유용한 함수를 작성하는 데 필요한 데이터일 수 있습니다.

 

# Create a function called 'nameImporter' to add a first and last name to the database
Open in Playground

 

In this example we tell Codex what to call the function and what task it's going to perform.

This approach scales even to the point where you can provide Codex with a comment and an example of a database schema to get it to write useful query requests for various databases.

 

이 예에서 우리는 Codex에게 함수를 호출할 대상과 수행할 작업을 알려줍니다.
이 접근 방식은 다양한 데이터베이스에 대한 유용한 쿼리 요청을 작성할 수 있도록 Codex에 주석과 데이터베이스 스키마의 예를 제공할 수 있는 지점까지 확장됩니다.

 

# Table albums, columns = [AlbumId, Title, ArtistId]
# Table artists, columns = [ArtistId, Name]
# Table media_types, columns = [MediaTypeId, Name]
# Table playlists, columns = [PlaylistId, Name]
# Table playlist_track, columns = [PlaylistId, TrackId]
# Table tracks, columns = [TrackId, Name, AlbumId, MediaTypeId, GenreId, Composer, Milliseconds, Bytes, UnitPrice]

# Create a query for all albums by Adele
Open in Playground

 

When you show Codex the database schema it's able to make an informed guess about how to format a query.

Specify the language. Codex understands dozens of different programming languages. Many share similar conventions for comments, functions and other programming syntax. By specifying the language and what version in a comment, Codex is better able to provide a completion for what you want. That said, Codex is fairly flexible with style and syntax.

 

Codex에 데이터베이스 스키마를 표시하면 쿼리 형식을 지정하는 방법에 대해 정보에 입각한 추측을 할 수 있습니다.
언어를 지정합니다. Codex는 수십 가지의 다양한 프로그래밍 언어를 이해합니다. 많은 사람들이 주석, 함수 및 기타 프로그래밍 구문에 대해 유사한 규칙을 공유합니다. 주석에 언어와 버전을 지정함으로써 Codex는 원하는 것을 더 잘 완성할 수 있습니다. 즉, Codex는 스타일과 구문이 상당히 유연합니다.

 

# R language
# Calculate the mean distance between an array of points
Open in Playground
# Python 3
# Calculate the mean distance between an array of points
Open in Playground

 

Prompt Codex with what you want it to do. If you want Codex to create a webpage, placing the first line of code in an HTML document (<!DOCTYPE html>) after your comment tells Codex what it should do next. The same method works for creating a function from a comment (following the comment with a new line starting with func or def).

 

원하는 작업을 Codex에 표시하십시오. Codex가 웹페이지를 생성하도록 하려면 HTML 문서(<!DOCTYPE html>)에 코드의 첫 번째 줄을 입력한 후 Codex에 다음에 수행할 작업을 알려줍니다. 동일한 방법이 주석에서 함수를 생성하는 데 작동합니다(주석 뒤에 func 또는 def로 시작하는 새 줄이 있음).

 

<!-- Create a web page with the title 'Kat Katman attorney at paw' -->
<!DOCTYPE html>
Open in Playground

 

Placing <!DOCTYPE html> after our comment makes it very clear to Codex what we want it to do.

 

주석 뒤에 <!DOCTYPE html>을 넣으면 Codex가 원하는 작업을 매우 명확하게 알 수 있습니다.

 

# Create a function to count to 100

def counter
Open in Playground

 

If we start writing the function Codex will understand what it needs to do next.

Specifying libraries will help Codex understand what you want. Codex is aware of a large number of libraries, APIs and modules. By telling Codex which ones to use, either from a comment or importing them into your code, Codex will make suggestions based upon them instead of alternatives.

 

함수 작성을 시작하면 Codex는 다음에 해야 할 일을 이해할 것입니다.
라이브러리를 지정하면 Codex가 원하는 것을 이해하는 데 도움이 됩니다. Codex는 수많은 라이브러리, API 및 모듈을 알고 있습니다. 주석에서 또는 코드로 가져오기를 통해 Codex에 어떤 것을 사용해야 하는지 알려줌으로써 Codex는 대안 대신 이를 기반으로 제안을 합니다.

 

<!-- Use A-Frame version 1.2.0 to create a 3D website -->
Open in Playground

 

By specifying the version you can make sure Codex uses the most current library.

Note: Codex can suggest helpful libraries and APIs, but always be sure to do your own research to make sure that they're safe for your application.

Comment style can affect code quality. With some languages the style of comments can improve the quality of the output. For example, when working with Python, in some cases using doc strings (comments wrapped in triple quotes) can give higher quality results than using the pound (#) symbol.

 

버전을 지정하면 Codex가 최신 라이브러리를 사용하도록 할 수 있습니다.
참고: Codex는 유용한 라이브러리와 API를 제안할 수 있지만 항상 자신의 응용 프로그램에 대해 안전한지 확인하기 위해 자체 조사를 수행해야 합니다.
주석 스타일은 코드 품질에 영향을 미칠 수 있습니다. 일부 언어에서는 주석 스타일이 출력 품질을 향상시킬 수 있습니다. 예를 들어 Python으로 작업할 때 경우에 따라 doc 문자열(3중 따옴표로 묶인 주석)을 사용하면 파운드(#) 기호를 사용하는 것보다 더 나은 품질의 결과를 얻을 수 있습니다.

 

"""
Create an array of users and email addresses
"""
Open in Playground

 

Put comments inside of functions can be helpful. Recommended coding standards usually suggest placing the description of a function inside the function. Using this format helps Codex more clearly understand what you want the function to do.

 

함수 내부에 주석을 넣는 것이 도움이 될 수 있습니다. 권장되는 코딩 표준은 일반적으로 함수 내부에 함수 설명을 배치할 것을 제안합니다. 이 형식을 사용하면 Codex가 함수에서 원하는 작업을 보다 명확하게 이해할 수 있습니다.

 

def getUserBalance(id):
    """
    Look up the user in the database ‘UserData' and return their current account balance.
    """
Open in Playground

 

Provide examples for more precise results. If you have a particular style or format you need Codex to use, providing examples or demonstrating it in the first part of the request will help Codex more accurately match what you need.

 

보다 정확한 결과를 위해 예를 제공하십시오. Codex가 사용해야 하는 특정 스타일이나 형식이 있는 경우 요청의 첫 번째 부분에서 예제를 제공하거나 시연하면 Codex가 필요한 것을 보다 정확하게 일치시키는 데 도움이 됩니다.

 

"""
Create a list of random animals and species
"""
animals  = [ {"name": "Chomper", "species": "Hamster"}, {"name":
Open in Playground

 

Lower temperatures give more precise results. Setting the API temperature to 0, or close to zero (such as 0.1 or 0.2) tends to give better results in most cases. Unlike GPT-3, where a higher temperature can provide useful creative and random results, higher temperatures with Codex may give you really random or erratic responses.

In cases where you need Codex to provide different potential results, start at zero and then increment upwards by .1 until you find suitable variation.

 

온도가 낮을수록 더 정확한 결과를 얻을 수 있습니다. API 온도를 0으로 설정하거나 0에 가깝게(예: 0.1 또는 0.2) 설정하면 대부분의 경우 더 나은 결과를 얻을 수 있습니다. 더 높은 온도가 유용한 창의적이고 임의적인 결과를 제공할 수 있는 GPT-3와 달리 Codex의 높은 온도는 정말 임의적이거나 불규칙한 응답을 제공할 수 있습니다.
다른 잠재적 결과를 제공하기 위해 Codex가 필요한 경우 0에서 시작하여 적절한 변형을 찾을 때까지 0.1씩 위쪽으로 증가합니다.

 

Organize tasks into functions. We can get Codex to write functions by specifying what the function should do in as precise terms as possible in comment. By writing the following comment, Codex creates a Javascript timer function that's triggered when a user presses a button:

A simple JavaScript timer

 

작업을 기능으로 구성합니다. 주석에서 가능한 한 정확한 용어로 함수가 수행해야 하는 작업을 지정하여 Codex가 함수를 작성하도록 할 수 있습니다. Codex는 다음 주석을 작성하여 사용자가 버튼을 누를 때 트리거되는 Javascript 타이머 기능을 생성합니다.
간단한 JavaScript 타이머

 

// Create a timer that creates an alert in 10 seconds
Open in Playground

 

We can use Codex to perform common tasks with well known libraries like creating a customer with the Stripe API:

Create a Stripe customer in Python

 

Codex를 사용하여 Stripe API로 고객을 생성하는 것과 같이 잘 알려진 라이브러리로 일반적인 작업을 수행할 수 있습니다.
Python에서 Stripe 고객 만들기

 

# Create a Stripe customer from an email address
Open in Playground

 

Creating example data. Testing applications often requires using example data. Because Codgen is a language model that understands how to comprehend and write natural language, you can ask Codex to create data like arrays of made up names, products and other variables.

 

예제 데이터를 생성합니다. 응용 프로그램을 테스트하려면 종종 예제 데이터를 사용해야 합니다. Codgen은 자연어를 이해하고 쓰는 방법을 이해하는 언어 모델이기 때문에 Codex에 구성된 이름, 제품 및 기타 변수의 배열과 같은 데이터를 생성하도록 요청할 수 있습니다.

 

/* Create an array of weather temperatures for San Francisco */
Open in Playground

 

Asking Codex to perform this task will produce a table like this:

 

Codex에게 이 작업을 수행하도록 요청하면 다음과 같은 테이블이 생성됩니다.

 

var weather = [
  { month: 'January', high: 58, low: 48 },
  { month: 'February', high: 61, low: 50 },
  { month: 'March', high: 64, low: 53 },
  { month: 'April', high: 67, low: 55 },
  { month: 'May', high: 70, low: 58 },
  { month: 'June', high: 73, low: 61 },
  { month: 'July', high: 76, low: 63 },
  { month: 'August', high: 77, low: 64 },
  { month: 'September', high: 76, low: 63 },
  { month: 'October', high: 73, low: 61 },
  { month: 'November', high: 68, low: 57 },
  { month: 'December', high: 64, low: 54 }
];
Open in Playground

 

Compound functions and small applications. We can provide Codex with a comment consisting of a complex request like creating a random name generator or performing tasks with user input and Codex can generate the rest provided there are enough tokens.

 

복합 함수 및 소규모 응용 프로그램. 임의 이름 생성기 생성 또는 사용자 입력으로 작업 수행과 같은 복잡한 요청으로 구성된 설명을 Codex에 제공할 수 있으며 Codex는 충분한 토큰이 있는 경우 나머지를 생성할 수 있습니다.

 

/*
Create a list of animals
Create a list of cities
Use the lists to generate stories about what I saw at the zoo in each city
*/
Open in Playground

 

Limit completion size for more precise results or lower latency. Requesting longer completions in Codex can lead to imprecise answers and repetition. Limit the size of the query by reducing max_tokens and setting stop tokens. For instance, add \n as a stop sequence to limit completions to one line of code. Smaller completions also incur less latency.

Use streaming to reduce latency. Large Codex queries can take tens of seconds to complete. To build applications that require lower latency, such as coding assistants that perform autocompletion, consider using streaming. Responses will be returned before the model finishes generating the entire completion. Applications that need only part of a completion can reduce latency by cutting off a completion either programmatically or by using creative values for stop.

Users can combine streaming with duplication to reduce latency by requesting more than one solution from the API, and using the first response returned. Do this by setting n > 1. This approach consumes more token quota, so use carefully (e.g., by using reasonable settings for max_tokens and stop).

Use Codex to explain code. Codex's ability to create and understand code allows us to use it to perform tasks like explaining what the code in a file does. One way to accomplish this is by putting a comment after a function that starts with "This function" or "This application is." Codex will usually interpret this as the start of an explanation and complete the rest of the text.

 

보다 정확한 결과 또는 대기 시간 단축을 위해 완료 크기를 제한합니다. Codex에서 더 긴 완료를 요청하면 부정확한 답변과 반복이 발생할 수 있습니다. max_tokens를 줄이고 중지 토큰을 설정하여 쿼리 크기를 제한합니다. 예를 들어 한 줄의 코드로 완료를 제한하려면 중지 시퀀스로 \n을 추가합니다. 완료 횟수가 적을수록 대기 시간도 줄어듭니다.


대기 시간을 줄이려면 스트리밍을 사용하십시오. 큰 Codex 쿼리는 완료하는 데 수십 초가 걸릴 수 있습니다. 자동 완성을 수행하는 코딩 도우미와 같이 짧은 대기 시간이 필요한 애플리케이션을 구축하려면 스트리밍을 사용하는 것이 좋습니다. 모델이 전체 완료 생성을 완료하기 전에 응답이 반환됩니다. 완료의 일부만 필요한 애플리케이션은 프로그래밍 방식으로 완료를 차단하거나 중지에 대한 창의적인 값을 사용하여 대기 시간을 줄일 수 있습니다.


사용자는 스트리밍과 복제를 결합하여 API에서 둘 이상의 솔루션을 요청하고 반환된 첫 번째 응답을 사용하여 대기 시간을 줄일 수 있습니다. n > 1로 설정하여 이를 수행하십시오. 이 접근 방식은 더 많은 토큰 할당량을 소비하므로 신중하게 사용하십시오(예: max_tokens 및 stop에 대한 합리적인 설정 사용).
Codex를 사용하여 코드를 설명하십시오. 코드를 생성하고 이해하는 Codex의 기능을 사용하여 파일의 코드가 수행하는 작업을 설명하는 것과 같은 작업을 수행할 수 있습니다. 이를 수행하는 한 가지 방법은 "이 함수" 또는 "이 애플리케이션은"으로 시작하는 함수 뒤에 주석을 추가하는 것입니다. Codex는 일반적으로 이것을 설명의 시작으로 해석하고 나머지 텍스트를 완성합니다.

 

/* Explain what the previous function is doing: It
Open in Playground

 

Explaining an SQL query. In this example we use Codex to explain in a human readable format what an SQL query is doing.

 

SQL 쿼리 설명. 이 예에서는 Codex를 사용하여 SQL 쿼리가 수행하는 작업을 사람이 읽을 수 있는 형식으로 설명합니다.

 

SELECT DISTINCT department.name
FROM department
JOIN employee ON department.id = employee.department_id
JOIN salary_payments ON employee.id = salary_payments.employee_id
WHERE salary_payments.date BETWEEN '2020-06-01' AND '2020-06-30'
GROUP BY department.name
HAVING COUNT(employee.id) > 10;
-- Explanation of the above query in human readable format
--
Open in Playground

Writing unit tests. Creating a unit test can be accomplished in Python simply by adding the comment "Unit test" and starting a function.

 

단위 테스트 작성. Python에서 "Unit test"라는 주석을 추가하고 함수를 시작하기만 하면 단위 테스트를 만들 수 있습니다.

 

# Python 3
def sum_numbers(a, b):
  return a + b

# Unit test
def
Open in Playground

 

Checking code for errors. By using examples, you can show Codex how to identify errors in code. In some cases no examples are required, however demonstrating the level and detail to provide a description can help Codex understand what to look for and how to explain it. (A check by Codex for errors should not replace careful review by the user. )

 

코드에 오류가 있는지 확인 중입니다. 예제를 사용하여 Codex에서 코드의 오류를 식별하는 방법을 보여줄 수 있습니다. 어떤 경우에는 예가 필요하지 않지만 설명을 제공하기 위해 수준과 세부 사항을 시연하면 Codex가 무엇을 찾고 어떻게 설명해야 하는지 이해하는 데 도움이 될 수 있습니다. (오류에 대한 Codex의 확인은 사용자의 신중한 검토를 대신할 수 없습니다. )

 

/* Explain why the previous function doesn't work. */
Open in Playground

 

Using source data to write database functions. Just as a human programmer would benefit from understanding the database structure and the column names, Codex can use this data to help you write accurate query requests. In this example we insert the schema for a database and tell Codex what to query the database for.

 

소스 데이터를 사용하여 데이터베이스 기능을 작성합니다. 인간 프로그래머가 데이터베이스 구조와 열 이름을 이해하면 도움이 되는 것처럼 Codex는 이 데이터를 사용하여 정확한 쿼리 요청을 작성하는 데 도움을 줄 수 있습니다. 이 예에서는 데이터베이스에 대한 스키마를 삽입하고 Codex에게 데이터베이스를 쿼리할 내용을 알려줍니다.

 

# Table albums, columns = [AlbumId, Title, ArtistId]
# Table artists, columns = [ArtistId, Name]
# Table media_types, columns = [MediaTypeId, Name]
# Table playlists, columns = [PlaylistId, Name]
# Table playlist_track, columns = [PlaylistId, TrackId]
# Table tracks, columns = [TrackId, Name, AlbumId, MediaTypeId, GenreId, Composer, Milliseconds, Bytes, UnitPrice]

# Create a query for all albums by Adele
Open in Playground

 

Converting between languages. You can get Codex to convert from one language to another by following a simple format where you list the language of the code you want to convert in a comment, followed by the code and then a comment with the language you want it translated into.

 

언어 간 변환. 주석에 변환하려는 코드의 언어를 나열한 다음 코드와 번역하려는 언어의 주석을 나열하는 간단한 형식에 따라 Codex를 한 언어에서 다른 언어로 변환할 수 있습니다.

 

# Convert this from Python to R
# Python version

[ Python code ]

# End

# R version
Open in Playground

 

Rewriting code for a library or framework. If you want Codex to make a function more efficient, you can provide it with the code to rewrite followed by an instruction on what format to use.

 

라이브러리 또는 프레임워크용 코드 재작성. Codex가 기능을 더 효율적으로 만들도록 하려면 다시 작성할 코드와 사용할 형식에 대한 지침을 Codex에 제공할 수 있습니다.

 

// Rewrite this as a React component
var input = document.createElement('input');
input.setAttribute('type', 'text');
document.body.appendChild(input);
var button = document.createElement('button');
button.innerHTML = 'Say Hello';
document.body.appendChild(button);
button.onclick = function() {
  var name = input.value;
  var hello = document.createElement('div');
  hello.innerHTML = 'Hello ' + name;
  document.body.appendChild(hello);
};

// React version:
Open in Playground

 

Inserting code 

Beta

The completions endpoint also supports inserting code within code by providing a suffix prompt in addition to the prefix prompt. This can be used to insert a completion in the middle of a function or file.

 

완료 끝점(completions endpoint)은 또한 접두사 프롬프트 외에 접미사 프롬프트를 제공하여 코드 내에 코드 삽입을 지원합니다. 함수나 파일 중간에 완성을 삽입하는 데 사용할 수 있습니다.

 

def get_largest_prime_factor(n):     if n < 2:         return False     def is_prime(n): > for i in range(2, n): > if n % i == 0: > return False > return True >     largest = 1     for j in range(2, n + 1):         if n % j == 0 and is_prime(j):     return largest

 

By providing the model with additional context, it can be much more steerable. However, this is a more constrained and challenging task for the model.

 

모델에 추가 컨텍스트를 제공함으로써 모델을 훨씬 더 조종할 수 있습니다. 그러나 이것은 모델에 대해 더 제한적이고 도전적인 작업입니다.

 

Best practices

Inserting code is a new feature in beta and you may have to modify the way you use the API for better results. Here are a few best practices:

Use max_tokens > 256. The model is better at inserting longer completions. With too small max_tokens, the model may be cut off before it's able to connect to the suffix. Note that you will only be charged for the number of tokens produced even when using larger max_tokens.

Prefer finish_reason == "stop". When the model reaches a natural stopping point or a user provided stop sequence, it will set finish_reason as "stop". This indicates that the model has managed to connect to the suffix well and is a good signal for the quality of a completion. This is especially relevant for choosing between a few completions when using n > 1 or resampling (see the next point).

Resample 3-5 times. While almost all completions connect to the prefix, the model may struggle to connect the suffix in harder cases. We find that resampling 3 or 5 times (or using best_of with k=3,5) and picking the samples with "stop" as their finish_reason can be an effective way in such cases. While resampling, you would typically want a higher temperatures to increase diversity.

Note: if all the returned samples have finish_reason == "length", it's likely that max_tokens is too small and model runs out of tokens before it manages to connect the prompt and the suffix naturally. Consider increasing max_tokens before resampling.

 

코드 삽입은 베타의 새로운 기능이며 더 나은 결과를 위해 API를 사용하는 방식을 수정해야 할 수도 있습니다. 다음은 몇 가지 모범 사례입니다.
max_tokens > 256을 사용하십시오. 모델은 더 긴 완료를 삽입하는 데 더 좋습니다. max_token이 너무 작으면 접미사에 연결하기 전에 모델이 잘릴 수 있습니다. 더 큰 max_tokens를 사용하는 경우에도 생성된 토큰 수에 대해서만 비용이 청구됩니다.


finish_reason == "중지"를 선호합니다. 모델이 자연스러운 중지 지점 또는 사용자가 제공한 중지 시퀀스에 도달하면 finish_reason을 "중지"로 설정합니다. 이것은 모델이 접미사에 잘 연결되었음을 나타내며 완성 품질에 대한 좋은 신호입니다. 이것은 특히 n > 1 또는 리샘플링을 사용할 때 몇 가지 완성 중에서 선택하는 것과 관련이 있습니다(다음 지점 참조).


3-5회 리샘플링. 거의 모든 완료가 접두사에 연결되지만 어려운 경우에는 모델이 접미사를 연결하는 데 어려움을 겪을 수 있습니다. 우리는 3번 또는 5번 리샘플링(또는 k=3,5와 함께 best_of를 사용)하고 finish_reason으로 "stop"을 사용하여 샘플을 선택하는 것이 이러한 경우에 효과적인 방법이 될 수 있음을 발견했습니다. 리샘플링하는 동안 일반적으로 다양성을 높이기 위해 더 높은 온도를 원할 것입니다.


참고: 반환된 모든 샘플에 finish_reason == "길이"가 있는 경우 max_tokens가 너무 작고 모델이 프롬프트와 접미사를 자연스럽게 연결하기 전에 토큰이 부족할 수 있습니다. 리샘플링하기 전에 max_tokens를 늘리는 것이 좋습니다.

 

Editing code 

Beta

The edits endpoint can be used to edit code, rather than just completing it. You provide some code and an instruction for how to modify it, and the code-davinci-edit-001 model will attempt to edit it accordingly. This is a natural interface for refactoring and tweaking code. During this initial beta period, usage of the edits endpoint is free.

 

edits 끝점은 코드를 완료하는 대신 코드를 편집하는 데 사용할 수 있습니다. 일부 코드와 수정 방법에 대한 지침을 제공하면 code-davinci-edit-001 모델이 그에 따라 수정을 시도합니다. 이것은 코드 리팩토링 및 조정을 위한 자연스러운 인터페이스입니다. 이 초기 베타 기간 동안 edits 엔드포인트 사용은 무료입니다.

 

Examples

Iteratively build a program

Writing code is often an iterative process that requires refining the text along the way. Editing makes it natural to continuously refine the output of the model until the final result is polished. In this example, we use fibonacci as an example of how to iteratively build upon code.

 

코드 작성은 종종 그 과정에서 텍스트를 수정해야 하는 반복적인 프로세스입니다. 편집은 최종 결과가 다듬어질 때까지 모델의 출력을 지속적으로 다듬는 것을 자연스럽게 만듭니다. 이 예제에서는 피보나치를 코드를 반복적으로 빌드하는 방법의 예로 사용합니다.

 

 

 

 

Best practices

The edits endpoint is still in alpha, we suggest following these best practices.

  1. Consider using an empty prompt! In this case, editing can be used similarly to completion.
  2. Be as specific with the instruction as possible.
  3. Sometimes, the model cannot find a solution and will result in an error. We suggest rewording your instruction or input.

모범 사례
edits 엔드포인트는 아직 알파 상태이므로 다음 모범 사례를 따르는 것이 좋습니다.

1. 빈 프롬프트 사용을 고려하십시오! 이 경우 편집은 완성과 유사하게 사용할 수 있습니다.
2. 가능한 한 구체적으로 지시하십시오.
3. 경우에 따라 모델이 솔루션을 찾지 못하고 오류가 발생합니다. 귀하의 지침이나 입력을 다른 말로 바꾸는 것이 좋습니다.

반응형

'Open AI > GUIDES' 카테고리의 다른 글

Guide - Rate limits  (0) 2023.03.05
Guide - Speech to text  (0) 2023.03.05
Guide - Chat completion (ChatGPT API)  (0) 2023.03.05
Guides - Production Best Practices  (0) 2023.01.10
Guides - Safety best practices  (0) 2023.01.10
Guides - Moderation  (0) 2023.01.10
Guides - Embeddings  (0) 2023.01.10
Guides - Fine tuning  (0) 2023.01.10
Guide - Image generation  (0) 2023.01.09
Guide - Text completion  (0) 2023.01.09

Guide - Text completion

2023. 1. 9. 07:27 | Posted by 솔웅


반응형

https://beta.openai.com/docs/guides/completion

 

OpenAI API

An API for accessing new AI models developed by OpenAI

beta.openai.com

Text completion

Learn how to generate or manipulate text

어떻게 텍스트를 만들어 내는지 배워 봅니다.

Introduction

The completions endpoint can be used for a wide variety of tasks. It provides a simple but powerful interface to any of our models. You input some text as a prompt, and the model will generate a text completion that attempts to match whatever context or pattern you gave it. For example, if you give the API the prompt, "As Descartes said, I think, therefore", it will return the completion " I am" with high probability.

The best way to start exploring completions is through our Playground. It's simply a text box where you can submit a prompt to generate a completion. To try it yourself, open this example in Playground:

 

완료 끝점 (Completions endpoint)은 다양한 작업에 사용할 수 있습니다. 모든 모델에 간단하지만 강력한 인터페이스를 제공합니다. 일부 텍스트를 프롬프트로 입력하면 모델은 사용자가 제공한 컨텍스트나 패턴과 일치하도록 시도하는 텍스트 완성을 생성합니다. 예를 들어 API에 "As Descartes said, I think, therefore "라는 프롬프트를 제공하면 높은 확률로 "I am" 완료를 반환합니다.
완료(completions) 탐색을 시작하는 가장 좋은 방법은 Playground를 이용하는 것입니다. 완료(completion)를 생성하기 위해 프롬프트를 제출할 수 있는 텍스트 상자일 뿐입니다. 직접 시도하려면 플레이그라운드에서 다음 예제를 여십시오.

Write a tagline for an ice cream shop.

Once you submit, you'll see something like this:

이것을 submit 하면 아래와 같은 내용을 보실 수 있습니다.

Write a tagline for an ice cream shop. We serve up smiles with every scoop!

The actual completion you see may differ because the API is stochastic by default. This means that you might get a slightly different completion every time you call it, even if your prompt stays the same. You can control this behavior with the temperature setting.

This simple text-in, text-out interface means you can "program" the model by providing instructions or just a few examples of what you'd like it to do. Its success generally depends on the complexity of the task and quality of your prompt. A good rule of thumb is to think about how you would write a word problem for a middle schooler to solve. A well-written prompt provides enough information for the model to know what you want and how it should respond. 

This guide covers general prompt design best practices and examples. To learn more about working with code using our Codex models, visit our code guide.

 

API는 기본적으로 확률적이므로 표시되는 실제 완료(completion)는 다를 수 있습니다. 즉, 프롬프트가 동일하게 유지되더라도 호출할 때마다 약간 다른 완성을 얻을 수 있습니다. 온도(temperature) 설정으로 이 동작을 제어할 수 있습니다.
이 간단한 텍스트 입력, 텍스트 출력 인터페이스는 지시 사항이나 원하는 작업의 몇 가지 예를 제공하여 모델을 "프로그래밍"할 수 있음을 의미합니다. 성공 여부는 일반적으로 작업의 복잡성과 프롬프트의 품질에 따라 달라집니다. 좋은 경험 법칙은 중학생이 풀 수 있는 단어 문제를 어떻게 작성할 것인지 생각하는 것입니다. 잘 작성된 프롬프트는 모델이 사용자가 원하는 것과 응답 방법을 알 수 있도록 충분한 정보를 제공합니다.
이 가이드는 일반적인 프롬프트 디자인 모범 사례 및 예제를 다룹니다. Codex 모델을 사용한 코드 작업에 대한 자세한 내용은 코드 가이드를 참조하십시오.

 
Keep in mind that the default models' training data cuts off in 2021, so they may not have knowledge of current events. We plan to add more continuous training in the future.
 
기본 모델의 교육 데이터는 2021년에 중단되므로 현재 이벤트에 대한 지식이 없을 수 있습니다. 향후 지속적인 교육을 추가할 계획입니다.

 

 

Prompt design

Basics

Our models can do everything from generating original stories to performing complex text analysis. Because they can do so many things, you have to be explicit in describing what you want. Showing, not just telling, is often the secret to a good prompt.

 

당사의 모델은 원본 스토리 생성에서 복잡한 텍스트 분석 수행에 이르기까지 모든 작업을 수행할 수 있습니다. 그들은 많은 일을 할 수 있기 때문에 원하는 것을 명확하게 설명해야 합니다. 말만 하는 것이 아니라 보여 주는 것이 좋은 프롬프트의 비결인 경우가 많습니다.

 

There are three basic guidelines to creating prompts:

 

프롬프트를 만들기 위한 세 가지 기본 지침이 있습니다.

 

Show and tell. Make it clear what you want either through instructions, examples, or a combination of the two. If you want the model to rank a list of items in alphabetical order or to classify a paragraph by sentiment, show it that's what you want.

 

Provide quality data. If you're trying to build a classifier or get the model to follow a pattern, make sure that there are enough examples. Be sure to proofread your examples — the model is usually smart enough to see through basic spelling mistakes and give you a response, but it also might assume this is intentional and it can affect the response.

 

Check your settings. The temperature and top_p settings control how deterministic the model is in generating a response. If you're asking it for a response where there's only one right answer, then you'd want to set these lower. If you're looking for more diverse responses, then you might want to set them higher. The number one mistake people use with these settings is assuming that they're "cleverness" or "creativity" controls.

 

보여주고 말하십시오. 지침, 예 또는 이 둘의 조합을 통해 원하는 것을 명확히 하십시오. 모델이 알파벳순으로 항목 목록의 순위를 매기거나 감정에 따라 단락을 분류하도록 하려면 그것이 원하는 것임을 보여주십시오.

양질의 데이터를 제공합니다. 분류자를 구축하거나 모델이 패턴을 따르도록 하려면 예제가 충분한지 확인하세요. 예제를 반드시 교정하십시오. 모델은 일반적으로 기본 철자 오류를 확인하고 응답을 제공할 만큼 충분히 똑똑하지만 이것이 의도적이며 응답에 영향을 미칠 수 있다고 가정할 수도 있습니다.

설정을 확인하십시오. 온도 및 top_p 설정은 모델이 응답을 생성하는 데 얼마나 결정적인지를 제어합니다. 정답이 하나뿐인 응답을 요청하는 경우 이 값을 더 낮게 설정하는 것이 좋습니다. 보다 다양한 응답을 찾고 있다면 더 높게 설정하는 것이 좋습니다. 사람들이 이러한 설정에서 가장 많이 범하는 실수는 "영리함" 또는 "창의성" 컨트롤이라고 가정하는 것입니다.

 

Troubleshooting

If you're having trouble getting the API to perform as expected, follow this checklist:

  1. Is it clear what the intended generation should be?
  2. Are there enough examples?
  3. Did you check your examples for mistakes? (The API won't tell you directly)
  4. Are you using temperature and top_p correctly?

API가 예상대로 작동하는 데 문제가 있는 경우 다음 체크리스트를 따르십시오.


1. 의도된 세대(generation)가 무엇이어야 하는지가 명확합니까?
2. 충분한 예가 있습니까?
3. 예제에서 실수를 확인했습니까? (API는 직접 알려주지 않습니다)
4. 온도와 top_p를 올바르게 사용하고 있습니까?

 

Classification

To create a text classifier with the API, we provide a description of the task and a few examples. In this example, we show how to classify the sentiment of Tweets.

Decide whether a Tweet's sentiment is positive, neutral, or negative. Tweet: I loved the new Batman movie! Sentiment:
Open in Playground

API로 텍스트 분류자를 생성하기 위해 작업에 대한 설명과 몇 가지 예를 제공합니다. 이 예에서는 트윗의 감정을 분류하는 방법을 보여줍니다.
트윗의 감정이 긍정적인지, 중립적인지, 부정적인지 결정합니다. 트윗: 새로운 배트맨 영화가 너무 좋았어요! 감정:
플레이그라운드에서 열기

 

It's worth paying attention to several features in this example:

  1. Use plain language to describe your inputs and outputs. We use plain language for the input "Tweet" and the expected output "Sentiment." As a best practice, start with plain language descriptions. While you can often use shorthand or keys to indicate the input and output, it's best to start by being as descriptive as possible and then working backwards to remove extra words and see if performance stays consistent.
  2. Show the API how to respond to any case. In this example, we include the possible sentiment labels in our instruction. A neutral label is important because there will be many cases where even a human would have a hard time determining if something is positive or negative, and situations where it's neither.
  3. You need fewer examples for familiar tasks. For this classifier, we don't provide any examples. This is because the API already has an understanding of sentiment and the concept of a Tweet. If you're building a classifier for something the API might not be familiar with, it might be necessary to provide more examples.

이 예에서 몇 가지 기능에 주의를 기울일 가치가 있습니다.


1. 일반 언어를 사용하여 입력 및 출력을 설명하십시오. 입력 "Tweet" 및 예상 출력 "Sentiment"에 일반 언어를 사용합니다. 가장 좋은 방법은 일반 언어 설명으로 시작하는 것입니다. 속기 또는 키를 사용하여 입력 및 출력을 표시할 수 있지만 가능한 한 설명적인 것으로 시작한 다음 거꾸로 작업하여 추가 단어를 제거하고 성능이 일관되게 유지되는지 확인하는 것이 가장 좋습니다.

 

2. 모든 사례에 대응하는 방법을 API에 보여줍니다. 이 예에서는 지침에 가능한 감정 레이블을 포함합니다. 사람도 긍정적인지 부정적인지 판단하기 힘든 경우가 많고, 둘 다 아닌 상황도 많기 때문에 중립적인 꼬리표가 중요하다.

 

3. 익숙한 작업에는 더 적은 예가 필요합니다. 이 분류자에 대해서는 어떤 예도 제공하지 않습니다. 이는 API가 이미 트윗의 감정과 개념을 이해하고 있기 때문입니다. API가 익숙하지 않을 수 있는 것에 대한 분류자를 빌드하는 경우 더 많은 예제를 제공해야 할 수 있습니다.

 

Improving the classifier's efficiency

Now that we have a grasp of how to build a classifier, let's take that example and make it even more efficient so that we can use it to get multiple results back from one API call.

Classify the sentiment in these tweets: 1. "I can't stand homework" 2. "This sucks. I'm bored 😠" 3. "I can't wait for Halloween!!!" 4. "My cat is adorable ❤️❤️" 5. "I hate chocolate" Tweet sentiment ratings:
Open in Playground

이제 분류기를 구축하는 방법을 이해했으므로 해당 예제를 사용하여 한 번의 API 호출에서 여러 결과를 반환하는 데 사용할 수 있도록 훨씬 더 효율적으로 만들어 보겠습니다.
다음 트윗에서 감정을 분류하세요. 1. "숙제를 참을 수 없어" 2. "이거 짜증나. 지루해 😠" 3. "할로윈이 너무 기다려져!!!" 4. "내 고양이는 사랑스러워 ❤️❤️" 5. "나는 초콜릿이 싫어" 트윗 감정 평가:
플레이그라운드에서 열기

 

We provide a numbered list of Tweets so the API can rate five (and even more) Tweets in just one API call.

It's important to note that when you ask the API to create lists or evaluate text you need to pay extra attention to your probability settings (Top P or Temperature) to avoid drift.

  1. Make sure your probability setting is calibrated correctly by running multiple tests.
  2. Don't make your list too long or the API is likely to drift.

 

API가 단 한 번의 API 호출로 5개(또는 그 이상)의 트윗을 평가할 수 있도록 번호가 매겨진 트윗 목록을 제공합니다.
목록을 만들거나 텍스트를 평가하도록 API에 요청할 때 드리프트를 방지하기 위해 확률 설정(상단 P 또는 온도)에 각별한 주의를 기울여야 한다는 점에 유의해야 합니다.
1. 여러 테스트를 실행하여 확률 설정이 올바르게 보정되었는지 확인하십시오.
2. 목록을 너무 길게 만들지 마십시오. 그렇지 않으면 API가 표류할 수 있습니다.

 


Generation

One of the most powerful yet simplest tasks you can accomplish with the API is generating new ideas or versions of input. You can ask for anything from story ideas, to business plans, to character descriptions and marketing slogans. In this example, we'll use the API to create ideas for using virtual reality in fitness.

Brainstorm some ideas combining VR and fitness:
Open in Playground

If needed, you can improve the quality of the responses by including some examples in your prompt.

 

API로 수행할 수 있는 가장 강력하면서도 가장 간단한 작업 중 하나는 새로운 아이디어 또는 입력 버전을 생성하는 것입니다. 스토리 아이디어부터 사업 계획, 캐릭터 설명 및 마케팅 슬로건에 이르기까지 무엇이든 요청할 수 있습니다. 이 예에서는 API를 사용하여 피트니스에서 가상 현실을 사용하기 위한 아이디어를 생성합니다.
VR과 피트니스를 결합한 몇 가지 아이디어를 브레인스토밍합니다.
플레이그라운드에서 열기


필요한 경우 프롬프트에 몇 가지 예를 포함하여 응답의 품질을 개선할 수 있습니다.


Conversation

The API is extremely adept at carrying on conversations with humans and even with itself. With just a few lines of instruction, we've seen the API perform as a customer service chatbot that intelligently answers questions without ever getting flustered or a wise-cracking conversation partner that makes jokes and puns. The key is to tell the API how it should behave and then provide a few examples.

Here's an example of the API playing the role of an AI answering questions:

The following is a conversation with an AI assistant. The assistant is helpful, creative, clever, and very friendly. Human: Hello, who are you? AI: I am an AI created by OpenAI. How can I help you today? Human:
Open in Playground

API는 사람과 대화하는 데 매우 능숙합니다. 몇 줄의 지침만으로 우리는 API가 당황하지 않고 지능적으로 질문에 대답하는 고객 서비스 챗봇 또는 농담과 말장난을 하는 현명한 대화 파트너로 작동하는 것을 보았습니다. 핵심은 API가 어떻게 동작해야 하는지 알려주고 몇 가지 예를 제공하는 것입니다.


다음은 AI가 질문에 답하는 역할을 하는 API의 예입니다.


다음은 AI 비서와의 대화입니다. 조수는 도움이 되고 창의적이며 영리하고 매우 친절합니다. 인간: 안녕, 누구세요? AI: 저는 OpenAI가 만든 AI입니다. 무엇을 도와드릴까요? 인간:


플레이그라운드에서 열기

 

This is all it takes to create a chatbot capable of carrying on a conversation. Underneath its simplicity, there are several things going on that are worth paying attention to:

  1. We tell the API the intent but we also tell it how to behave. Just like the other prompts, we cue the API into what the example represents, but we also add another key detail: we give it explicit instructions on how to interact with the phrase "The assistant is helpful, creative, clever, and very friendly."
  2. Without that instruction the API might stray and mimic the human it's interacting with and become sarcastic or some other behavior we want to avoid.
  3. We give the API an identity. At the start we have the API respond as an AI assistant. While the API has no intrinsic identity, this helps it respond in a way that's as close to the truth as possible. You can use identity in other ways to create other kinds of chatbots. If you tell the API to respond as a woman who works as a research scientist in biology, you'll get intelligent and thoughtful comments from the API similar to what you'd expect from someone with that background.

대화를 이어갈 수 있는 챗봇을 만드는 데 필요한 모든 것입니다. 단순함 아래에는 주의를 기울일 가치가 있는 몇 가지 사항이 있습니다.


1. 우리는 API에 의도를 알릴 뿐 아니라 행동 방법도 알려줍니다. 다른 프롬프트와 마찬가지로 API에 예제가 나타내는 내용을 입력하지만 또 다른 주요 세부 정보도 추가합니다. "어시스턴트는 유용하고 창의적이며 영리하고 매우 친절합니다. "

 

2. 이 명령이 없으면 API가 길을 잃고 상호 작용하는 인간을 모방하고 비꼬거나 피하고 싶은 다른 동작이 될 수 있습니다.

 

3. 우리는 API에 ID를 부여합니다. 처음에는 API가 AI 비서로 응답하도록 합니다. API에는 본질적인 ID가 없지만 가능한 한 진실에 가까운 방식으로 응답하는 데 도움이 됩니다. 다른 방식으로 ID를 사용하여 다른 종류의 챗봇을 만들 수 있습니다. 생물학 연구 과학자로 일하는 여성으로 응답하도록 API에 지시하면 해당 배경을 가진 사람에게 기대하는 것과 유사한 지능적이고 사려 깊은 의견을 API에서 받게 됩니다.

 

 

In this example we create a chatbot that is a bit sarcastic and reluctantly answers questions:

 

이 예에서는 약간 비꼬고 마지못해 질문에 대답하는 챗봇을 만듭니다.

Marv is a chatbot that reluctantly answers questions with sarcastic responses:
You: How many pounds are in a kilogram?
Marv: This again? There are 2.2 pounds in a kilogram. Please make a note of this.
You: What does HTML stand for?
Marv: Was Google too busy? Hypertext Markup Language. The T is for try to ask better questions in the future.
You: When did the first airplane fly?
Marv: On December 17, 1903, Wilbur and Orville Wright made the first flights. I wish they’d come and take me away. You: What is the meaning of life?
Marv: I’m not sure. I’ll ask my friend Google.
You: Why is the sky blue?
Open in Playground

Marv는 마지못해 비꼬는 답변으로 질문에 대답하는 챗봇입니다.
당신: 1킬로그램은 몇 파운드인가요?
마브: 또? 킬로그램에는 2.2파운드가 있습니다. 이를 메모해 두십시오.
당신: HTML은 무엇을 의미합니까?
Marv: Google이 너무 바빴나요? 하이퍼텍스트 마크업 언어. T는 앞으로 더 나은 질문을 하기 위한 것입니다.
당신: 최초의 비행기는 언제 날았나요?
마브: 1903년 12월 17일에 Wilbur와 Orville Wright가 첫 비행을 했습니다. 그들이 와서 나를 데려갔으면 좋겠다. 

당신: 삶의 의미는 무엇입니까?
마브: 잘 모르겠습니다. 내 친구 구글에게 물어볼게.
당신: 하늘이 왜 파란색이야?
플레이그라운드에서 열기

 

To create an amusing and somewhat helpful chatbot, we provide a few examples of questions and answers showing the API how to reply. All it takes is just a few sarcastic responses, and the API is able to pick up the pattern and provide an endless number of snarky responses.

 

재미있고 다소 도움이 되는 챗봇을 만들기 위해 API가 응답하는 방법을 보여주는 질문과 답변의 몇 가지 예를 제공합니다. 비꼬는 답변 몇 개만 있으면 API가 패턴을 파악하고 무수한 비꼬는 답변을 제공할 수 있습니다.


 

Transformation

The API is a language model that is familiar with a variety of ways that words and characters can be used to express information. This ranges from natural language text to code and languages other than English. The API is also able to understand content on a level that allows it to summarize, convert and express it in different ways.

 

API는 정보를 표현하기 위해 단어와 문자를 사용할 수 있는 다양한 방법에 익숙한 언어 모델입니다. 이는 자연어 텍스트에서 코드 및 영어 이외의 언어에 이르기까지 다양합니다. API는 또한 콘텐츠를 다양한 방식으로 요약, 변환 및 표현할 수 있는 수준에서 콘텐츠를 이해할 수 있습니다.

 

Translation

In this example we show the API how to convert from English to French, Spanish, and Japanese:

Translate this into French, Spanish and Japanese:
What rooms do you have available?
Open in Playground

This example works because the API already has a grasp of these languages, so there's no need to try to teach them.

If you want to translate from English to a language the API is unfamiliar with, you'd need to provide it with more examples or even fine-tune a model to do it fluently.

 

이 예에서는 영어에서 프랑스어, 스페인어 및 일본어로 변환하는 방법을 API에 보여줍니다.
이것을 프랑스어, 스페인어 및 일본어로 번역하십시오: 어떤 방이 있습니까?
플레이그라운드에서 열기
이 예제는 API가 이미 이러한 언어를 이해하고 있으므로 이를 가르치려고 할 필요가 없기 때문에 작동합니다.
영어에서 API가 익숙하지 않은 언어로 번역하려면 더 많은 예제를 제공하거나 유창하게 수행할 수 있도록 모델을 미세 조정해야 합니다.

 

Conversion

In this example we convert the name of a movie into emoji. This shows the adaptability of the API to picking up patterns and working with other characters.

 

이 예에서는 영화 이름을 이모티콘으로 변환합니다. 이것은 패턴을 선택하고 다른 캐릭터와 작업하는 API의 적응성을 보여줍니다.

Convert movie titles into emoji.
Back to the Future: 👨👴🚗🕒
Batman: 🤵🦇
Transformers: 🚗🤖
Star Wars:
Open in Playground

Summarization

The API is able to grasp the context of text and rephrase it in different ways. In this example, we create an explanation a child would understand from a longer, more sophisticated text passage. This illustrates that the API has a deep grasp of language.

 

API는 텍스트의 컨텍스트를 파악하고 다른 방식으로 바꿀 수 있습니다. 이 예에서는 어린이가 더 길고 정교한 텍스트 구절에서 이해할 수 있는 설명을 만듭니다. 이것은 API가 언어를 깊이 이해하고 있음을 보여줍니다.

Summarize this for a second-grade student:
Jupiter is the fifth planet from the Sun and the largest in the Solar System. It is a gas giant with a mass one-thousandth that of the Sun, but two-and-a-half times that of all the other planets in the Solar System combined. Jupiter is one of the brightest objects visible to the naked eye in the night sky, and has been known to ancient civilizations since before recorded history. It is named after the Roman god Jupiter.[19] When viewed from Earth, Jupiter can be bright enough for its reflected light to cast visible shadows,[20] and is on average the third-brightest natural object in the night sky after the Moon and Venus.
Open in Playground        
2학년 학생을 위해 이것을 요약하십시오:
목성은 태양에서 다섯 번째 행성이며 태양계에서 가장 큰 행성입니다. 그것은 질량이 태양의 1000분의 1이지만 태양계의 다른 모든 행성을 합친 것의 2.5배인 가스 거성입니다. 목성은 밤하늘에서 육안으로 볼 수 있는 가장 밝은 물체 중 하나로, 역사가 기록되기 이전부터 고대 문명에 알려졌습니다. 그것은 로마 신 Jupiter의 이름을 따서 명명되었습니다.[19] 지구에서 볼 때 목성은 반사광이 눈에 보이는 그림자를 드리울 만큼 충분히 밝을 수 있으며[20] 평균적으로 밤하늘에서 달과 금성 다음으로 세 번째로 밝은 자연 물체입니다.
플레이그라운드에서 열기
 

Completion

While all prompts result in completions, it can be helpful to think of text completion as its own task in instances where you want the API to pick up where you left off. For example, if given this prompt, the API will continue the train of thought about vertical farming. You can lower the temperature setting to keep the API more focused on the intent of the prompt or increase it to let it go off on a tangent.

 

모든 프롬프트는 완료로 이어지지만 API가 사용자가 중단한 위치에서 선택하기를 원하는 경우 텍스트 완성을 자체 작업으로 생각하는 것이 도움이 될 수 있습니다. 예를 들어, 이 프롬프트가 주어지면 API는 수직 농업에 대한 일련의 생각을 계속할 것입니다. API가 프롬프트의 의도에 더 집중하도록 온도 설정을 낮추거나 접선에서 꺼지도록 온도 설정을 높일 수 있습니다.

Vertical farming provides a novel solution for producing food locally, reducing transportation costs and
Open in Playground

수직 농업은 현지에서 식량을 생산하고 운송 비용을 절감하며
플레이그라운드에서 열기

 

This next prompt shows how you can use completion to help write React components. We send some code to the API, and it's able to continue the rest because it has an understanding of the React library. We recommend using our Codex models for tasks that involve understanding or generating code. To learn more, visit our code guide.

이 다음 프롬프트는 완성을 사용하여 React 구성 요소를 작성하는 방법을 보여줍니다. API에 일부 코드를 보내고 React 라이브러리를 이해하고 있기 때문에 나머지를 계속할 수 있습니다. 코드 이해 또는 생성과 관련된 작업에는 Codex 모델을 사용하는 것이 좋습니다. 자세한 내용은 코드 가이드를 참조하십시오.
 
import React from 'react'; const HeaderComponent = () => (
Open in Playground

Factual responses

The API has a lot of knowledge that it's learned from the data that it was been trained on. It also has the ability to provide responses that sound very real but are in fact made up. There are two ways to limit the likelihood of the API making up an answer.

  1. Provide a ground truth for the API. If you provide the API with a body of text to answer questions about (like a Wikipedia entry) it will be less likely to confabulate a response.
  2. Use a low probability and show the API how to say "I don't know". If the API understands that in cases where it's less certain about a response that saying "I don't know" or some variation is appropriate, it will be less inclined to make up answers.

API에는 학습된 데이터에서 학습한 많은 지식이 있습니다. 또한 매우 실제처럼 들리지만 실제로는 만들어진 응답을 제공하는 기능이 있습니다. API가 답변을 구성할 가능성을 제한하는 두 가지 방법이 있습니다.

1. API에 대한 실측 정보를 제공합니다. Wikipedia 항목과 같은 질문에 답하기 위해 API에 텍스트 본문을 제공하면 응답을 구성할 가능성이 줄어듭니다.

2. 낮은 확률을 사용하고 API에 "모르겠습니다"라고 말하는 방법을 보여줍니다. API가 "모르겠습니다"라고 말하는 응답이 확실하지 않거나 일부 변형이 적절한 경우를 이해하면 응답을 구성할 가능성이 줄어듭니다.

 

In this example we give the API examples of questions and answers it knows and then examples of things it wouldn't know and provide question marks. We also set the probability to zero so the API is more likely to respond with a "?" if there is any doubt.

 

이 예에서는 API가 알고 있는 질문과 답변의 예를 API에 제공한 다음 알 수 없는 항목의 예를 제공하고 물음표를 제공합니다. 또한 API가 "?"로 응답할 가능성이 더 높도록 확률을 0으로 설정했습니다. 의심의 여지가 있다면.

Q: Who is Batman?
A: Batman is a fictional comic book character.
Q: What is torsalplexity?
A: ?
Q: What is Devz9?
A: ?
Q: Who is George Lucas?
A: George Lucas is American film director and producer famous for creating Star Wars.
Q: What is the capital of California?
A: Sacramento.
Q: What orbits the Earth?
A: The Moon.
Q: Who is Fred Rickerson?
A: ?
Q: What is an atom?
A: An atom is a tiny particle that makes up everything.
Q: Who is Alvan Muntz?
A: ?
Q: What is Kozar-09?
A: ?
Q: How many moons does Mars have?
A: Two, Phobos and Deimos.
Q:
Open in Playground

Inserting text 

Beta

The completions endpoint also supports inserting text within text by providing a suffix prompt in addition to the prefix prompt. This need naturally arises when writing long-form text, transitioning between paragraphs, following an outline, or guiding the model towards an ending. This also works on code, and can be used to insert in the middle of a function or file. Visit our code guide to learn more.

To illustrate how important suffix context is to our ability to predict, consider the prompt, “Today I decided to make a big change.” There’s many ways one could imagine completing the sentence. But if we now supply the ending of the story: “I’ve gotten many compliments on my new hair!”, the intended completion becomes clear.

 

완성 끝점(completions endpoint)은 또한 접두사 프롬프트 외에 접미사 프롬프트를 제공하여 텍스트 내에 텍스트 삽입을 지원합니다. 이러한 필요성은 긴 형식의 텍스트를 작성하거나, 단락 사이를 전환하거나, 개요를 따르거나, 모델을 결말로 안내할 때 자연스럽게 발생합니다. 이는 코드에서도 작동하며 함수 또는 파일 중간에 삽입하는 데 사용할 수 있습니다. 자세한 내용은 코드 가이드를 참조하세요.
접미사 컨텍스트가 우리의 예측 능력에 얼마나 중요한지 설명하기 위해 "오늘 나는 큰 변화를 주기로 결정했습니다."라는 프롬프트를 고려하십시오. 문장 완성을 상상할 수 있는 방법에는 여러 가지가 있습니다. 그러나 이제 이야기의 결말을 "내 새로운 머리에 대해 많은 찬사를 받았습니다!"라고 하면 의도한 완성이 분명해집니다.

 

I went to college at Boston University. After getting my degree, I decided to make a change. A big change!   I packed my bags and moved to the west coast of the United States.   Now, I can’t get enough of the Pacific Ocean!

By providing the model with additional context, it can be much more steerable. However, this is a more constrained and challenging task for the model.

 

모델에 추가 컨텍스트를 제공함으로써 모델을 훨씬 더 조종할 수 있습니다. 그러나 이것은 모델에 대해 더 제한적이고 도전적인 작업입니다.

 

Best practices

Inserting text is a new feature in beta and you may have to modify the way you use the API for better results. Here are a few best practices:

Use max_tokens > 256. The model is better at inserting longer completions. With too small max_tokens, the model may be cut off before it's able to connect to the suffix. Note that you will only be charged for the number of tokens produced even when using larger max_tokens.

Prefer finish_reason == "stop". When the model reaches a natural stopping point or a user provided stop sequence, it will set finish_reason as "stop". This indicates that the model has managed to connect to the suffix well and is a good signal for the quality of a completion. This is especially relevant for choosing between a few completions when using n > 1 or resampling (see the next point).

Resample 3-5 times. While almost all completions connect to the prefix, the model may struggle to connect the suffix in harder cases. We find that resampling 3 or 5 times (or using best_of with k=3,5) and picking the samples with "stop" as their finish_reason can be an effective way in such cases. While resampling, you would typically want a higher temperatures to increase diversity.

Note: if all the returned samples have finish_reason == "length", it's likely that max_tokens is too small and model runs out of tokens before it manages to connect the prompt and the suffix naturally. Consider increasing max_tokens before resampling.

Try giving more clues. In some cases to better help the model’s generation, you can provide clues by giving a few examples of patterns that the model can follow to decide a natural place to stop.

 

텍스트 삽입은 베타의 새로운 기능이며 더 나은 결과를 위해 API 사용 방식을 수정해야 할 수도 있습니다. 다음은 몇 가지 모범 사례입니다.


max_tokens > 256을 사용하십시오. 모델은 더 긴 완료를 삽입하는 데 더 좋습니다. max_token이 너무 작으면 접미사에 연결하기 전에 모델이 잘릴 수 있습니다. 더 큰 max_tokens를 사용하는 경우에도 생성된 토큰 수에 대해서만 비용이 청구됩니다.


finish_reason == "중지"를 선호합니다. 모델이 자연스러운 중지 지점 또는 사용자가 제공한 중지 시퀀스에 도달하면 finish_reason을 "중지"로 설정합니다. 이것은 모델이 접미사에 잘 연결되었음을 나타내며 완성 품질에 대한 좋은 신호입니다. 이것은 특히 n > 1 또는 리샘플링을 사용할 때 몇 가지 완성 중에서 선택하는 것과 관련이 있습니다(다음 지점 참조).


3-5회 리샘플링. 거의 모든 완료가 접두사에 연결되지만 어려운 경우에는 모델이 접미사를 연결하는 데 어려움을 겪을 수 있습니다. 우리는 3번 또는 5번 리샘플링(또는 k=3,5와 함께 best_of를 사용)하고 finish_reason으로 "stop"을 사용하여 샘플을 선택하는 것이 이러한 경우에 효과적인 방법이 될 수 있음을 발견했습니다. 리샘플링하는 동안 일반적으로 다양성을 높이기 위해 더 높은 온도를 원할 것입니다.


참고: 반환된 모든 샘플에 finish_reason == "길이"가 있는 경우 max_tokens가 너무 작고 모델이 프롬프트와 접미사를 자연스럽게 연결하기 전에 토큰이 부족할 수 있습니다. 리샘플링하기 전에 max_tokens를 늘리는 것이 좋습니다.


더 많은 단서를 제공하십시오. 경우에 따라 모델 생성을 더 잘 돕기 위해 모델이 따라야 할 자연스러운 위치를 결정하기 위해 따라갈 수 있는 패턴의 몇 가지 예를 제공하여 단서를 제공할 수 있습니다.

How to make a delicious hot chocolate: 1. Boil water 2. Put hot chocolate in a cup 3. Add boiling water to the cup 4. Enjoy the hot chocolate

1. Dogs are loyal animals. 2. Lions are ferocious animals. 3. Dolphins are playful animals. 4. Horses are majestic animals.

 

Editing text 

Alpha

The edits endpoint can be used to edit text, rather than just completing it. You provide some text and an instruction for how to modify it, and the text-davinci-edit-001 model will attempt to edit it accordingly. This is a natural interface for translating, editing, and tweaking text. This is also useful for refactoring and working with code. Visit our code guide to learn more. During this initial beta period, usage of the edits endpoint is free.

 

edits 끝점은 텍스트를 완료하는 대신 텍스트를 편집하는 데 사용할 수 있습니다. 일부 텍스트와 수정 방법에 대한 지침을 제공하면 text-davinci-edit-001 모델이 그에 따라 수정을 시도합니다. 텍스트 번역, 편집 및 조정을 위한 자연스러운 인터페이스입니다. 이는 리팩토링 및 코드 작업에도 유용합니다. 자세한 내용은 코드 가이드를 참조하세요. 이 초기 베타 기간 동안 edits 엔드포인트 사용은 무료입니다.

 

Examples

INPUT
GPT-3 is a very nice AI That's pretty good at writing replies When it's asked a question It gives its suggestion This is a poem it made that rhymes
INSTRUCTIONS
Make this in the voice of GPT-3
OUTPUT
I am a very nice AI
반응형

'Open AI > GUIDES' 카테고리의 다른 글

Guide - Rate limits  (0) 2023.03.05
Guide - Speech to text  (0) 2023.03.05
Guide - Chat completion (ChatGPT API)  (0) 2023.03.05
Guides - Production Best Practices  (0) 2023.01.10
Guides - Safety best practices  (0) 2023.01.10
Guides - Moderation  (0) 2023.01.10
Guides - Embeddings  (0) 2023.01.10
Guides - Fine tuning  (0) 2023.01.10
Guide - Image generation  (0) 2023.01.09
Guide - Code completion  (0) 2023.01.09
이전 1 2 다음