TDApiClient.API_Request is a static helper function to invoke the in-database function API_Request.
This function returns a teradataml DataFrame.
Required Arguments:
- dataframe: Specifies an input teradataml DataFrame which acts as the input query for the API_Request in-database function.
- See list of additional required arguments and corresponding parameters in the in-database function API_Request in the following table.
Optional Arguments:
- options: Specifies key-value arguments to be passed to the in-database function API_Request. See list of these key-value arguments in the following table.
This table shows the mapping between TDApiClient.API_Request arguments to the corresponding parameters in the in-database function API_Request. For details of these parameters, see API_Request In-database Function Syntax Elements.
TDApiClient.API_Request Argument | Required or Optional | API_Request in-database function Parameter |
---|---|---|
api_type | Required | API_TYPE |
authorization | Required | AUTHORIZATION |
endpoint | Optional | ENDPOINT |
number_embeddings | Optional | NUM_EMBEDDINGS |
model_name | Optional | MODEL_NAME |
text_column | Optional | TEXT_COLUMN |
Example Prerequisites
To run the following examples, load necessary package first.
from tdapiclient import TDApiClient from teradataml import DataFrame
Example 1: Use TDApiClient.API_Request with OpenAI
auth_info_fmt_str = ('{{ "key": "{}" }}') auth_info = auth_info_fmt_str.format("open-ai-key")
embeddings_df = TDApiClient.API_Request(DataFrame("product_reviews"), "open-ai-embedding", authorization=auth_info, num_embeddings='1576', model_name='text-embedding-ada-002', text_column="comment")
Example 2: Use TDApiClient.API_Request with Azure OpenAI using endpoint URL
auth_info_fmt_str = ('{{ "Key": "{}" }}') auth_info = auth_info_fmt_str.format("az-ai-key")
az_embeddings_df = TDApiClient.API_Request(DataFrame("product_reviews"), "az-ai-embedding", authorization=auth_info, endpoint='https://test-azure-open-ai-instance.openai.azure.com/openai/deployments/embedding-ada/embeddings?api-version=2023-05-15', num_embeddings='1576', model_name='text-embedding-ada-002', text_column="comment")
Example 3: Use TDApiClient.API_Request with Azure OpenAI using resource and deployment parameters
auth_info_fmt_str = ('{{ "Key": "{}", "Resource" : "{}", "Deployment" : "{}" }}') auth_info = auth_info_fmt_str.format("az-ai-key", "az_resource_name", "az_deployment_name")
az_embeddings_df = TDApiClient.API_Request(DataFrame("product_reviews"), "az-ai-embedding", authorization=auth_info, num_embeddings='1576', model_name='text-embedding-ada-002', text_column="comment")