class_docstr: Twelve Labs API handler implementation.
class_docstr_tok: ["Twelve","Labs","API","handler","implementation","."]
docstr: Creates a model for for interacting with the Twelve Labs API. This method is called when creating a new model.
  The following steps are performed:
      1. Create an index if it doesn't exist already.
      2. Create video indexing tasks for all video files or video urls.
      3. Poll for video indexing tasks to complete.
  
  Parameters
  ----------
  target : str
      Name of the target column.
  
  df : pd.DataFrame, Optional
      DataFrame containing the data to be used in creating the model. This can include the columns containing video urls or video files.
  
  args : Dict, Optional
      Arguments from the USING clause.
docstr_tok: ["Creates","a","model","for","for","interacting","with","the","Twelve","Labs","API",".","This","method","is","called","when","creating","a","new","model",".","The","following","steps","are","performed",":","1",".","Create","an","index","if","it","does","n't","exist","already",".","2",".","Create","video","indexing","tasks","for","all","video","files","or","video","urls",".","3",".","Poll","for","video","indexing","tasks","to","complete",".","Parameters","--","--","--","--","--","target",":","str","Name","of","the","target","column",".","df",":","pd.DataFrame",",","Optional","DataFrame","containing","the","data","to","be","used","in","creating","the","model",".","This","can","include","the","columns","containing","video","urls","or","video","files",".","args",":","Dict",",","Optional","Arguments","from","the","USING","clause","."]
code: def create(
      self,
      target: str,
      df: Optional[pd.DataFrame] = None,
      args: Optional[Dict] = None,
  ) -> None:
      """
      Creates a model for for interacting with the Twelve Labs API. This method is called when creating a new model.
      The following steps are performed:
          1. Create an index if it doesn't exist already.
          2. Create video indexing tasks for all video files or video urls.
          3. Poll for video indexing tasks to complete.
  
      Parameters
      ----------
      target : str
          Name of the target column.
  
      df : pd.DataFrame, Optional
          DataFrame containing the data to be used in creating the model. This can include the columns containing video urls or video files.
  
      args : Dict, Optional
          Arguments from the USING clause.
      """
  
      # get USING args and add target
      args = args["using"]
      args["target"] = target
  
      # get api key
      api_key = get_api_key(
          api_name=self.name,
          create_args=args,
          engine_storage=self.engine_storage,
      )
  
      # initialize TwelveLabsAPIClient
      twelve_labs_api_client = TwelveLabsAPIClient(api_key=api_key)
  
      # update args with api key
      args["api_key"] = api_key
  
      # get index if it exists
      index_id = twelve_labs_api_client.get_index_by_name(
          index_name=args["index_name"]
      )
  
      # create index if it doesn't exist
      if not index_id:
          logger.info(
              f"Index {args['index_name']} does not exist. Creating index."
          )
          index_id = twelve_labs_api_client.create_index(
              index_name=args["index_name"],
              engine_id=args["engine_id"]
              if "engine_id" in args
              else None,
              index_options=args["index_options"],
              addons=args["addons"] if "addons" in args else [],
          )
  
      else:
          logger.info(
              f"Index {args['index_name']} already exists. Using existing index."
          )
  
      # store index_id in args
      args["index_id"] = index_id
  
      # initialize video_urls and video_files
      video_urls, video_files = None, None
  
      # create video indexing tasks for all video files or video urls
      # video urls will be given precedence
      # check if video_urls_column has been set and use it to get the video urls
      if "video_urls_column" in args:
          logger.info(
              "video_urls_column has been set, therefore, it will be given precedence."
          )
          video_urls = df[args["video_urls_column"]].tolist()
  
      # else, check if video_files_column has been set and use it to get the video files
      elif "video_files_column" in args:
          logger.info(
              "video_urls_column has not been set, therefore, video_files_column will be used."
          )
          video_files = df[args["video_files_column"]].tolist()
  
      # else, check if video_urls or video_files have been set and use them
      else:
          logger.info(
              "video_urls_column and video_files_column have not been set, therefore, video_urls and video_files will be used."
          )
          video_urls = (
              args["video_urls"] if "video_urls" in args else None
          )
          video_files = (
              args["video_files"] if "video_files" in args else None
          )
  
      # if video_urls and video_files are not set, then raise an exception
      if not video_urls and not video_files:
          logger.error(
              "Neither video_urls_column, video_files_column, video_urls nor video_files have been set."
          )
          raise RuntimeError(
              "Neither video_urls_column, video_files_column, video_urls nor video_files have been set. Please set one of them."
          )
  
      task_ids = twelve_labs_api_client.create_video_indexing_tasks(
          index_id=index_id,
          video_urls=video_urls,
          video_files=video_files,
      )
  
      # poll for video indexing tasks to complete
      twelve_labs_api_client.poll_for_video_indexing_tasks(
          task_ids=task_ids
      )
  
      # store args in model_storage
      self.model_storage.json_set("args", args)
  
file_path: mindsdb/mindsdb/integrations/handlers/twelve_labs_handler/twelve_labs_handler.py
imports: import pandas
  from typing import Optional, Dict
  from mindsdb.utilities import log
  from mindsdb.integrations.libs.base import BaseMLEngine
  from mindsdb.integrations.utilities.handler_utils import get_api_key
  from mindsdb.integrations.libs.api_handler_exceptions import MissingConnectionParams
  from mindsdb.integrations.handlers.twelve_labs_handler.settings import TwelveLabsHandlerModel
  from mindsdb.integrations.handlers.twelve_labs_handler.twelve_labs_api_client import TwelveLabsAPIClient
label_desc: Use image node_id 3 for calling the TwelveLabsHandler obj's underlying member method code with example usage: obj.create(target, df, args) without return types