TeradataAI Examples | Teradata Package for Generative AI - Examples: How to use TeradataAI - Teradata VantageCloud Lake

Lake - Analyze Your Data with ClearScape Analytics™

Deployment
VantageCloud
Edition
Lake
Product
Teradata VantageCloud Lake
Release Number
Published
February 2025
ft:locale
en-US
ft:lastEdition
2026-02-20
dita:mapPath
tcl1683670667798.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
tcl1683670667798
To use authorization objects when the "api_type" is set to azure, aws, nim, or gcp during the initialization of TeradataAI, refer to Common Functionality or Rules.

TeradataAI authentication precedence is: authorization object, explicit parameters, configuration file, then environment variables.

Example 1: Instantiate the TeradataAI using model "anthropic.claude-v2"

>>> llm_aws = TeradataAI(api_type = "aws",
                       access_key = "<AWS bedrock access key>",
                       secret_key = "<AWS bedrock secret key>",
                       session_key = "<AWS bedrock session key>",
                       region = "us-west-2",
                       model_name = "anthropic.claude-v2")

Example 2: Instantiate the TeradataAI using model "anthropic.claude-v2” and configuring the relevant environment variables

>>> os.environ["AWS_DEFAULT_REGION"] = "us-west-2"
>>> os.environ["AWS_ACCESS_KEY_ID"] = "<Enter AWS Access Key ID>"
>>> os.environ["AWS_SECRET_ACCESS_KEY"] = "<Enter AWS Secret Key>"
>>> os.environ["AWS_SESSION_TOKEN"] = "<Enter AWS Session key>"
>>> llm_aws = TeradataAI(api_type = "aws",
                  model_name = "anthropic.claude-v2")

Example 3: Instantiate the TeradataAI using model "anthropic.claude-v2" and passing the sensitive information using a ‘.env’ file

>>> llm_aws = TeradataAI(api_type = "aws",
                             model_name = "anthropic.claude-v2",
                             config_file = "<path to .env file>")
        -------------- env file ----------------
        AWS_DEFAULT_REGION = <aws region>
        AWS_ACCESS_KEY_ID = <aws access key>
        AWS_SECRET_ACCESS_KEY = <aws secret key>
        AWS_SESSION_TOKEN = <aws session token>
        ----------------------------------------

Example 4: Instantiate the TeradataAI using model "anthropic.claude-v2" and passing the authorization information to each argument of the function

>>> llm_aws = TeradataAI(api_type = "aws",
                       model_name = "anthropic.claude-v2",
                       authorization = "<authorization object>")

Example 1: Instantiate TeradataAI using model "gpt-3.5-turbo"

>>> llm_azure = TeradataAI(api_type = "azure",
                  api_base = "<https://****.openai.azure.com/>",
                  api_version = "2000-11-35",
                  api_key = <provide your llm API key>,
                  deployment_id = <provide your azure AI engine name>,
                  model_name = "gpt-3.5-turbo")

Example 2: Instantiate TeradataAI using model "gpt-3.5-turbo" and configuring the relevant environment variables

>>> os.environ['AZURE_OPENAI_API_KEY'] = <provide your azure AI API key>
>>> os.environ['AZURE_OPENAI_ENDPOINT'] = <provide your azure AI engine name>
>>> os.environ['AZURE_OPENAI_API_VERSION'] = <provide your azure AI version>
>>> os.environ['AZURE_OPENAI_DEPLOYMENT_ID'] = <provide your azure AI deployment id>
>>> llm_azure = TeradataAI(api_type="azure",
                       model_name="gpt-3.5-turbo"
                       )

Example 3: Instantiate TeradataAI using model "gpt-3.5-turbo" and passing the sensitive information using a ‘.env’ file

>>> llm_azure = TeradataAI(api_type = "azure",
                             model_name = "gpt-3.5-turbo",
                             config_file = "<path to .env file>")
        -------------- env file ----------------
        AZURE_OPENAI_API_KEY = <azure AI API key>
        AZURE_OPENAI_ENDPOINT = <https://****.openai.azure.com/>
        AZURE_OPENAI_API_VERSION = 2000-11-35
        AZURE_OPENAI_DEPLOYMENT_ID = <azure AI engine name>
        ----------------------------------------

Example 4: Instantiate TeradataAI using model "gpt-3.5-turbo" and passing the authorization information to each argument of the function

>>> llm_azure = TeradataAI(api_type = "azure",
                       model_name = "gpt-3.5-turbo",
                       authorization = "<authorization object>"

Example 1: Instantiate TeradataAI using model "gemini-1.5-pro-001"

>>> llm_gcp = TeradataAI(api_type = "gcp",
                  project = "<GCP project name>",
                  model_name = "gemini-1.5-pro-001",
                  region = "us-central1",
                  enable_safety = True,
                  access_token = "<GCP ACCESS TOKEN>",
                  model_args = {"temperature": 1,
                                "top_p": 0.95}
                  )

Example 2: Instantiate TeradataAI using model "gemini-1.5-pro-001" and configuring the relevant environment variables

>>> os.environ['GOOGLE_CLOUD_PROJECT'] = <GCP project name>
>>> os.environ['GOOGLE_CLOUD_REGION'] = <GCP cloud region>
>>> os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = <GCP access token>
>>> llm_gcp = TeradataAI(api_type="gcp",
                       model_name="gemini-1.5-pro-001"
                       )

Example 3: Instantiate TeradataAI using model "gemini-1.5-pro-001" and passing the sensitive information using a ‘.env’ file

>>> llm_gcp = TeradataAI(api_type = "gcp",
                             model_name = "gemini-1.5-pro-001",
                             config_file = "<path to .env file>
        -------------- env file ----------------
        GOOGLE_CLOUD_PROJECT = <GCP project name>
        GOOGLE_CLOUD_REGION = 'us-central1'
        GOOGLE_APPLICATION_CREDENTIALS = <GCP access token>
        ----------------------------------------

Example 4: Instantiate TeradataAI using model "gemini-1.5-pro-001" and passing the authorization information to each argument of the function

>>> llm_gcp = TeradataAI(api_type = "gcp",
                       model_name = "gemini-1.5-pro-001",
                       authorization = "<authorization object>"

Example 1: Instantiate TeradataAI using model "sentence-transformers/all-MiniLM-L6-v2" and default environment

>>> model_name = 'sentence-transformers/all-MiniLM-L6-v2'
>>> model_args = {'transformer_class': 'AutoModelForTokenClassification', 'task' : 'token-classification'}
>>> llm_hf = TeradataAI(api_type = "hugging_face",
         model_name = model_name,
         model_args = model_args)

Example 2 : Instantiate TeradataAI using model "lakshyakh93/deberta_finetuned_pii" and configuring the “ues_args” to provide a custom environment

>>> model_name = 'lakshyakh93/deberta_finetuned_pii'
>>> model_args = {'transformer_class': 'AutoModelForTokenClassification', 'task' : 'token-classification'}
# Using an existing user environment 'demo'.         
>>> ues_args = {'env_name': 'demo'}
>>> llm = TeradataAI(api_type = "hugging_face",
                             model_name = model_name,
                             model_args = model_args,
                             ues_args = ues_args)
NVIDIA NIM
Example 1 : Instantiate the TeradataAI using model "meta/llama-3.1-8b-instruct"
>>> llm_nim = TeradataAI(api_type = "nim",
                     api_key = "<nim api key>"
                     api_base = "<nim base url>",
                      model_name = "meta/llama-3.1-8b-instruct")

Example 2: Instantiate the TeradataAI using model "meta/llama-3.1-8b-instruct" and configuring the relevant environment variables

>>> import os
>>> os.environ["NVIDIA_API_KEY"] = "<NVIDIA NIM API key>"
>>> llm_nim = TeradataAI(api_type = "nim",
                     api_base = "<nim base url>",
                      model_name = "meta/llama-3.1-8b-instruct")

Example 3: Instantiate the TeradataAI using model "meta/llama-3.1-8b-instruct" and passing the sensitive information using a ‘.env’ file

        -------------- env file ----------------
        "NVIDIA_API_KEY" = "<NVIDIA NIM API key>"
        ----------------------------------------
llm = TeradataAI(api_type = "nim",
                 api_base = "<nim base url>",
                  model_name = "meta/llama-3.1-8b-instruct")

Example 4: Instantiate the TeradataAI using model "meta/llama-3.1-8b-instruct" and passing the authorization information to each argument of the function

Set up the environment variable to work with the NVIDIA NIM model.

>>> import os
>>> os.environ["NVIDIA_API_KEY"] = "<NVIDIA NIM API key>"
>>> llm = TeradataAI(api_type = "nim",
                     api_base = "<nim base url>",
                     model_name = "meta/llama-3.1-8b-instruct")
ONNX

Create an LLM endpoint for "api_type" = 'onnx' for the ONNX model "bge-small-en-v1.5" with "model_id" as 'td-bge-small' that does not yet exist in the database and is to be stored in table with "table_name" as 'onnx_models'.

>>> from teradatagenai import TeradataAI
>>> llm = TeradataAI(api_type = "onnx",
                     model_name = "bge-small-en-v1.5",
                     model_id = "td-bge-small",
                     model_path = "/path/to/onnx/model",
                     tokenizer_path = "/path/to/onnx/tokenizer,
                     table_name = "onnx_models")

Example 1: Create LLM endpoint for "api_type" = 'onnx' for the ONNX model "bge-small-en-v1.5" with "model_id" as 'td-bge-small' that does not yet exist in the database and is to be stored in default table

>>> from teradatagenai import TeradataAI
>>> llm = TeradataAI(api_type = "onnx",
                     model_name = "bge-small-en-v1.5",
                     model_id = "td-bge-small",
                     model_path = "/path/to/onnx/model",
                     tokenizer_path = "/path/to/onnx/tokenizer)

Example 2: Create LLM endpoint for "api_type" as 'onnx' for the ONNX model "bge-m3" with "model_id" as 'td-bge-m3' already stored in the table 'onnx_models'

>>> from teradatagenai import TeradataAI
>>> llm = TeradataAI(api_type = "onnx",
                     model_name = "bge-m3",
                     model_id = "td-bge-m3",
                     table_name = "onnx_models")

Example 3: Create LLM endpoint for "api_type" as 'onnx' for the ONNX model "bge-m3" with "model_id" as 'td-bge-m3' already stored in the default table

>>> from teradatagenai import TeradataAI
>>> llm = TeradataAI(api_type = "onnx",
                     model_name = "bge-m3",
                     model_id = "td-bge-m3")