class_docstr: Records the model classes used to define an endpoints request/response body.
  
  The request / response body schemas are generated dynamically depending on the endpoint + components passed into the
  class initializer. Component inputs & outputs (as defined in `@expose` object decorations) dtype method (`serialize`
  and `deserialize`) type hints are inspected in order to constuct a specification unique to the endpoint, they are
  returned as subclasses of pydantic ``BaseModel``.
class_docstr_tok: ["Records","the","model","classes","used","to","define","an","endpoints","request\/response","body",".","The","request","\/","response","body","schemas","are","generated","dynamically","depending","on","the","endpoint","+","components","passed","into","the","class","initializer",".","Component","inputs","&","outputs","(","as","defined","in","`","@","expose","`","object","decorations",")","dtype","method","(","`","serialize","`","and","`","deserialize","`",")","type","hints","are","inspected","in","order","to","constuct","a","specification","unique","to","the","endpoint",",","they","are","returned","as","subclasses","of","pydantic","``","BaseModel","``","."]
docstr: Subclass of pydantic ``BaseModel`` specifying HTTP request body schema.
  
  Notes
  -----
  * Because pydantic does not allow you to define two models with
    the same `model name`, even when they are assigned to different
    python variables and contain different fields:
  
    >>> image_1 = create_model('Image', ...)  # doctest: +SKIP
    >>> image_2 = create_model('Image', ...)  # doctest: +SKIP
    >>> payload = create_model("Payload_1", **{"payload": image_1})  # doctest: +SKIP
    ERROR: Exception in ASGI application
    Traceback (most recent call last):
      ...
      model_name = model_name_map[model]
    KeyError: <class 'Image'>
  
    We prepend the name of the endpoint (which must be unique since
    endpoints are stored as a dict mapping names -> definitions within
    the composition) to the model class title. While this means that there
    are a lot of models defined within the OpenAPI scheam, this does not
    impact the field names of each models.
  
    As an examples: a model is created which will be a subfield of a
    "payload" model. The endpoint is named "classify_endpoint". The
    model we are defined will contains an encoded image string field.
    The model's name in the OpenAPI definition will be listed as
    "Classify_Endpoint_Image", but the field name "image" is untouched.
    Any POST to that endpoint just needs to send a json struct with
    the key "image" -> the raw data... The field names are NOT altered,
    and therefore this workaround should pose very little issue for
    our end users).
docstr_tok: ["Subclass","of","pydantic","``","BaseModel","``","specifying","HTTP","request","body","schema",".","Notes","--","--","-","*","Because","pydantic","does","not","allow","you","to","define","two","models","with","the","same","`","model","name","`",",","even","when","they","are","assigned","to","different","python","variables","and","contain","different","fields",":",">",">",">","image_1","=","create_model","(","'Image","'",",","...",")","#","doctest",":","+SKIP",">",">",">","image_2","=","create_model","(","'Image","'",",","...",")","#","doctest",":","+SKIP",">",">",">","payload","=","create_model","(","``","Payload_1","''",",","*","*","{","``","payload","''",":","image_1","}",")","#","doctest",":","+SKIP","ERROR",":","Exception","in","ASGI","application","Traceback","(","most","recent","call","last",")",":","...","model_name","=","model_name_map","[","model","]","KeyError",":","<","class","'Image","'",">","We","prepend","the","name","of","the","endpoint","(","which","must","be","unique","since","endpoints","are","stored","as","a","dict","mapping","names","-",">","definitions","within","the","composition",")","to","the","model","class","title",".","While","this","means","that","there","are","a","lot","of","models","defined","within","the","OpenAPI","scheam",",","this","does","not","impact","the","field","names","of","each","models",".","As","an","examples",":","a","model","is","created","which","will","be","a","subfield","of","a","``","payload","''","model",".","The","endpoint","is","named","``","classify_endpoint","''",".","The","model","we","are","defined","will","contains","an","encoded","image","string","field",".","The","model","'s","name","in","the","OpenAPI","definition","will","be","listed","as","``","Classify_Endpoint_Image","''",",","but","the","field","name","``","image","''","is","untouched",".","Any","POST","to","that","endpoint","just","needs","to","send","a","json","struct","with","the","key","``","image","''","-",">","the","raw","data","...","The","field","names","are","NOT","altered",",","and","therefore","this","workaround","should","pose","very","little","issue","for","our","end","users",")","."]
code: def request_model(self) -> RequestModel:
      """Subclass of pydantic ``BaseModel`` specifying HTTP request body schema.
  
      Notes
      -----
      * Because pydantic does not allow you to define two models with
        the same `model name`, even when they are assigned to different
        python variables and contain different fields:
  
        >>> image_1 = create_model('Image', ...)  # doctest: +SKIP
        >>> image_2 = create_model('Image', ...)  # doctest: +SKIP
        >>> payload = create_model("Payload_1", **{"payload": image_1})  # doctest: +SKIP
        ERROR: Exception in ASGI application
        Traceback (most recent call last):
          ...
          model_name = model_name_map[model]
        KeyError: <class 'Image'>
  
        We prepend the name of the endpoint (which must be unique since
        endpoints are stored as a dict mapping names -> definitions within
        the composition) to the model class title. While this means that there
        are a lot of models defined within the OpenAPI scheam, this does not
        impact the field names of each models.
  
        As an examples: a model is created which will be a subfield of a
        "payload" model. The endpoint is named "classify_endpoint". The
        model we are defined will contains an encoded image string field.
        The model's name in the OpenAPI definition will be listed as
        "Classify_Endpoint_Image", but the field name "image" is untouched.
        Any POST to that endpoint just needs to send a json struct with
        the key "image" -> the raw data... The field names are NOT altered,
        and therefore this workaround should pose very little issue for
        our end users).
  
      """
      attrib_dict = {}
      inputs = self._endpoint.inputs
      for payload_name, component_and_input_key in inputs.items():
          component, _, key = component_and_input_key.split(".")
          param = self._component[component].inputs[key]
          hints = param.datatype.type_hints["input_args"]
          each = {}
          for key, key_t in hints.items():
              each[key] = (key_t, ...)
          model = create_model(
              f"{self.name.title()}_{payload_name.title()}", **each
          )
          if isinstance(param.datatype, Repeated):
              attrib_dict[payload_name] = (
                  Tuple[model, ...],
                  ...,
              )
          else:
              attrib_dict[payload_name] = (
                  model,
                  ...,
              )
  
      payload_model = create_model(
          f"{self.name.title()}_Payload", **attrib_dict
      )
      RequestModel = create_model(
          f"{self.name.title()}_RequestModel",
          __module__=self.__class__.__module__,
          **{
              "session": (Optional[str], None),
              "payload": (payload_model, ...),
          },
      )
      RequestModel.update_forward_refs()
      return RequestModel
  
file_path: lightning-flash/src/flash/core/serve/interfaces/models.py
imports: from typing import Dict, Optional, Tuple
  from flash.core.serve.component import ModelComponent
  from flash.core.serve.core import Endpoint
  from flash.core.serve.types import Repeated
  from flash.core.utilities.imports import _PYDANTIC_AVAILABLE, _TOPIC_SERVE_AVAILABLE
label_desc: Use image node_id 6 for calling the EndpointProtocol obj's underlying member method code with example usage: obj.request_model() and returns: RequestModel