Repository: microsoft/promptflow
File: src/promptflow-core/promptflow/core/_serving/app_base.py (Python)

Code before:

        # enable environment_variables
        environment_variables = kwargs.get("environment_variables", {})
        logger.debug(f"Environment variables: {environment_variables}")
        os.environ.update(environment_variables)
        default_environment_variables = self.flow.get_environment_variables_with_overrides()
        self.set_default_environment_variables(default_environment_variables)

        self.flow_name = self.extension.get_flow_name()
        self.flow.name = self.flow_name
        conn_data_override, conn_name_override = self.extension.get_override_connections(self.flow)
        self.connections_override = conn_data_override
        self.connections_name_override = conn_name_override

        self.connection_provider = self.extension.get_connection_provider()
        self.credential = self.extension.get_credential()
        self.sample = get_sample_json(self.project_path, logger)

        self.init = kwargs.get("init", {})
        try:
            init_params = os.environ.get(PROMPTFLOW_FLOW_INIT_CONFIG, "{}")
            init_dict: dict = json.loads(init_params)
            init_dict.update(self.init)
            self.init = init_dict
        except Exception as e:
            logger.error("Failed to retrieve init params from environment variable PROMPTFLOW_FLOW_INIT_CONFIG: ", e)

        logger.debug("Init params: " + str(self.init))

        self.init_swagger()
        # try to initialize the flow invoker
        try:
            self.init_invoker_if_not_exist()
        except Exception as e:
            if self.extension.raise_ex_on_invoker_initialization_failure(e):
                raise e
        # ensure response has the correct content type
        mimetypes.add_type("application/javascript", ".js")
        mimetypes.add_type("text/css", ".css")
        setup_user_agent_to_operation_context(self.extension.get_user_agent())

    @abstractmethod
    def get_context_data_provider(self):
        pass

    @abstractmethod
    def streaming_response_required(self):
        pass

    def init_invoker_if_not_exist(self):
        if self.flow_invoker:

Review comment (bug):
IF init data format is not correct, deployment should fail instead of just logging the exception. Need to throw an User error exception here.

Code after:

        # enable environment_variables
        environment_variables = kwargs.get("environment_variables", {})
        logger.debug(f"Environment variables: {environment_variables}")
        os.environ.update(environment_variables)
        default_environment_variables = self.flow.get_environment_variables_with_overrides()
        self.set_default_environment_variables(default_environment_variables)

        self.flow_name = self.extension.get_flow_name()
        self.flow.name = self.flow_name
        conn_data_override, conn_name_override = self.extension.get_override_connections(self.flow)
        self.connections_override = conn_data_override
        self.connections_name_override = conn_name_override

        self.connection_provider = self.extension.get_connection_provider()
        self.credential = self.extension.get_credential()
        self.sample = get_sample_json(self.project_path, logger)

        self.init = kwargs.get("init", {})
        if not self.init:
            init_params = os.environ.get(PF_FLOW_INIT_CONFIG, "{}")
            init_dict: dict = json.loads(init_params)
            self.init = init_dict

        logger.debug("Init params: " + str(self.init))

        self.init_swagger()
        # try to initialize the flow invoker
        try:
            self.init_invoker_if_not_exist()
        except Exception as e:
            if self.extension.raise_ex_on_invoker_initialization_failure(e):
                raise e
        # ensure response has the correct content type
        mimetypes.add_type("application/javascript", ".js")
        mimetypes.add_type("text/css", ".css")
        setup_user_agent_to_operation_context(self.extension.get_user_agent())

    @abstractmethod
    def get_context_data_provider(self):
        pass

    @abstractmethod
    def streaming_response_required(self):
        pass

    def init_invoker_if_not_exist(self):
        if self.flow_invoker:
            return
        self.logger.info("Promptflow executor starts initializing...")
        self.flow_invoker = AsyncFlowInvoker(