2023년 April 23일

OpenAI API : Create embeddings

임베딩이란 기계 학습 모델과 알고리즘이 쉽게 사용할 수 있는 주어진 입력의 벡터 표현(or 벡터 값)

POST https://api.openai.com/v1/embeddingsCreates an embedding vector representing the input text.
Request bodymodel (string / 필수)ID of the model to use.
input (string or array / 필수)Input text to get embeddings for, encoded as a string or array of tokens. To get embeddings for multiple inputs in a single request, pass an array of strings or array of token arrays. Each input must not exceed 8192 tokens in length.
user (string / 선택)

Request 시 (curl 사용 )

curl https://api.openai.com/v1/embeddings \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "input": "The food was delicious and the waiter...",
    "model": "text-embedding-ada-002"
  }'

Parameters

{
  "model": "text-embedding-ada-002",
  "input": "The food was delicious and the waiter..."
}

Response 값

{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "embedding": [
        0.0023064255,
        -0.009327292,
        .... (1536 floats total for ada-002)
        -0.0028842222,
      ],
      "index": 0
    }
  ],
  "model": "text-embedding-ada-002",
  "usage": {
    "prompt_tokens": 8,
    "total_tokens": 8
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

연관 글
BCT NEWS
인기 글
워드프레스 유지보수
워드프레스 유지보수