now.apps.base.app module#

class now.apps.base.app.JinaNOWApp[source]#

Bases: object

Interface for Jina NOW applications. To create a new application, you need to inherit from this class and override the methods. Example:

class TextToImageApp(JinaNowApp):

pass

property app_name: str#

Name of the app. Should be an enum value set in now.constants.Apps

Return type

str

property is_enabled: bool#

Set to True if this app is enabled for the end user.

Return type

bool

property description: str#

Short description of the app.

Return type

str

abstract property input_modality: now.constants.Modalities#

Modality used for running search queries

Return type

Modalities

abstract property output_modality: now.constants.Modalities#

Modality used for indexing data

Return type

Modalities

set_flow_yaml(**kwargs)[source]#

Used to configure the flow yaml in the Jina NOW app. The interface is as follows: - if kwargs[‘finetuning’]=True, choose finetuning flow - if kwargs[‘encode’]=True, choose encoding flow (to get embeddings for finetuning) - temporarily introduced kwargs[‘dataset_len’], if app optimizes different flows to it

property bff: Optional[str]#

TODO This function is currently not used but already introduces the concept of custom bff Used to configure the bff which is used to define input and output format. :rtype: Optional[str] :return: the path to the file where the bff routs are configured

property playground: Optional[str]#

TODO This function is currently not used but already introduces the concept of custom playground Used to configure the playground(streamlit app) where the user can run example queries :rtype: Optional[str] :return: the path to the streamlit file.

property options: List[now.now_dataclasses.DialogOptions]#

Get the options which are used to configure the app. Base class should override this function and return the list of their option. Check DialogOptions for the format of the options On CLI the user will get a prompt and at the storefront, a GUI will be generated accordingly. Example: return [options.your_custom_options`] :rtype: List[DialogOptions] :return: List[DialogOptions]

property supported_file_types: List[str]#

Used to filter files in local structure or an S3 bucket.

Return type

List[str]

property example_datasource: List[now.datasource.datasource.DemoDatasource]#

# TODO just a prototype - needs to be implemented in the future Get a list of example datasets for the app.

Return type

List[DemoDatasource]

property required_docker_memory_in_gb: int#

Recommended memory limit for the docker client to run this app.

Return type

int

property finetune_datasets: [Tuple]#

Defines the list of demo datasets which are fine-tunable.

Return type

[Tuple]

set_app_parser(parser, formatter)[source]#

This parser reads from the options property and parses it to form the command line arguments for app

Return type

None

run_checks(user_input)[source]#
Return type

bool

setup(dataset, user_input, kubectl_path)[source]#

Runs before the flow is deployed. Common use cases:

  • create a database

  • finetune a model + push the artifact

  • notify other services

  • check if starting the app is currently possible

Parameters
  • dataset (DocumentArray) –

  • user_input (UserInput) – user configuration based on the given options

Return type

Dict

Returns

dict used to replace variables in flow yaml and to clean up resources after the flow is terminated

cleanup(app_config)[source]#

Runs after the flow is terminated. Cleans up the resources created during setup. Common examples are:

  • delete a database

  • remove artifact

  • notify other services

Parameters

app_config (dict) – contains all information needed to clean up the allocated resources

Return type

None

preprocess(da, user_input, is_indexing=False)[source]#

Loads and preprocesses every document such that it is ready for finetuning/indexing.

Return type

DocumentArray

property bff_mapping_fns: Dict[str, Tuple[Any, Any, Callable[[Any], jina.serve.runtimes.gateway.http.models.JinaRequestModel], Callable[[jina.serve.runtimes.gateway.http.models.JinaResponseModel], Any]]]#

Apps usually have a custom input format and response which does not match the JinaRequestModel or JinaResponseModel. To create the mapping each Jina NOW app can implement the two bff mapping functions for each path - one for requests and one for responses

Return type

Dict[str, Tuple[Any, Any, Callable[[Any], JinaRequestModel], Callable[[JinaResponseModel], Any]]]

Returns

dictionary from path to a tuple of request model, response model,

request mapping fn and response mapping fn. By default, the mapping is the identity function and the request model and respond model are the default models. The path is a regex expression.

property index_query_access_paths: str#

Gives access paths for indexing and searching.

Return type

str

property max_request_size: int#

Max number of documents in one request

Return type

int