class_docstr: APIService is used to define a service.
  After the definition is completed, you can use HTTPServer or the GRPCServer to started it.
  
  Example:
  
  .. code-block:: python
  
      import typing as T
      from pydantic import BaseModel
      from towhee import AutoPipes, api_service
      from towhee.serve.io import JSON
  
      service = api_service.APIService(desc="Welcome")
      stn = AutoPipes.pipeline('sentence_embedding')
  
      @service.api(path='/embedding')
      def chat(params: T.List[T.Any]):
          return stn(*params).to_list()
  
      class Item(BaseModel):
          url: str
          ids: T.List[int]
  
      @service.api(path='/echo', input_model = JSON(Item), output_model=JSON(Item))
      def echo(item: Item):
          return item
  
      if __name__ == '__main__':
          import sys
          if sys.argv[1] == 'http':
              from towhee.serve.http.server import HTTPServer
              HTTPServer(service).run('0.0.0.0', 8000)
          else:
              import logging
              from towhee.utils.log import engine_log
              engine_log.setLevel(logging.INFO)
              from towhee.serve.grpc.server import GRPCServer
              GRPCServer(service).run('0.0.0.0', 8000)
  
      Client Example:
          http:
              import requests
              requests.post('http://127.0.0.1:8000/echo', json={'url': 1, 'ids': [1, 2]}).json()
              requests.post('http://127.0.0.1:8000/embedding', json=['hello world']).json()
  
          grpc:
              from towhee.serve.grpc.client import Client
              c = Client('0.0.0.0', 8000)
              c('/echo', {'url': 1, 'ids': [1, 2]})
              c('/embedding', ['hello'])
code: def api(
      self,
      input_model: Optional[Any] = None,
      output_model: Optional[Any] = None,
      path: Optional[str] = None,
  ):
      def decorator(func: Callable):
          self.add_api(func, input_model, output_model, path)
          return func
  
      return decorator
  
file_path: towhee/towhee/serve/api_service.py
imports: from typing import Optional, Any, Union, List, Callable, Tuple
  from functools import partial
  from pydantic import BaseModel
label_desc: Use image node_id 1 for calling the APIService obj's underlying member method code with example usage: obj.api(input_model, output_model, path) and returns: decorator, func