Examples API Worker Interface

Minimal example, instantiate the api_worker with URL to the API server, job type and auth_key. Waiting for and receiving job data and sending job result:

from aime_api_worker_interface import APIWorkerInterface

api_worker = APIWorkerInterface('http://api.aime.team', 'llama2_chat', <auth_key>)
while True:
    job_data = api_worker.job_request()
    output = do_deep_learning_worker_calculations(job_data, ...)
    api_worker.send_job_results(output)

Example usage with progress:

from aime_api_worker_interface import APIWorkerInterface

api_worker = APIWorkerInterface('http://api.aime.team', 'llama2_chat', <auth_key>)
while True:
    job_data = api_worker.job_request()

    for step in deep_learning_worker_calculation:
        progress_in_percent = round(step*100/len(deep_learning_worker_calculation))
        progress_data = do_deep_learning_worker_calculation_step(job_data, ...)
        if api_worker.progress_data_received:
            api_worker.send_progress(progress_in_percent, progress_data)
    output = get_result()
    api_worker.send_job_results(output)

Example usage with callback:

from aime_api_worker_interface import APIWorkerInterface

def progress_callback(api_worker, progress, progress_data):
    if api_worker.progress_data_received:
        api_worker.send_progress(progress, progress_data)


api_worker = APIWorkerInterface('http://api.aime.team', 'llama2_chat', <auth_key>)
callback = Callback(api_worker)

while True:
    job_data = api_worker.job_request()
    output = do_deep_learning_worker_calculation(job_data, progress_callback, api_worker, ...)
    api_worker.send_progress(progress, progress_data)

Example usage with callback class:

from aime_api_worker_interface import APIWorkerInterface

class Callback():

    def __init__(self, api_worker):
        self.api_worker = api_worker


    def progress_callback(self, progress, progress_data):
        if self.api_worker.progress_data_received:
            self.api_worker.send_progress(progress, progress_data)

    def result_callback(self, result):
        self.api_worker.send_job_results(result)


api_worker = APIWorkerInterface('http://api.aime.team', 'llama2_chat', <auth_key>)
callback = Callback(api_worker)

while True:
    job_data = api_worker.job_request()
    do_deep_learning_worker_calculation(job_data, callback.result_callback, callback.progress_callback, ...)