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

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리


반응형

https://platform.openai.com/docs/api-reference/chat

 

OpenAI API

An API for accessing new AI models developed by OpenAI

platform.openai.com

 

Chat

Given a chat conversation, the model will return a chat completion response.

채팅 대화가 주어지면 해당 모델은 chat completin response를 return 합니다.

 

Create chat completion

Beta

POST https://api.openai.com/v1/chat/completions

Creates a completion for the chat message

chat message에 대해 completion을 생성합니다.

 

import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")

completion = openai.ChatCompletion.create(
  model="gpt-3.5-turbo",
  messages=[
    {"role": "user", "content": "Hello!"}
  ]
)

print(completion.choices[0].message)
{
  "model": "gpt-3.5-turbo",
  "messages": [{"role": "user", "content": "Hello!"}]
}
{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "created": 1677652288,
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "\n\nHello there, how may I assist you today?",
    },
    "finish_reason": "stop"
  }],
  "usage": {
    "prompt_tokens": 9,
    "completion_tokens": 12,
    "total_tokens": 21
  }
}

 

Request body

model
string Required

ID of the model to use. Currently, only gpt-3.5-turbo and gpt-3.5-turbo-0301 are supported.

사용할 모델의 ID입니다. 현재 gpt-3.5-turbo 및 gpt-3.5-turbo-0301만 지원됩니다.

 

messages
array Required

The messages to generate chat completions for, in the chat format.

채팅 형식으로 chat completions를 생성할 메시지입니다.

 

temperature
number Optional Defaults to 1

What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.

0과 2 사이에서 사용할 샘플링 온도. 0.8과 같은 높은 값은 출력을 더 무작위로 만들고 0.2와 같은 낮은 값은 더 집중적이고 결정적으로 만듭니다.

 

We generally recommend altering this or top_p but not both.

 

이 값이나 top_p 값을 변경할 수 있는데 두가지를 한꺼번에 변경하는 것은 권장하지 않습니다.

 

 

top_p
number Optional Defaults to 1

An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.

Temperature 의 대안 방법 입니다. ,nucleus 샘플링 이라고 합니다.  모델은 top_p probability mass  와 관련 된 토큰의 결과들을 고려하게 됩니다. 즉 0.1 값을 갖게 되면 상의 10%의 probability mass (확률량)를 구성하는 토큰만 고려된다는 것을 의미합니다. 

 

We generally recommend altering this or temperature but not both.

 

이 값이나 temperature 값을 변경할 수 있는데 두가지를 한꺼번에 변경하는 것은 권장하지 않습니다.

 

n
integer Optional Defaults to 1

How many chat completion choices to generate for each input message.

각 입력 메시지에 대해 생성하기 위한 chat completion choices 는 얼마나 많이 있는지를 나타냄

 

stream
boolean Optional Defaults to false

If set, partial message deltas will be sent, like in ChatGPT. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message.

True로 설정하면 ChatGPT에서와 같이 부분 메시지(델타)가 전송됩니다. 토큰은 사용 가능해지면 데이터 전용 서버 전송 이벤트로 전송되며, 스트림은 data: [DONE] 메시지로 종료됩니다.

 

stop
string or array Optional Defaults to null

Up to 4 sequences where the API will stop generating further tokens.

API가 추가 토큰 생성을 중지하는 최대 4개의 시퀀스.

 

max_tokens
integer Optional Defaults to inf

The maximum number of tokens allowed for the generated answer. By default, the number of tokens the model can return will be (4096 - prompt tokens).

생성된 답변에 허용되는 최대 토큰 수입니다. 기본적으로 모델이 반환할 수 있는 토큰 수는 (4096 - 프롬프트 토큰)입니다.

 

presence_penalty
number Optional Defaults to 0

Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.

-2.0에서 2.0 사이의 숫자입니다. 양수 값은 지금까지 텍스트에 나타나는지 여부에 따라 새 토큰에 페널티를 주어 모델이 새 주제에 대해 이야기할 가능성을 높입니다.

 

See more information about frequency and presence penalties.

 
 
frequency_penalty
number
Optional
Defaults to 0

Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.

-2.0에서 2.0 사이의 숫자입니다. 양수 값은 지금까지 텍스트의 기존 빈도를 기반으로 새 토큰에 페널티를 주어 모델이 동일한 줄을 그대로 반복할 가능성을 줄입니다.

 

See more information about frequency and presence penalties.

 
 
logit_bias
map Optional Defaults to null

Modify the likelihood of specified tokens appearing in the completion.

completion에 지정된 토큰이 나타날 가능성을 수정합니다.

 

Accepts a json object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban or exclusive selection of the relevant token.

 

토큰(토크나이저의 토큰 ID로 지정됨)을 -100에서 100까지의 관련 바이어스 값에 매핑하는 json 개체를 accept합니다. 수학적으로 바이어스는 샘플링 전에 모델에서 생성된 로짓에 추가됩니다. 정확한 효과는 모델마다 다르지만 -1과 1 사이의 값은 선택 가능성을 낮추거나 높여야 합니다. -100 또는 100과 같은 값은 관련 토큰을 금지하거나 배타적으로 선택해야 합니다.

 

 

user
string Optional

A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.

OpenAI가 남용을 모니터링하고 탐지하는 데 도움이 될 수 있는 최종 사용자를 나타내는 고유 식별자입니다.

 

 

OpenAI API

An API for accessing new AI models developed by OpenAI

platform.openai.com

 
 
 
반응형