Files
Yeuoly 5f517df4f5 feat: mark constructors as final in multiple classes (#132)
- Added `@final` decorator to the constructors of `AgentStrategy`, `Endpoint`, `AIModel`, and `Tool` classes to prevent overriding.
- Included documentation notes in each constructor to indicate that they should not be overridden.
2025-05-07 13:22:20 +08:00

42 lines
1.2 KiB
Python

from abc import ABC, abstractmethod
from collections.abc import Mapping
from typing import final
from werkzeug import Request, Response
from dify_plugin.core.runtime import Session
class Endpoint(ABC):
@final
def __init__(self, session: Session) -> None:
"""
Initialize the endpoint
NOTE:
- This method has been marked as final, DO NOT OVERRIDE IT.
"""
self.session = session
############################################################
# Methods that can be implemented by plugin #
############################################################
@abstractmethod
def _invoke(self, r: Request, values: Mapping, settings: Mapping) -> Response:
"""
Invokes the endpoint with the given request.
To be implemented by subclasses.
"""
############################################################
# For executor use only #
############################################################
def invoke(self, r: Request, values: Mapping, settings: Mapping) -> Response:
"""
Invokes the endpoint with the given request.
"""
return self._invoke(r, values, settings)