Get Status Helper functions

Use this function as a helper to poll the status of an ongoing request:

It assumes that you have set the MPX_SDK_BEARER_TOKEN = <your api key> environment variable in your .env file.

import time
from mpx_genai_sdk import Masterpiecex
from dotenv import load_dotenv

print(f'mpx version: {mpx_genai_sdk.__version__}')

load_dotenv()
mpx_client = Masterpiecex()

# Check that our API key works - you should see a welcome message
print(mpx_client.connection_test.retrieve())
# Expect:  Welcome to MasterpieceX API!

# Helper function to get the status of a Request
# Wait until the object has been generated (status = 'complete' or 'failed')
def retrieve_request_status(request_id):
  status_resp = mpx_client.status.retrieve(request_id)
  print(status_resp)
  while status_resp.status not in ["complete", "failed"]:
      time.sleep(10)
      status_resp = mpx_client.status.retrieve(request_id)
      print ('*', end='')
  print('') # clears waiting indicators
  print(status_resp)
  return status_resp

# Create a 3D model from a text prompt
general_resp = client.functions.create_general("prompt": "cute dog")
print(general_resp)
# Need to get the request id returned from the general model
request_id = general_resp.request_id
status_resp = retrieve_request_status(request_id)
print(f'status_resp: {status_resp}')
print("\nGeneration complete. See status_resp for links to the 3D model and thumbnail")
import Masterpiecex from 'mpx-genai-sdk'
import dotenv from 'dotenv';

dotenv.config();
const mpxClient = new Masterpiecex();

console.log(`mpx version: ${mpxClient.version}`);

// Check that our API key works - you should see a welcome message
mpxClient.connectionTest.retrieve().then((message) => {
  console.log(message);
});

// Helper function to get the status of a Request
// Wait until the object has been generated (status = 'complete' or 'failed')
async function retrieveRequestStatus(requestId: string) {
  let statusResp = await mpxClient.status.retrieve(requestId);
  console.log(statusResp);

  while (statusResp.status !== 'complete' && statusResp.status !== 'failed') {
    await new Promise((resolve) => setTimeout(resolve, 10000));
    statusResp = await mpxClient.status.retrieve(requestId);
    process.stdout.write('*');
  }
  console.log(''); // clears waiting indicators
  console.log(statusResp);
  return statusResp;
}

// Create a 3D model from a text prompt
mpxClient.functions.createGeneral({ prompt: 'cute dog' }).then((generalResp) => {
  console.log(generalResp);
  const requestId = generalResp.requestId;
  retrieveRequestStatus(requestId).then((statusResp) => {
    console.log(`status_resp: ${statusResp}`);
    console.log('Generation complete. See status_resp for links to the 3D model and thumbnail');
  });
});