Пример #1
0
def get_versioning_api() -> VersioningApi:
    configuration = Configuration()
    configuration.host = getenv('LIGHTLY_SERVER_LOCATION',
                                'https://api.lightly.ai')
    api_client = ApiClient(configuration=configuration)
    versioning_api = VersioningApi(api_client)
    return versioning_api
Пример #2
0
    def __init__(self, token: str, dataset_id: str = None, embedding_id: str = None):

        self.check_version_compatibility()

        configuration = Configuration()
        configuration.host = getenv('LIGHTLY_SERVER_LOCATION', 'https://api.lightly.ai')
        configuration.api_key = {'token': token}
        api_client = ApiClient(configuration=configuration)
        self.api_client = api_client

        self.token = token
        if dataset_id is not None:
            self._dataset_id = dataset_id
        if embedding_id is not None:
            self.embedding_id = embedding_id

        self.datasets_api = DatasetsApi(api_client=self.api_client)
        self.samplings_api = SamplingsApi(api_client=self.api_client)
        self.jobs_api = JobsApi(api_client=self.api_client)
        self.tags_api = TagsApi(api_client=self.api_client)
        self.embeddings_api = EmbeddingsApi(api_client=api_client)
        self.mappings_api = MappingsApi(api_client=api_client)
        self.scores_api = ScoresApi(api_client=api_client)
        self.samples_api = SamplesApi(api_client=api_client)
        self.quota_api = QuotaApi(api_client=api_client)
Пример #3
0
def _prefix(*args, **kwargs):
    """Returns the prefix for the users routes.

    All routes through users require authentication via jwt.

    """
    server_location = getenv('LIGHTLY_SERVER_LOCATION',
                             'https://api.lightly.ai')
    return server_location + '/users/docker'
Пример #4
0
def _prefix(*args, **kwargs):
    """Returns the prefix for the pip route.

    The pip route does not require authentication.

    """
    server_location = getenv('LIGHTLY_SERVER_LOCATION',
                             'https://api.lightly.ai')
    return server_location + '/pip'
Пример #5
0
def _prefix(dataset_id: Union[str, None] = None, *args, **kwargs):
    """Returns the prefix for the embeddings routes.

    Args:
        dataset_id:
            Identifier of the dataset.

    """
    server_location = getenv('LIGHTLY_SERVER_LOCATION',
                             'https://api.lightly.ai')
    prefix = server_location + '/users/datasets'
    if dataset_id is None:
        return prefix + '/embeddings'
    else:
        return prefix + '/' + dataset_id + '/embeddings'
Пример #6
0
 def test_getenv_fail(self):
     env = getenv('TEST_ENV_VARIABLE_WHICH_DOES_NOT_EXIST', 'hello world')
     self.assertEqual(env, 'hello world')
Пример #7
0
 def test_getenv(self):
     os.environ['TEST_ENV_VARIABLE'] = 'hello world'
     env = getenv('TEST_ENV_VARIABLE', 'default')
     self.assertEqual(env, 'hello world')
Пример #8
0
""" Communication with Lightly Servers """

# Copyright (c) 2020. Lightly AG and its affiliates.
# All Rights Reserved

import time
import random
import requests

from lightly.api.utils import getenv
SERVER_LOCATION = getenv('LIGHTLY_SERVER_LOCATION',
                         'https://api.lightly.ai')


def _post_request(dst_url, data=None, json=None,
                  max_backoff=32, max_retries=5):

    counter = 0
    backoff = 1. + random.random() * 0.1
    success = False
    while not success:

        response = requests.post(dst_url, data=data, json=json)
        success = (response.status_code == 200)

        # exponential backoff
        if response.status_code in [500, 502]:
            time.sleep(backoff)
            backoff = 2*backoff if backoff < max_backoff else backoff
        elif response.status_code in [402]:
            msg = f'Dataset limit reached. Failed to upload samples. '