### Install Traceloop SDK via pip Source: https://docs.truefoundry.com/docs/tracing/tracing-getting-started This command installs the Traceloop SDK, which is necessary for integrating tracing capabilities into your application, using the Python package installer pip. ```bash pip install traceloop-sdk ``` -------------------------------- ### Install TrueFoundry CLI Source: https://docs.truefoundry.com/docs/setup-cli Installs the TrueFoundry CLI library, enabling interaction with deployments and experiment tracking. Requires Python >= 3.8. ```bash pip install -U "truefoundry" ``` -------------------------------- ### Configure Python Build for Service Deployment Source: https://docs.truefoundry.com/docs/deploy-first-service This section explains how to configure the `PythonBuild` class within the `Build` specification. It details setting the `command` to start the service (e.g., `uvicorn app:app --port 8000 --host 0.0.0.0`) and specifying the `requirements_path` for dependencies (e.g., `requirements.txt`). This defines how the Python application is built and executed. ```Python service = Service( name="fastapi", image=Build( build_spec=PythonBuild( command="uvicorn app:app --port 8000 --host 0.0.0.0", requirements_path="requirements.txt", ) ), ports=[ Port( port=8000, host=args.host, ) ], resources=Resources( cpu_request=0.2, cpu_limit=0.5, memory_request=200, memory_limit=500, ephemeral_storage_request=1000, ephemeral_storage_limit=2000 ), env={ "UVICORN_WEB_CONCURRENCY": "1", "ENVIRONMENT": "dev" } ) ``` -------------------------------- ### Install TrueFoundry CLI with Workflow Support Source: https://docs.truefoundry.com/docs/setup-cli Installs the TrueFoundry CLI with additional support for Workflows. This extra requires Python >= 3.9 and < 3.13. ```bash pip install -U "truefoundry[workflow]" ``` -------------------------------- ### Deploy TrueFoundry Service using Python SDK Source: https://docs.truefoundry.com/docs/deploy-first-service This Python snippet shows how to initiate the deployment of a TrueFoundry service. The `service.deploy()` method is called with the `workspace_fqn` parameter, which specifies the target workspace for the deployment. ```python service.deploy(workspace_fqn=args.workspace_fqn) ``` -------------------------------- ### Import ServiceFoundry Modules and Configure Logging Source: https://docs.truefoundry.com/docs/deploy-first-service This Python snippet shows the necessary imports for using `servicefoundry` classes like `Build`, `PythonBuild`, `Service`, `Resources`, and `Port`. It also sets up basic logging configuration to display `servicefoundry` logs at the `INFO` level. ```Python import argparse import logging from servicefoundry import Build, PythonBuild, Service, Resources, Port logging.basicConfig(level=logging.INFO) ``` -------------------------------- ### Run TrueFoundry Deployment Script Source: https://docs.truefoundry.com/docs/deploy-first-service This shell command executes the `deploy.py` script, which typically contains the TrueFoundry service definition and deployment logic. It's used to trigger the deployment process from the command line. ```Shell python deploy.py ``` -------------------------------- ### Configure Service Resources and Deploy to TrueFoundry Source: https://docs.truefoundry.com/docs/deploy-first-service This Python snippet demonstrates how to define resource constraints (CPU, memory, ephemeral storage), environment variables for a TrueFoundry service, and then deploy the configured service to a specified workspace. It highlights setting host, resource requests/limits, and common environment variables. ```Python ports=[ Port( port=8000, # Define the host for the service, to learn how to set this view the above callout host="your-service-your-workspace-8000.your-organization.ai", ) ], # Define the resource constraints. # # Requests are the minimum amount of resources that a container needs to run. # Limits are the maximum amount of resources that a container can use. # # If a container tries to use more resources than its limits, it will be throttled or killed. resources=Resources( # CPU is specified as a number. 1 CPU unit is equivalent to 1 physical CPU core, or 1 virtual core. cpu_request=0.2, cpu_limit=0.5, # Memory is defined as an integer and the unit is Megabytes. memory_request=200, memory_limit=500, # Ephemeral storage is defined as an integer and the unit is Megabytes. ephemeral_storage_request=1000, ephemeral_storage_limit=2000, ), # Define environment variables that your Service will have access to env={ "UVICORN_WEB_CONCURRENCY": "1", "ENVIRONMENT": "dev" } ) # Deploy the service to the specified workspace, copy workspace FQN using the following guide # https://docs.truefoundry.com/docs/key-concepts#creating-a-workspace service.deploy(workspace_fqn="your-workspace-fqn") ``` -------------------------------- ### Configure TrueFoundry Deployment from GitHub Source: https://docs.truefoundry.com/docs/deploy-first-service Defines the essential configuration parameters required for deploying a service directly from a GitHub repository using the TrueFoundry platform's web interface. This includes specifying the repository URL, the path to the build context within the repository, the command to execute the application, and the port on which the service will listen. ```Configuration Repo URL: https://github.com/truefoundry/getting-started-examples Path to build context: ./deploy-model-with-fastapi/ Command: uvicorn app:app --host 0.0.0.0 --port 8000 Port: 8000 ``` -------------------------------- ### Install Python OpenTelemetry and Dotenv Packages Source: https://docs.truefoundry.com/docs/tracing/tracing-python-opentelemetry Install the necessary Python packages for OpenTelemetry API, SDK, OTLP HTTP exporter, and dotenv for environment variable loading. ```sh pip install opentelemetry-api opentelemetry-sdk opentelemetry-exporter-otlp-proto-http python-dotenv ``` -------------------------------- ### Install TrueFoundry ML SDK and Authenticate CLI Source: https://docs.truefoundry.com/docs/deploying-an-llm-model-from-the-model-catalogue Instructions to install the `truefoundry[ml]` Python SDK and log in to the TrueFoundry platform using the command-line interface (CLI). This setup is required before interacting with the Model Registry programmatically. ```Shell pip install -U truefoundry[ml] tfy login --host ``` -------------------------------- ### Specify Docker Image Build Configuration for Python Source: https://docs.truefoundry.com/docs/deploy-first-service This Python snippet illustrates how to configure the Docker image build process within a `Service` definition using the `Build` and `PythonBuild` classes. It demonstrates setting the `command` to run the application and specifying the `requirements_path` for Python dependencies. ```Python service = Service( name="fastapi", image=Build( build_spec=PythonBuild( command="uvicorn app:app --port 8000 --host 0.0.0.0", requirements_path="requirements.txt", ) ), ports=[ Port( port=8000, host=args.host, ) ], resources=Resources( cpu_request=0.2, ``` -------------------------------- ### Execute Local TrueFoundry Deployment Script Source: https://docs.truefoundry.com/docs/deploy-first-service Provides the command-line instruction to initiate the service deployment process from a local machine. This command executes the `deploy.py` script, which contains the service configuration, and should be run from the project's root directory where the `deploy.py` file resides. ```Bash python deploy.py ``` -------------------------------- ### Project Directory Structure Source: https://docs.truefoundry.com/docs/deploy-first-service This snippet illustrates the file organization of the FastAPI service for the Iris classification problem, showing the main application file, the trained model, and the dependency list. ```plaintext . ├── app.py - Contains FastAPI code for inference. ├── iris_classifier.joblib - The model file. └── requirements.txt - Lists dependencies. ``` -------------------------------- ### Initialize Traceloop SDK and Integrate OpenAI Chat Completion Source: https://docs.truefoundry.com/docs/tracing/tracing-getting-started This comprehensive Python code snippet demonstrates how to initialize the Traceloop SDK with TrueFoundry API key and tracing project details, and then integrate it with an OpenAI chat completion call. It shows how to set up environment variables for the API key and how to stream responses from the OpenAI model while Traceloop automatically captures the traces. ```Python import os from traceloop.sdk import Traceloop from openai import OpenAI # This is the code snipped that we copied in the previous step # Replace this with the code snippet you copied TFY_API_KEY = os.environ.get("TFY_API_KEY") Traceloop.init( api_endpoint="https://platform.live-demo.truefoundry.cloud/api/otel", headers = { "Authorization": f"Bearer {TFY_API_KEY}", "TFY-Tracing-Project": "tracing-project:live-demo/tracing/agno-plot-agent", }, ) client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY")) stream = client.chat.completions.create( messages = [ {"role": "system", "content": "You are an AI bot."}, {"role": "user", "content": "Enter your prompt here"}, ], model= "openai-main/gpt-4o", stream=True, temperature=0.7, max_tokens=256, top_p=0.8, frequency_penalty=0, presence_penalty=0, stop=[""], ) for chunk in stream: if chunk.choices and len(chunk.choices) > 0 and chunk.choices[0].delta.content is not None: print(chunk.choices[0].delta.content, end="") ``` -------------------------------- ### Define TrueFoundry Service with Python `deploy.py` Script Source: https://docs.truefoundry.com/docs/deploy-first-service A partial Python code snippet from the `deploy.py` script demonstrating how to programmatically define and configure a TrueFoundry service. It showcases the use of `Service` and `Build` objects from the `truefoundry.deploy` module, specifying the service name, Python build details, the command to run the application, and the path to the requirements file for Docker image creation. ```Python import logging from truefoundry.deploy import Build, PythonBuild, Service, Resources, Port # Set up logging to display informational messages logging.basicConfig(level=logging.INFO) # Create a TrueFoundry **Service** object to configure your service service = Service( # Specify the name of the service name="your-service", # Define how to build your code into a Docker image image=Build( # `PythonBuild` helps specify the details of your Python Code. # These details will be used to templatize a DockerFile to build your Docker Image build_spec=PythonBuild( # Define the command to run the application command="uvicorn app:app --port 8000 --host 0.0.0.0", # Specify the path to requirements file requirements_path="requirements.txt", ) ), # Set the ports your server will listen on ``` -------------------------------- ### Install Python Dependencies for OpenAI OpenTelemetry Tracing Source: https://docs.truefoundry.com/docs/tracing/tracing-python-opentelemetry-openai This command installs all necessary Python packages for instrumenting OpenAI API calls with OpenTelemetry SDK, including the API, SDK, OTLP HTTP exporter, dotenv for environment variables, and the OpenAI client. ```sh pip install opentelemetry-api opentelemetry-sdk opentelemetry-exporter-otlp-proto-http python-dotenv openai ``` -------------------------------- ### Configure Service Resources and Environment Variables Source: https://docs.truefoundry.com/docs/deploy-first-service This snippet demonstrates how to define resource constraints (CPU, memory, ephemeral storage) and set environment variables for a service using the `Resources` and `env` parameters within the `Service` class. It sets limits for CPU, memory, and ephemeral storage, along with environment variables like `UVICORN_WEB_CONCURRENCY` and `ENVIRONMENT`. ```Python service = Service( name="fastapi", image=Build( build_spec=PythonBuild( command="uvicorn app:app --port 8000 --host 0.0.0.0", requirements_path="requirements.txt", ) ), ports=[ Port( port=8000, host=args.host, ) ], resources=Resources( cpu_request=0.2, cpu_limit=0.5, memory_request=200, memory_limit=500, ephemeral_storage_request=1000, ephemeral_storage_limit=2000 ), env={ "UVICORN_WEB_CONCURRENCY": "1", "ENVIRONMENT": "dev" } ) ``` -------------------------------- ### Define FastAPI Service with TrueFoundry SDK and Environment Variables Source: https://docs.truefoundry.com/docs/deploy-first-service This Python snippet demonstrates how to define a `Service` object using the TrueFoundry SDK. It configures the service's image build with a Python environment, sets up port mapping, specifies CPU and memory resource requests and limits, and includes environment variables for runtime configuration. ```python service = Service( name="fastapi", image=Build( build_spec=PythonBuild( command="uvicorn app:app --port 8000 --host 0.0.0.0", requirements_path="requirements.txt", ) ), ports=[ Port( port=8000, host=args.host, ) ], resources=Resources( cpu_request=0.2, cpu_limit=0.5, memory_request=200, memory_limit=500, ephemeral_storage_request=1000, ephemeral_storage_limit=2000 ), env={ "UVICORN_WEB_CONCURRENCY": "1", "ENVIRONMENT": "dev" } ) ``` -------------------------------- ### Local Deployment Project Directory Structure Source: https://docs.truefoundry.com/docs/deploy-first-service Illustrates the recommended file and directory organization for a project intended for deployment from a local machine. It highlights the crucial placement of the `deploy.py` script in the root, alongside application code (`app.py`), dependencies (`requirements.txt`), and any necessary data files like `iris_classifier.joblib`. ```Filesystem . ├── iris_classifier.joblib ├── app.py ├── deploy.py └── requirements.txt ``` -------------------------------- ### Configure Truefoundry Python Task with Various Parameters and Mounts Source: https://docs.truefoundry.com/docs/example-of-task-config-with-different-parameters This example demonstrates a comprehensive `PythonTaskConfig` setup for Truefoundry workflows, including image build specifications (Python version, pip/apt packages), resource allocation (CPU, memory, ephemeral storage, NVIDIA GPU), service account, and different types of mounts like `StringDataMount`. It also shows how to define a task with retries and integrate it into a simple workflow. ```Python from truefoundry.workflow import ( PythonTaskConfig, TaskPythonBuild, task, workflow, ) from truefoundry.deploy import Resources, SecretMount, VolumeMount, StringDataMount, NvidiaGPU task_config = PythonTaskConfig( image=TaskPythonBuild( python_version="3.9", pip_packages=["truefoundry[workflow]==0.4.7rc0"], #To install pip packages from a requirements file uncomment this and provide the path to the requirements file # requirements_path="requirements.txt", apt_packages=[ "git", "ffmpeg", ] ), resources=Resources( cpu_request=0.45, cpu_limit=0.5, memory_request=100, memory_limit=150, ephemeral_storage_request=100, ephemeral_storage_limit=150, devices=[NvidiaGPU(name="T4", count=1)], capacity_type="spot_fallback_on_demand" ), service_account="default", mounts=[ # To use volume mount or secret mount uncomment the following lines and provide the correct values # VolumeMount(mount_path="/tmp/data", volume_fqn="tfy-volume://tfy-usea1-devtest:nikp-wf-test:wf-test"), # SecretMount(mount_path="/tmp/secret", secret_fqn="tfy-secret://truefoundry:test-secret-1730850194619:abctestkey3"), StringDataMount(mount_path="/tmp/stringdata", data="Enter your data here"), ] ) # Task 1: Extract data (simulates loading data from an external source) @task(task_config=task_config, retries=3) def print_string_mount_data() -> str: with open("/tmp/stringdata", "r") as f: data = f.read() print(f"Data: {data}") return data @workflow def simple_workflow() -> str: data = print_string_mount_data() return data if __name__ == "__main__": print(f"data_pipeline(): {simple_workflow()}") ``` -------------------------------- ### Create Tracing Project using TrueFoundry Python SDK Source: https://docs.truefoundry.com/docs/tracing/tracing-getting-started This code snippet demonstrates how to programmatically create or update a tracing project within a TrueFoundry ML Repository using the Python SDK. It requires specifying the ML repository name and the desired tracing project name. The FQN of the created project is printed, which is needed for subsequent tracing steps. ```Python from truefoundry import client from truefoundry_sdk import TracingProjectManifest result = client.tracing_projects.create_or_update( manifest=TracingProjectManifest( ml_repo="{ML_REPO_NAME}", name="{TRACING_PROJECT_NAME}" ) ) print(result.data.fqn) ``` -------------------------------- ### Define Resource Constraints for Service Deployment Source: https://docs.truefoundry.com/docs/deploy-first-service This section details how to apply resource constraints using the `Resources` class, including `cpu_request`, `cpu_limit`, `memory_request`, `memory_limit`, `ephemeral_storage_request`, and `ephemeral_storage_limit`. These parameters control the allocation and utilization of CPU, memory, and temporary storage for the deployed application, preventing resource exhaustion. ```Python service = Service( name="fastapi", image=Build( build_spec=PythonBuild( command="uvicorn app:app --port 8000 --host 0.0.0.0", requirements_path="requirements.txt", ) ), ports=[ Port( port=8000, host=args.host, ) ], resources=Resources( cpu_request=0.2, cpu_limit=0.5, memory_request=200, memory_limit=500, ephemeral_storage_request=1000, ephemeral_storage_limit=2000 ), env={ "UVICORN_WEB_CONCURRENCY": "1", "ENVIRONMENT": "dev" } ) ``` -------------------------------- ### Example `values.yaml` Configuration for TrueFoundry Helm Chart Source: https://docs.truefoundry.com/docs/installing-control-plane-using-helm-chart This YAML snippet provides a template for the `values.yaml` file, which is essential for configuring the TrueFoundry Control Plane Helm chart. It includes placeholders for tenant details, control plane URL, cluster name, database credentials, API keys, and image pull configurations, along with options for dev mode and virtual service settings. ```yaml tenantName: "" # Given by TrueFoundry team controlPlaneURL: "https://domain" # Given by TrueFoundry team clusterName: "" truefoundry: enabled: true devMode: enabled: false # Set to true if you want to test the control plane in dev mode # Virtual service to create virtualservice: enabled: false hosts: ["domain"] gateways: ["istio-system/tfy-wildcard"] database: host: "" name: "" username: "" password: "" tfyApiKey: "" # Given by TrueFoundry team truefoundryImagePullConfigJSON: "" # Given by truefoundry team tfyAgent: enabled: false # kept false as this is used only in compute plane ``` -------------------------------- ### Define Complete TrueFoundry Service for FastAPI Source: https://docs.truefoundry.com/docs/deploy-first-service This Python snippet provides a comprehensive definition of a `Service` object for deploying a FastAPI application. It specifies the service name, defines the Docker image build process using `PythonBuild`, configures network ports, sets resource requests and limits, and includes environment variables. ```Python service = Service( name="fastapi", image=Build( build_spec=PythonBuild( command="uvicorn app:app --port 8000 --host 0.0.0.0", requirements_path="requirements.txt", ) ), ports=[ Port( port=8000, host=args.host, ) ], resources=Resources( cpu_request=0.2, cpu_limit=0.5, memory_request=200, memory_limit=500, ephemeral_storage_request=1000, ephemeral_storage_limit=2000 ), env={ "UVICORN_WEB_CONCURRENCY": "1", "ENVIRONMENT": "dev" } ) ``` -------------------------------- ### Trace Autonomous Agents and Tools with Traceloop @agent and @tool Decorators Source: https://docs.truefoundry.com/docs/tracing/tracing-getting-started This snippet illustrates how to apply Traceloop's `@agent` and `@tool` decorators for tracing autonomous agents and their components. It defines an `@agent` function `translate_joke_to_pirate` and an `@tool` function `history_jokes_tool`, enabling detailed tracing of agent execution and tool interactions. ```Python from openai import OpenAI from traceloop.sdk.decorators import agent, tool client = OpenAI(api_key=os.environ["OPENAI_API_KEY"]) @agent(name="joke_translation") def translate_joke_to_pirate(joke: str): completion = client.chat.completions.create( model="gpt-3.5-turbo", messages=[{"role": "user", "content": f"Translate the below joke to pirate-like english:\n\n{joke}"}], ) history_jokes_tool() return completion.choices[0].message.content @tool(name="history_jokes") def history_jokes_tool(): completion = client.chat.completions.create( model="gpt-3.5-turbo", messages=[{"role": "user", "content": f"get some history jokes"}], ) return completion.choices[0].message.content ``` -------------------------------- ### Kustomize Recommended patches Format Example Source: https://docs.truefoundry.com/docs/kustomize-patch-migration-guide This YAML snippet demonstrates the modern `patches` format, which is the recommended approach in Kustomize v5+. It separates the target resource identification (group, version, kind, name) into a `target` block and the actual modifications into a `patch` block. ```yaml patches: - target: group: apps version: v1 kind: Deployment name: my-service-gv patch: | spec: template: metadata: annotations: prometheus.io/port: "8000" prometheus.io/scrape: "true" ``` -------------------------------- ### Install Persistent Apt Packages in SSH Server Build Script Source: https://docs.truefoundry.com/docs/launch-an-ssh-server This snippet demonstrates how to install `apt` packages persistently on an SSH server by adding them to a 'Build Script'. This ensures that the packages remain installed across notebook restarts, unlike direct installations from the notebook which are not persistent. The example shows installing `ffmpeg`. ```bash sudo apt update sudo apt install ffmpeg ``` -------------------------------- ### Install ArgoCD Helm Chart Source: https://docs.truefoundry.com/docs/generic-control-plane This command installs or upgrades the ArgoCD helm chart into the 'argocd' namespace. It disables applicationSet, notifications, and Dex components, providing a minimal ArgoCD setup required for TrueFoundry. ```Shell helm upgrade --install argocd argocd/argo-cd -n argocd \ --create-namespace \ --version 7.4.4 \ --set applicationSet.enabled=false \ --set notifications.enabled=false \ --set dex.enabled=false ``` -------------------------------- ### Initialize and Track a New ML Run with TrueFoundry Source: https://docs.truefoundry.com/docs/ml-repo-quickstart This code initializes a new machine learning run using the `mlfoundry` client. It creates a run associated with a specified ML repository and assigns it a unique name, making it visible on the TrueFoundry dashboard for tracking. ```Python from truefoundry.ml import get_client client = get_client() run = client.create_run(ml_repo="iris-demo", run_name="svm-model") ``` -------------------------------- ### Clone TrueFoundry Examples Repository Source: https://docs.truefoundry.com/docs/deploy-job-using-python-sdk Clones the `getting-started-examples` GitHub repository, which contains the training script for the Iris model, to your local machine. ```Shell git clone https://github.com/truefoundry/getting-started-examples.git ``` -------------------------------- ### Install CUDA 11.8 and cuDNN 8 in Jupyter Docker Image Source: https://docs.truefoundry.com/docs/launch-notebooks This Dockerfile example shows how to extend a TrueFoundry Jupyter image to include CUDA 11.8 and cuDNN 8. It sets environment variables for CUDA architecture, installs necessary apt packages, adds the CUDA keyring, and then installs the specific CUDA toolkit and cuDNN versions. ```dockerfile FROM truefoundrycloud/jupyter:0.2.20-sudo ENV TORCH_CUDA_ARCH_LIST="7.0 7.5 8.0 8.6 9.0+PTX" ENV DEBIAN_FRONTEND=noninteractive USER root # Install CUDA 11.8 RUN apt update && \ apt install -y --no-install-recommends git curl wget htop && \ wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.1-1_all.deb -O /tmp/cuda-keyring_1.1-1_all.deb && \ dpkg -i /tmp/cuda-keyring_1.1-1_all.deb && \ apt update && \ apt install -y --no-install-recommends cuda-toolkit-11-8 libcudnn8=8.9.7.29-1+cuda11.8 libcudnn8-dev=8.9.7.29-1+cuda11.8 USER jovyan ``` -------------------------------- ### Example TrueFoundry Workflow with Custom Dockerfile Source: https://docs.truefoundry.com/docs/python-function-tasks-with-dockefile A complete example demonstrating a TrueFoundry workflow that uses a custom Dockerfile to install `jq` and a Python task to execute it. This snippet includes both the Dockerfile definition and the Python workflow code. ```Dockerfile # Use an official Python runtime as a parent image FROM python:3.10-slim # Install jq binary RUN apt-get update && apt-get install -y jq # Set the working directory WORKDIR /app RUN pip install truefoundry[workflow]==0.4.8 # Copy the current directory contents into the container COPY . /app # Set the default command to run Python CMD ["python"] ``` ```Python from truefoundry.workflow import task, workflow, PythonTaskConfig, TaskDockerFileBuild from truefoundry.deploy import Resources task_config = PythonTaskConfig( image=TaskDockerFileBuild( dockerfile_path="Dockerfile", ), resources=Resources(cpu_request=0.45) ) @task(task_config=task_config) def run_jq(input_json: str) -> str: import subprocess # Run the jq binary using Python's subprocess module process = subprocess.run( ["jq", "."], # jq command to pretty-print JSON input=input_json, text=True, capture_output=True, ) return process.stdout @workflow def my_workflow(input_json: str) -> str: return run_jq(input_json=input_json) ``` -------------------------------- ### Retrieve Workspace Details by ID (GET /api/svc/v1/workspaces/{id}) Source: https://docs.truefoundry.com/api-reference/workspaces/get-workspace This OpenAPI specification defines the GET endpoint for retrieving details of a specific workspace using its ID. It includes security requirements, path parameters, and detailed response schemas for both successful (200) and error (404) cases, along with examples of the expected data structures. It also defines related component schemas like Collaborator, Permissions, and WorkspaceManifest. ```YAML paths: path: /api/svc/v1/workspaces/{id} method: get servers: - url: https://{controlPlaneURL} variables: controlPlaneURL: type: string description: Control Plane URL default: app.truefoundry.com request: security: - title: jwt parameters: query: {} header: Authorization: type: http scheme: bearer cookie: {} parameters: path: id: schema: - type: string required: true description: Workspace id of the space query: {} header: {} cookie: {} body: {} response: '200': application/json: schemaArray: - type: object properties: data: allOf: - description: Workspace allOf: - $ref: '#/components/schemas/Workspace' refIdentifier: '#/components/schemas/GetWorkspaceResponse' requiredProperties: - data examples: example: value: data: id: fqn: name: tenantName: clusterId: createdBySubject: subjectId: subjectType: user subjectSlug: subjectDisplayName: createdAt: '2023-11-07T05:31:56Z' updatedAt: '2023-11-07T05:31:56Z' environmentId: manifest: type: workspace cluster_fqn: name: environment_name: labels: {} annotations: {} collaborators: - subject: role_id: permissions: - resource_fqn: resource_type: role_id: isSystemWs: true createdBy: description: Returns the workspaces associated with provided workspace id '404': application/json: schemaArray: - type: object properties: statusCode: allOf: - type: integer description: HTTP Status Code message: allOf: - type: string description: Error Message code: allOf: - oneOf: - type: integer - type: string description: Error code details: allOf: - type: array description: Error details items: type: object refIdentifier: '#/components/schemas/HttpError' requiredProperties: - statusCode - message examples: example: value: statusCode: 123 message: code: 123 details: - {} description: Not found. Invalid workspace id deprecated: false type: path components: schemas: Collaborator: type: object required: - subject - role_id properties: subject: description: >- +label=Subject FQN +usage=Fully Qualified Name of the subject. eg: user:email or team:teamname type: string role_id: description: |- +label=Role ID +usage=Role ID for the resource type: string Permissions: type: object required: - resource_fqn - resource_type - role_id properties: resource_fqn: description: |- +label= Resource FQN +usage=The fully qualified name of the resource type: string resource_type: description: |- +label=Resource Type +usage=The type of the resource (cluster, workspace, etc.) type: string role_id: description: >- +label=Role ID +usage=The role id of the role to be assigned to the service account for that resource type: string WorkspaceManifest: type: object required: - type - cluster_fqn - name properties: type: description: +value=workspace type: string enum: - workspace cluster_fqn: description: |- ``` -------------------------------- ### Get User API Endpoint - OpenAPI Specification Source: https://docs.truefoundry.com/api-reference/users/get-user This OpenAPI specification defines the `/api/svc/v1/users/{id}` GET endpoint. It details the path parameter `id` (User Id), security requirements using JWT bearer token, and comprehensive response schemas for a successful 200 OK response (returning a User object) and a 404 Not Found error. It also includes example response values and defines reusable `User` and `UserMetadata` schemas. ```APIDOC paths: path: /api/svc/v1/users/{id} method: get servers: - url: https://{controlPlaneURL} variables: controlPlaneURL: type: string description: Control Plane URL default: app.truefoundry.com request: security: - title: jwt parameters: query: {} header: Authorization: type: http scheme: bearer cookie: {} parameters: path: id: schema: - type: string required: true description: User Id query: {} header: {} cookie: {} body: {} response: '200': application/json: schemaArray: - type: object properties: data: allOf: - description: User allOf: - $ref: '#/components/schemas/User' refIdentifier: '#/components/schemas/GetUserResponse' requiredProperties: - data examples: example: value: data: id: email: userName: tenantName: metadata: sub: imageURL: displayName: userObject: {} inviteAccepted: true registeredInIdp: true preference: {} roles: - active: true createdAt: '2023-11-07T05:31:56Z' updatedAt: '2023-11-07T05:31:56Z' description: Returns the User associated with provided User id '404': application/json: schemaArray: - type: object properties: statusCode: allOf: - type: integer description: HTTP Status Code message: allOf: - type: string description: Error Message code: allOf: - oneOf: - type: integer - type: string description: Error code details: allOf: - type: array description: Error details items: type: object refIdentifier: '#/components/schemas/HttpError' requiredProperties: - statusCode - message examples: example: value: statusCode: 123 message: code: 123 details: - {} description: Not Found. No user found for the given user ID deprecated: false type: path components: schemas: UserMetadata: type: object properties: sub: type: string imageURL: type: string displayName: type: string userObject: type: object additionalProperties: true inviteAccepted: type: boolean registeredInIdp: type: boolean preference: type: object additionalProperties: true User: type: object properties: id: type: string email: type: string userName: type: string tenantName: type: string metadata: $ref: '#/components/schemas/UserMetadata' roles: type: array items: type: string active: type: boolean createdAt: format: date-time type: string updatedAt: format: date-time type: string required: - id - email - userName - tenantName - metadata - active - createdAt - updatedAt ``` -------------------------------- ### Batch Object API Response Schema and Example Source: https://docs.truefoundry.com/api-reference/batch/get-batch This snippet outlines the properties of the 'Batch' object as returned by the API, including various timestamps indicating its lifecycle status (e.g., created_at, completed_at, failed_at), file IDs, and request counts. An example response payload is provided to illustrate the expected data structure and typical values. ```APIDOC Batch Object Properties: id: object: endpoint: errors: input_file_id: completion_window: status: output_file_id: error_file_id: created_at: (timestamp) in_progress_at: (timestamp) expires_at: (timestamp) finalizing_at: (timestamp) completed_at: (timestamp) failed_at: (timestamp) expired_at: (timestamp) cancelling_at: (timestamp) cancelled_at: (timestamp) request_counts: total: completed: failed: metadata: Example Batch Object Response: { "id": "", "object": "", "endpoint": "", "errors": , "input_file_id": "", "completion_window": "", "status": "", "output_file_id": "", "error_file_id": "", "created_at": 123, "in_progress_at": 123, "expires_at": 123, "finalizing_at": 123, "completed_at": 123, "failed_at": 123, "expired_at": 123, "cancelling_at": 123, "cancelled_at": 123, "request_counts": { "total": 123, "completed": 123, "failed": 123 }, "metadata": } ``` -------------------------------- ### Customize Jupyter Image with apt and pip packages Source: https://docs.truefoundry.com/docs/launch-notebooks This Dockerfile example demonstrates how to create a custom Jupyter Notebook image by installing additional apt packages (like `ffmpeg`) and pip packages (like `gradio`) on top of a TrueFoundry base image. It ensures non-interactive installation for apt packages and uses PEP 517 for pip. ```docker FROM truefoundrycloud/jupyter:0.2.20 # Install apt packages RUN DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends ffmpeg # Install pip packages RUN python3 -m pip install --use-pep517 --no-cache-dir ``` -------------------------------- ### Initial Project File Structure Overview Source: https://docs.truefoundry.com/docs/deploy-job-using-python-sdk Displays the initial organization of the project files, highlighting `train.py` (the training script) and `requirements.txt` (dependencies). ```Text . ├── train.py - Contains the training script code. └── requirements.txt - Contains the list of all dependencies. ``` -------------------------------- ### TrueFoundry UI Deployment Configuration Parameters Source: https://docs.truefoundry.com/docs/deploy-your-first-asyncservice These are the key configuration parameters to be entered into the TrueFoundry UI form when deploying the async service, including the GitHub repository URL, the path to the build context, the command to run the FastAPI application, and the service port. ```text Repo URL: https://github.com/truefoundry/getting-started-examples Path to build context: ./deploy-model-with-fastapi/ Command: uvicorn app:app --host 0.0.0.0 --port 8000 Port: 8000 Destination URL (Inside Sidecar): http://0.0.0.0:8000/predict ``` -------------------------------- ### Get GKE Cluster Credentials Source: https://docs.truefoundry.com/docs/add-certificate-for-tls Retrieves the kubectl credentials for a specified Google Kubernetes Engine cluster, allowing command-line access to the cluster. This command requires the `gcloud` CLI to be installed and configured. ```shell gcloud container clusters get-credentials $CLUSTER_NAME --zone $CLUSTER_LOCATION --project $PROJECT_ID ``` -------------------------------- ### GET /api/svc/v1/secrets/{id}/deployments API Specification Source: https://docs.truefoundry.com/api-reference/secrets/list-associated-active-deployments This OpenAPI specification defines the GET endpoint to retrieve all deployments associated with a given secret ID. It includes details on path, query, and header parameters, security requirements (JWT bearer token), and the structure of the successful 200 JSON response, including pagination and a detailed deployment object example. ```YAML paths: path: /api/svc/v1/secrets/{id}/deployments method: get servers: - url: https://{controlPlaneURL} variables: controlPlaneURL: type: string description: Control Plane URL default: app.truefoundry.com request: security: - title: jwt parameters: query: {} header: Authorization: type: http scheme: bearer cookie: {} parameters: path: id: schema: - type: string required: true description: Secret Id of the secret. query: limit: schema: - type: integer required: false description: Number of items per page maximum: 1000 minimum: 1 default: 100 example: 10 offset: schema: - type: integer required: false description: Number of items to skip minimum: 0 default: 0 example: 0 header: {} cookie: {} body: {} response: '200': application/json: schemaArray: - type: object properties: data: allOf: - description: Associated Deployments type: array items: $ref: '#/components/schemas/Deployment' pagination: allOf: - description: Pagination Information allOf: - $ref: '#/components/schemas/Pagination' refIdentifier: '#/components/schemas/GetAssociatedDeploymentsResponse' requiredProperties: - data - pagination examples: example: value: data: - id: version: 123 fqn: applicationId: manifest: name: image: type: build docker_registry: build_source: type: remote remote_uri: build_spec: type: dockerfile dockerfile_path: build_context_path: command: build_args: {} artifacts_download: cache_volume: storage_class: cache_size: 500 artifacts: - type: truefoundry-artifact artifact_version_fqn: download_path_env_variable: resources: cpu_request: 128.0005 cpu_limit: 128.0005 memory_request: 1000000 memory_limit: 1000000 ephemeral_storage_request: 1000000 ephemeral_storage_limit: 1000000 shared_memory_size: 1000032 node: type: node_selector instance_families: - capacity_type: spot_fallback_on_demand devices: - type: nvidia_gpu name: count: 8 env: null ports: - port: 32768 protocol: TCP expose: true app_protocol: http host: path: rewrite_path_to: auth: type: basic_auth username: password: service_account: mounts: - type: secret mount_path: secret_fqn: labels: {} kustomize: patch: {} additions: - {} liveness_probe: config: type: http path: port: 32767 host: scheme: initial_delay_seconds: 18000 ``` -------------------------------- ### Log in to TrueFoundry CLI with Device Code Source: https://docs.truefoundry.com/docs/setup-cli Logs into TrueFoundry using the CLI with a device code. This command will prompt you to open a URL and enter the displayed code. Replace `` with your actual TrueFoundry host URL. ```bash tfy login --host ```