Use SambaStudio Python SDK#

The examples below describe common interactions for the SambaStudio Python SDK.

List models#

import json
# 1. Import SDK
from snsdk import SnSdk
# 2. Create SnSdk instance using SAMBASTUDIO_HOSTNAME, API_KEY and TENANT_ID
sdk = SnSdk("<SAMBASTUDIO_HOSTNAME>", "<API_KEY>", "<TENANT_ID>")
print("MODELS")
print(json.dumps(sdk.list_models(), indent=4))

Create an endpoint#

import json
# 1. Import SDK
from snsdk import SnSdk
# 2. Create SnSdk instance using SAMBASTUDIO_HOSTNAME, API_KEY and TENANT_ID
sdk = SnSdk("<SAMBASTUDIO_HOSTNAME>", "<API_KEY>", "<TENANT_ID>")
print(f"CREATING AN ENDPOINTS IN PROJECT: {'<PROJECT>'}")
sdk.http_session.cookies.set("tenant", "<TENANT_ID>")
print(json.dumps(
sdk.create_endpoint(
    "<PROJECT>",
    "<ENDPOINT_NAME>",
    "<ENDPOINT_DESCRIPTION>",
    "<MODEL_CHECKPOINT>",
    "<NUMBER_OF_INSTANCES>",
    "<HYPER_PARAMETERS>",
),
indent=4))

Get the endpoint details#

import json
# 1. Import SDK
from snsdk import SnSdk
# 2. Create SnSdk instance using SAMBASTUDIO_HOSTNAME, API_KEY and TENANT_ID
sdk = SnSdk("<SAMBASTUDIO_HOSTNAME>", "<API_KEY>", "<TENANT_ID>")
print(f"DETAILS OF ENDPOINTS: '<ENDPOINTS>' IN PROJECT: '<PROJECT>'")
print(json.dumps(sdk.endpoint_info("<PROJECT>", "<ENDPOINT>"), indent=4))

Get prediction for the prompt#

import json
# 1. Import SDK
from snsdk import SnSdk
# 2. Create SnSdk instance using SAMBASTUDIO_HOSTNAME, API_KEY and TENANT_ID
sdk = SnSdk("<SAMBASTUDIO_HOSTNAME>", "<API_KEY>", "<TENANT_ID>")
print(f"PREDICTION")
print(json.dumps(sdk.nlp_predict("<PROJECT>", "<ENDPOINT>", "<["SAMPLE_PROMPT"]>"), indent=4))