ACTIONS
  • Home
  • My Actions
  • My Projects
  • My Packages
OpenAI -> Get embeddings
Function Documentation: OpenAI -> Get Embeddings

Action summary

OpenAI -> Get embeddings

Xano

Function Documentation: OpenAI -> Get Embeddings

OpenAI Embeddings API

Overview

This function generates an embedding for a given text input using the OpenAI API. It requires parameters such as the input text & model. The function ensures that the necessary environment variables are set and verifies conditions before making the API request and processing the response.

Inputs

  1. openai_api_key (registry|text) Required Sensitive data

    • Description: The API key for your OpenAI account.
  2. input_text (text) Required

    • Description: The text input for which an embedding will be generated by the OpenAI API.
  3. model (enum) Required

    • Description: Specifies the model to be used for generating the embedding.
    • Options:
      • text-embedding-3-small (default)
      • text-embedding-3-large
      • text-embedding-ada-002

Function Stack

1. OpenAI API Request

  1. API Request to https://api.openai.com

    • Purpose: Sends a request to the OpenAI API using the specified model and input text.
  2. Precondition: openai_api_response.status == 200

    • Purpose: Confirms that the API request was successful (HTTP status code 200).

2. OpenAI API Response

  1. Create Variable: response
    • Purpose: Stores the response from the OpenAI API.

Response

  • The function returns the generated embedding.

Success response

   {
   [
      0.020631326,
      -0.0042284927,
      .
      .
      .
      0.03682661
   ]
   }

Error response

{
  "message": "Incorrect API key provided: sk-Nosne*********************************************GQPD. You can find your API key at https://platform.openai.com/account/api-keys."
}

Example

Input

{
  "input_text": "Welcome to Xano Actions!",
  "model": "text-embedding-3-small",
  "show_token_usage": true
}

Response

{
   [
      0.020631326,
      -0.0042284927,
      .
      .
      .
      0.03682661
   ]
}

Version notes

2024-10-04 14:37:26
Current
2024-10-04T19:37:28.000+00:00