パイプラインで使用するカスタム・コンポーネントの作成

Orchestration Pipelines カスタム・コンポーネントは、あなたが書き込んだスクリプトを実行します。 カスタム・コンポーネントを使用して、パイプライン間で再使用可能スクリプトを共有できます。

カスタム・コンポーネントは、プロジェクト・ 資産 として作成します。 その後、そのプロジェクトで作成するパイプラインでコンポーネントを使用できます。 パイプライン用のカスタム・コンポーネントは、必要な数だけ作成できます。 現在は、 Python 関数を使用して、カスタム・コンポーネントをプログラマチックに作成する必要があります。

プロジェクト 資産 としてのコンポーネントの作成

カスタム・コンポーネントを作成するには、Python クライアントを使用して IBM Orchestration Pipelinesで認証し、コンポーネントをコーディングしてから、指定したプロジェクトにコンポーネントを公開します。 プロジェクトで使用可能になったら、パイプライン内のノードにコンポーネントを割り当てて、パイプライン・フローの一部として実行できます。

この例では、 2 つの数値を加算してから、そのコンポーネントをパイプライン・ノードに割り当てるプロセスを示します。

  1. Python クライアントを使用して、関数をコンポーネントとして公開します。 プロジェクトの Jupyter Notebook で以下のコードを実行します。

    # Install libraries
    ! pip install ibm-orchestration-pipelines
    
    # Authentication
    from ibm_orchestration_pipelines import OrchestrationPipelines
    
    apikey = ''
    service_url = 'your_host_url'
    project_id = 'your_project_id'
    username = ''
    
    client = OrchestrationPipelines(apikey, url=service_url, username=username)
    
    
    # Define the function of the component
    
    # If you define the input parameters, users are required to 
    # input them in the UI
    
    def add_two_numbers(a: int, b: int) -> int:
        print('Adding numbers: {} + {}.'.format(a, b))
        return a + b + 10
    
    # Other possible functions might be sending a Slack message,
    # or listing directories in a storage volume, and so on.
    
    # Publish the component    
    client.publish_component(
        name='Add numbers', # Appears in UI as component name 
        func=add_two_numbers,
        description='Custom component adding numbers', # Appears in UI as component description 
        project_id=project_id,
        overwrite=True, # Overwrites an existing component with the same name 
    )
    

    新しい API キーを生成するには、以下のようにします。

    1. バナーでプロファイルをクリックします
    2. 「 API キー」>「新規キーの生成」をクリックします。
  2. Run Pipelines コンポーネント というノードを Run の下のキャンバスにドラッグします。
    カスタム・コンポーネント・ノードの取得

  3. 使用するコンポーネントの名前を選択します。
    実際のコンポーネント機能の選択

  4. パイプライン・ ジョブ の一部としてノードに接続して実行します。
    コンポーネントの接続

パイプライン・コンポーネントの管理

これらの Python クライアント・メソッドを使用して、カスタム・パイプライン・コンポーネントを管理します。

表 1. パイプライン・コンポーネントの管理
メソッド 機能
client.get_components(project_id=project_id) プロジェクトからのコンポーネントのリスト
client.get_component(project_id=project_id, component_id=component_id) ID によるコンポーネントの取得
client.get_component(project_id=project_id, name=component_name) 名前によるコンポーネントの取得
client.publish_component(component name) 新規コンポーネントの公開
client.delete_component(project_id=project_id, component_id=component_id) ID によるコンポーネントの削除