Examples Python API Client Interface

Synchronous with progress callback:

from python_api_client_interface import ModelAPI

def progress_callback(progress_info, progress_data):
    process_progress_info(progress_info)
    process_progress_data(progress_data)

model_api = ModelAPI('https://api.aime.team', 'llama2_chat', 'user_name', 'user_key')
model_api.do_api_login()
result = model_api.do_api_request(params, progress_callback)
result_2 = model_api.do_api_request(params, progress_callback)
...

Asynchronous with asynchronous callbacks:

import asyncio
from python_api_client_interface import ModelAPI

async def result_callback(result):
    await process_result(result)

async def progress_callback(progress_info, progress_data):
    await process_progress_info(progress_info)
    await process_progress_data(progress_data)

async def progress_error_callback(error_description):
    print(error_description)

async def main():
    model_api = modelAPI('https://api.aime.team', 'llama2_chat', 'user_name', 'user_key')
    await model_api.do_api_login()
    result = await model_api.do_api_request(params, result_callback, progress_callback)
    result2 = await model_api.do_api_request(params, result_callback, progress_callback)
    ...
    await model_api.close_session()

asynchio.run(main())

Asynchronous with synchronous callbacks:

import asyncio
from python_api_client_interface import ModelAPI

sync def result_callback(result):
    process_result(result)

def progress_callback(progress_info, progress_data):
    process_progress_info(progress_info)
    process_progress_data(progress_data)

def progress_error_callback(error_description):
    print(error_description)

async def main():
    model_api = modelAPI('https://api.aime.team', 'llama2_chat', 'user_name', 'user_key')
    await model_api.do_api_login()
    result = await model_api.do_api_request(params, result_callback, progress_callback)
    result2 = await model_api.do_api_request(params, result_callback, progress_callback)
    ...
    await model_api.close_session()

asynchio.run(main())