def __init__(self, bento_service: BentoService, config: Config) -> None: self._version = bento_service.version service_name = bento_service.name namespace = bentoml_config("instrument").get("default_namespace") self._metric = Summary( name=service_name + "_oracle_metric", documentation=" Oracle Metric", namespace=namespace, labelnames=["endpoint", "service_version"], ) self._selected_arm = Counter( name=service_name + "_arm_total", documentation='Total number selected arm', namespace=namespace, labelnames=["endpoint", "service_version", "arm"])
class BaseInputAdapter: """InputAdapter is an abstraction layer between user defined API callback function and prediction request input in a variety of different forms, such as HTTP request body, command line arguments or AWS Lambda event object. """ HTTP_METHODS = ["POST", "GET"] _BATCH_REQUEST_HEADER = bentoml_config("apiserver").get( "batch_request_header") BATCH_MODE_SUPPORTED = False def __init__(self, output_adapter=None, **base_config): ''' base_configs: - is_batch_input ''' self._config = base_config self._output_adapter = output_adapter @property def config(self): if getattr(self, '_config', None) is None: self._config = {} return self._config @property def output_adapter(self): if self._output_adapter is None: from .default_output import DefaultOutput self._output_adapter = DefaultOutput() return self._output_adapter def handle_request(self, request, func): """Handles an HTTP request, convert it into corresponding data format that user API function is expecting, and return API function result as the HTTP response to client :param request: Flask request object :param func: user API function """ raise NotImplementedError def handle_batch_request(self, requests: Iterable[SimpleRequest], func) -> Iterable[SimpleResponse]: """Handles an HTTP request, convert it into corresponding data format that user API function is expecting, and return API function result as the HTTP response to client :param requests: List of flask request object :param func: user API function """ raise NotImplementedError def handle_cli(self, args, func): """Handles an CLI command call, convert CLI arguments into corresponding data format that user API function is expecting, and prints the API function result to console output :param args: CLI arguments :param func: user API function """ raise NotImplementedError def handle_aws_lambda_event(self, event, func): """Handles a Lambda event, convert event dict into corresponding data format that user API function is expecting, and use API function result as response :param event: AWS lambda event data of the python `dict` type :param func: user API function """ raise NotImplementedError @property def request_schema(self): """ :return: OpenAPI json schema for the HTTP API endpoint created with this input adapter """ return {"application/json": {"schema": {"type": "object"}}} @property def pip_dependencies(self): """ :return: List of PyPI package names required by this InputAdapter """ return []
def view_effective(): track_cli('config-view-effective') bentoml_config().write(sys.stdout) return
def view_effective(): bentoml_config().write(sys.stdout) return
import pickle from functools import lru_cache from typing import Sequence from bentoml import config as bentoml_config from bentoml.types import HTTPRequest, HTTPResponse BATCH_REQUEST_HEADER = bentoml_config("apiserver").get("batch_request_header") class PlasmaDataLoader: """ Transfer datas with plasma store, in development now """ @classmethod @lru_cache(maxsize=1) def get_plasma(cls): import pyarrow.plasma as plasma import subprocess object_store_size = 2 * 10 * 1000 * 1000 plasma_path = "/tmp/store" subprocess.Popen( ["plasma_store", "-s", plasma_path, "-m", str(object_store_size)]) return plasma.connect(plasma_path) @classmethod def merge_requests(cls, reqs) -> bytes: merged_reqs = tuple((b, h) for h, b in reqs) oid = cls.get_plasma().put(merged_reqs)