Skip to main content

Runes client enables remote execution of python code triggered from a Crucible Plugin on the Signals & Sorcery platform.

Project description

signals_and_sorcery_logo

Signals & Sorcery

Signals & Sorcery is a platform for that connects Rune AIs to Crucible plugins.

For more information:

RUNES CLIENT

The Runes Client (this repo) is a python3 pip package. It is used to create Rune AIs. Rune AIs are Jupyter Notebooks scripted using the elixir client and packaged as containers. The client is responsible for moving data and files backand forth from the plugin (and server). The client allows a user to register python functions with the Signals & Sorcery discovery server. After a function has been registered it can then be triggered remotely from any of the Crucible plugins.

Installation

pip install runes-client --upgrade

Tests

from the root of the source code dir run:

pip uninstall runes-client -y && pip install -e . && pytest -s

Usage

This is a simple example of a RUNES script created using the runes-client. The script defines an arbitrary function that takes two arguments, an integer and a RunesFilePath. The function is registered with the SignalsAndSorceryAPI server. The script then connects to the SignalsAndSorceryAPI server and waits for a plugin to interact with it.

For thorough documentation and tutorials visit: https://signalsandsorcery.com/client/

import runes_client.core as runes 
from runes_client import RunesFilePath, ui_param

# The token generated by the Crucible plugin.  
# The token is used by the discovery server.  It associates the RUNE with the plugin.
TOKEN="0715c132-0b31-406e-b562-9206c479a48a"

# There are two separate function you need to register.  
# 1. The imports.  This is where you load any libraries you need to use in your RUNE.  This is important so that the RUNE is aware when dependencies are loaded and its ready to be called from the plugin.
# 2. The method.  This is the primary function of the RUNE.  This is where you write the code that will be executed when the RUNE is triggered.

# Name the function anything you like.  This is the imports function.  This is where you load any libraries you need to use in your RUNE.
async def register_imports():
    
    # perform any ```pip install <package>``` here
   
    import uuid, os, random, shutil 

    # all imports need to be made global.  If your imports are straight forward you can use the `make_imports_global` function.
    # If you need to do something more complex you will need to manually make the imports global. For example, in this case we download a large pre-trained model and need to make it global.

    # global model
    # model = MusicGen.get_pretrained('facebook/musicgen-melody')

    runes.make_imports_global([uuid, os, random, shutil])
    
    #NOTE: `make_imports_global()` does not support imports with aliases.  You will need to manually make these global.
    
# Now register the imports function with the discovery server.
runes.register_imports(register_imports)

# The registered method can be named anything.  This is the primary function of the RUNE.  
# This function will be rendered as a web form in the crucible plugin. Note: the method must be `async`.  
# All parameters must be type hinted.  
# Five parameter types are supported: int, float, str, bool, RunesFilePath
# RunesFilePath is a special type. When the file is sent to the remote, it is intercepted by the system and 
# transported to a temp dir on the remote.  In this case the variable `b` is local path to the file.

# The `ui_param` is an optional decorator. It is used to define how the parameter input UI will be rendered in the plugin.  
# If the decorator is not used, the parameter will be rendered as a text input field. 
@ui_param('a', 'RunesNumberSlider', min=0, max=10, step=1, default=5)
@ui_param('c', 'RunesMultiChoice', options=['cherries', 'oranges', 'grapes'], default='grapes')
async def arbitrary_method(a: int, b: RunesFilePath, c: str):
    try: 
        # -----------------------------------------
        # This is where you can write custom code to operate on the input params.
        # ex param `a` could be the number of variations created from param `b` using something like MusicLM
        # -----------------------------------------
        
        # This is how you send results back to the plugin, when processing is complete.
        await runes.results().add_file(b) 
        # This message is displayed in the plugin.
        await runes.results().add_message("This is a message XYZ") 

        return True
    except Exception as e: 
        #explicitly send an error message back to the plugin
        await runes.results().add_error(f"Method encountered an error: {e}")
        return False


# The token generated by the plugin. 
runes.set_token(token=TOKEN)
# The name of the remote.  This is displayed in the plugin.
runes.set_name("My Remote Code")
# The description of the remote.  This is displayed in the plugin.
runes.set_description("This is not a real description.")
# Register the method with the discovery server.
runes.register_method(arbitrary_method)

# When a file is sent to the remote as a RunesFilePath, it will become available at this sample rate. 
runes.set_input_target_sample_rate(44100) #supported values [22050, 32000, 44100, 48000]
# When a file is sent to the remote as a RunesFilePath, it will become available at this bit rate. 
runes.set_input_target_bit_depth(16) #supported values [16, 24, 32]
# When a file is sent to the remote as a RunesFilePath, it will become available with this number of channels.
runes.set_input_target_channels(2) #supported values [1, 2] mono/stereo respectively
# When a file is sent to the remote as a RunesFilePath, it will become available in this format.
runes.set_input_target_format('wav') #supported values ["wav", "mp3", "aif", "flac"]

# When results are sent back to the plugin, they will be sent at this sample rate.
runes.set_output_target_sample_rate(44100)
# When results are sent back to the plugin, they will be sent at this bit rate.
runes.set_output_target_bit_depth(16)
# When results are sent back to the plugin, they will be sent with this number of channels.
runes.set_output_target_channels(2)
# When results are sent back to the plugin, they will be sent in this format.
runes.set_output_target_format('wav')

# This should be the last line of the script.  It connects to the discovery server and waits for a remote trigger.
runes.connect_to_server()

CONFIGURATION:

Note: If the following environment variables are not set, the client will use the default values. The default values will point to the public Signals & Sorcery server (https://signalsandsorceryapi.com/api/swagger/). If you wish to host your own instance you will need to configure the following environment variables.

export DN_CLIENT_API_BASE_URL='https://signalsandsorceryapi.com/'
export DN_CLIENT_SOCKET_IP='0.0.0.0'
export DN_CLIENT_SOCKET_PORT='8765'
export DN_CLIENT_SENTRY_API_KEY='XXX'
"DN_CLIENT_STORAGE_BUCKET", "https://storage.googleapis.com/your_gcp_bucket/"

Note: If the env var DN_CLIENT_TOKEN is set it will override the set_token() function.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

runes-client-0.9.2.tar.gz (37.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

runes_client-0.9.2-py3-none-any.whl (53.5 kB view details)

Uploaded Python 3

File details

Details for the file runes-client-0.9.2.tar.gz.

File metadata

  • Download URL: runes-client-0.9.2.tar.gz
  • Upload date:
  • Size: 37.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.2

File hashes

Hashes for runes-client-0.9.2.tar.gz
Algorithm Hash digest
SHA256 9c53896589d32463ce8ed5445e2b470b130bff75b9df1541af5dd8037fc94425
MD5 c8d058b3281065b3d675ea9ec128ce84
BLAKE2b-256 5d36dfa1ba05f42d9e4e26dde908827612815dbb27d8b56c8b9254dd3ee27de6

See more details on using hashes here.

File details

Details for the file runes_client-0.9.2-py3-none-any.whl.

File metadata

  • Download URL: runes_client-0.9.2-py3-none-any.whl
  • Upload date:
  • Size: 53.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.2

File hashes

Hashes for runes_client-0.9.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a92e48d6b4620cae222f44894d2cc96aa31d1d22b9cda1c7dde61251905782ef
MD5 18a712d965063f9a323a6687f3149240
BLAKE2b-256 157a2650ace432e9094cb7492f8a5273b5510f69c3b9bed3d3b66a72715056b3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page