Skip to content

How to create an app in Snowpark Container Services

Public preview

This page outlines the steps that are required to build a Docker image that can be deployed into Snowpark Container Services and used with the Data Productivity Cloud Snowpark Container Prompt component.


Prerequisites

Review the Snowflake prerequisites to confirm you meet the requirements for creating an app.


Instructions

  1. You may wish to set up a security integration and make sure that the role you use to set up the Snowpark Container Services app has the BIND SERVICE ENDPOINT PERMISSION. For example:

    CREATE SECURITY INTEGRATION IF NOT EXISTS snowservices_ingress_oauth
      TYPE=oauth
      OAUTH_CLIENT=snowservices_ingress
      ENABLED=true;
    GRANT BIND SERVICE ENDPOINT ON ACCOUNT TO ROLE test_role;
    
  2. Create a Snowflake compute pool (if not created). This is the pool of virtual machine nodes on which your service will run.

    CREATE COMPUTE POOL tutorial_compute_pool
      MIN_NODES = 1
      MAX_NODES = 1
      INSTANCE_FAMILY = CPU_X64_XS;
    
  3. Check your compute pool is running:

    DESCRIBE COMPUTE POOL tutorial_compute_pool;
    
  4. Create a Snowflake stage to store your service specification files:

    CREATE STAGE IF NOT EXISTS tutorial_stage
      DIRECTORY = ( ENABLE = true );
    
  5. Create an image repository on your snowflake account. This is where you push images to, and where Snowflake will pull images from:

    CREATE IMAGE REPOSITORY IF NOT EXISTS tutorial_repository
    

The Snowpark Container Prompt component generates a user-defined function (UDF) at runtime with the signature.

udf(systemPrompt VARCHAR, userPrompt VARCHAR, inputValues VARIANT, metadata VARIANT)

inputValues is a JSON object containing the { columnName: columnValue } of all of your inputs selected in the component. Metadata is also a JSON object, containing any key:value pairs specified in the metadata parameters.

The UDF is invoked by the Snowpark Container Prompt component and translated into JSON, which is what your app will receive. This looks as below:

{
    "data": [
                [0, "System Prompt", "User Prompt", {"Input Column Name": "Input Column Value"}, {"metadata key": "metadata value"}]
    ]
}

Your service response must look like this:

{
    "data": [
      [0, "completion result"]
    ]
}

Note

If the Output Format parameter in the Snowpark Container Prompt component is set to JSON, your service must respond with valid JSON, otherwise your output rows will all error.


Build and deploy your Docker image

Note

In the code blocks below, my_service is an example service name. Replace it with your own service name.

  1. Build and push a Docker image to the repo:

    docker build --rm --platform linux/amd64 -t <repository_url>/my_service_image:latest
    docker login <registry_hostname> -u <username>
    docker push <repository_url>/<image_name>
    
    e.g docker push myorg-myacct.registry.snowflakecomputing.com/tutorial_db/data_schema/tutorial_repository/my_service_image:latest
    

    Note

    Your service will be selectable in the Snowpark Container Prompt component within the Service property.

  2. Create your Snowpark Container Services service:

     CREATE SERVICE my_service
      IN COMPUTE POOL tutorial_compute_pool
      FROM SPECIFICATION $$
        spec:
          containers:
          - name: echo
            image: /tutorial_db/data_schema/tutorial_repository/my_service:latest
            env:
              SERVER_PORT: 8000
            readinessProbe:
              port: 8000
              path: /healthcheck
          endpoints:
          - name: echoendpoint
            port: 8000
            public: true
          $$
       MIN_INSTANCES=1
       MAX_INSTANCES=1;
    

    Note

    Your endpoint will be selectable in the Snowpark Container Prompt component within the Endpoint property.

  3. Check service details:

    SELECT SYSTEM$GET_SERVICE_STATUS('my_service');
    
    DESCRIBE SERVICE my_service;