API_Request In-database Function Usage | OpenAI or Azure OpenAI | Teradata - API_Request In-database Function Usage - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
ft:locale
en-US
ft:lastEdition
2024-12-11
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

Usage Considerations

Before using the API_Request in-database function, you should:
  • Know the name of the OpenAI model or Azure OpenAI endpoint, and Teradata text column to use;
  • Have credentials which has permissions on OpenAI or Azure OpenAI to use this in-database function.

Usage Example 1: Use API_Request in-database function with OpenAI

SELECT * from tapidb.API_Request
(
    on (select * from alice.string_input_table )
    USING AUTHORIZATION('{"Key":"OPEN_AI_KEY"}')
    API_TYPE('open-ai-embedding')
    TEXT_COLUMN('text')
) as "DT";

 *** Query completed. One row found. 1538 columns returned.
 *** Warning: 3705 Request executed in interpretive EVL mode.
 *** Total elapsed time was 7 seconds.

 *** Warning: Report has more than 100 column(s).
              Only the first 100 column(s) will be displayed.

id          text           embeddings_0     embeddings_1       .....
----------- ------------- -------------- --------------- 
1           Test message      -0.423563         0.23566

Example 2: Use API_Request in-database function with Azure OpenAI using ENDPOINT parameter

SELECT * from tapidb.API_Request
(
    on (select * from alice.string_input_table )
    USING AUTHORIZATION('{"Key":"az_ai_key"}')
    API_TYPE('az-ai-embedding')
    ENDPOINT('https://test-azure-open-ai-instance.openai.azure.com/openai/deployments/embedding-ada/embeddings?api-version=2023-05-15')
    TEXT_COLUMN('text')
) as "DT";
*** Query completed. One row found. 1538 columns returned.
 *** Warning: 3705 Request executed in interpretive EVL mode.
 *** Total elapsed time was 7 seconds.

 *** Warning: Report has more than 100 column(s).
              Only the first 100 column(s) will be displayed.

id          text           embeddings_0     embeddings_1       .....
----------- ------------- -------------- --------------- 
1           Test message      -0.423563         0.23566

Example 3: Use API_Request in-database function with Azure OpenAI using resource and deployment parameters

SELECT * from tapidb.API_Request
(
    on (select * from alice.string_input_table )
    USING AUTHORIZATION('{"Key":"az_ai_key", "Resource" : "test-azure-open-ai-instance", "Deployment" : "embedding-ada"}')
    API_TYPE('az-ai-embedding')
    TEXT_COLUMN('text')
) as "DT";
*** Query completed. One row found. 1538 columns returned.
 *** Warning: 3705 Request executed in interpretive EVL mode.
 *** Total elapsed time was 7 seconds.

 *** Warning: Report has more than 100 column(s).
              Only the first 100 column(s) will be displayed.

id          text           embeddings_0     embeddings_1       .....
----------- ------------- -------------- --------------- 
1           Test message      -0.423563         0.23566