API Worker Interface
You can easily turn your existing Pytorch and Tensorflow script into an API computer worker by integrating the AIME API Worker Interface.
It is currently available as Python Pip package, extendable to other programming language. It mainly consist of three calls:
Wait for a job and get the input parameters for the compute job
In case of lengthy jobs: send job status or intermediate results
Send the final job result
This can be integrated after the model is loaded in a loop to process jobs without having to load the model for each request, giving much faster response times than starting a script for each compute request.
Setup:
The AIME API worker interface Python Pip package can be installed with following commands:
pip install wheel pip install git+https://github.com//aime-team/aime-api-worker-interface
Examples
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, ...)
Note
This project is under active development.