Learn R Programming

chatAI4R (version 1.3.1)

textEmbedding: Text Embedding from OpenAI Embeddings API

Description

This function calls the OpenAI Embeddings API to get the multidimensional vector via text embedding of the input text. This function uses the 'text-embedding-3-small' model by default, with options for 'text-embedding-3-large' and legacy 'text-embedding-ada-002'.

Usage

textEmbedding(
  text,
  model = "text-embedding-3-small",
  api_key = Sys.getenv("OPENAI_API_KEY")
)

Value

A vector representing the text embeddings.

Arguments

text

A string. The input text to get the embedding for. This should be a character string.

model

A string. The embedding model to use. Options: "text-embedding-3-small" (default), "text-embedding-3-large", "text-embedding-ada-002" (legacy).

api_key

A string. The API key for the OpenAI API. Defaults to the value of the environment variable "OPENAI_API_KEY".

Author

Satoshi Kume

Examples

Run this code
if (FALSE) {
Sys.setenv(OPENAI_API_KEY = "Your API key")
textEmbedding("Hello, world!")
textEmbedding("Hello, world!", model = "text-embedding-3-large")
}

Run the code above in your browser using DataLab