Interacting with Ontology from Compute Module

Context

I’ve developed an app that processes a video file with an ML model. I’ve pushed the image to Foundry and created a compute module from it.

The compute module was developed as a “Functions module” with “Application permissions” and a 3rd party application and service user were created that I’ve given permission to the relevant project and submission criteria in relevant action types.

Challenge

My challenge is interacting with the Ontology from the Compute Module, especially regarding reading a video file in an Object (property: input_video), passing that into the running compute Module and then returning a video to be saved in the output_video property.

I want to assume the automatically created 3rd Party should allow me to interact with the Ontology but it’s not particularly via an OSDK so I don’t have the benefit of communicating with the Ontology like with a typical OSDK application.

Do I create a dedicated OSDK app and use the service account created from there or do I rely on the service user created from the Compute Module

If you want to use the Ontology SDK in a compute module you can change the created 3rd Party application for one you have already created with an osdk in your developer console. Here are the in platform docs describing how to do so:

Create the application and generate an OSDK

  1. Navigate to Developer Console and create a new application.

  2. Choose to also generate an OSDK. Then, add your Ontology objects.

  3. Select the Python SDK language option.

  4. Select the Backend service application type.

  5. Under Data permissions, select Application’s permissions.

Grant access to the application service user

The client ID generated in your Developer Console application must have access to the added Ontology resources to allow the OSDK to access them. To do this, navigate to the OAuth & Scopes tab and select Check access in the Resource access scope section. Here, can view your current access status or navigate to resources to manage access. In the Security tab of the given resource, search for the client ID of your application, then add that user.

Create and add a source to your compute module

By default, egress is disabled for all compute modules. To use the OSDK from a compute module, you must first set up a source for the hostname that you will pass into the OSDK. (Compute modules in platform docs contains how to add a source)

Configure application permissions

After creating a source for the hostname, you can configure permissions for your OSDK application:

  1. From the Configure tab of your compute module, scroll to the top of the page and select Application permissions

  2. Select Use other app credentials

  3. In the dialog that appears, enter the client ID and secret you received in Developer Console. Select Apply, then save your configuration changes.

You can now access the client ID/secret of your application user from within your compute module:

from compute_modules.auth import retrieve_third_party_id_and_creds

client_id, client_secret = retrieve_third_party_id_and_creds()

Build your Docker image

In the Start developing tab of your Developer Console application, you will find a command similar to the one below to install your OSDK library with pip:

pip install pokemon_app_sdk  --upgrade \
    --extra-index-url "https://user:$FOUNDRY_TOKEN@stack.palantirfoundry.com/artifacts/api/repositories/ri.artifacts.main.repository.8d6eacb5-058c-47c7-a601-cf38cf76de8f/contents/release/pypi/simple" \
    --extra-index-url "https://user:$FOUNDRY_TOKEN@stack.palantirfoundry.com/artifacts/api/repositories/ri.foundry-sdk-asset-bundle.main.artifacts.repository/contents/release/pypi/simple"

You can use this same command to build a Docker image with that dependency by adding an ARG to your Dockerfile.

For example, below is a working requirements.txt and corresponding Dockerfile

pokemon_app_sdk
foundry-compute-modules>=0.9.0
FROM --platform=linux/amd64 python:3.12

ARG FOUNDRY_TOKEN

COPY requirements.txt .
RUN pip install -r requirements.txt --upgrade \
    --extra-index-url "https://user:$FOUNDRY_TOKEN@stack.palantirfoundry.com/artifacts/api/repositories/ri.artifacts.main.repository.8d6eacb5-058c-47c7-a601-cf38cf76de8f/contents/release/pypi/simple" \
    --extra-index-url "https://user:$FOUNDRY_TOKEN@stack.palantirfoundry.com/artifacts/api/repositories/ri.foundry-sdk-asset-bundle.main.artifacts.repository/contents/release/pypi/simple"

COPY src .
USER 5000
ENTRYPOINT ["python", "app.py"]

Then, pass your Docker image by passing your FOUNDRY_TOKEN using --build-arg:

FOUNDRY_TOKEN=<your-foundry-token>

docker build --build-arg FOUNDRY_TOKEN=$FOUNDRY_TOKEN -t stack-container-registry.palantirfoundry.com/your-compute-module:0.0.1 .

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.