From 77953bfde8322ac6fd3efc2b1c767bcc8042360e Mon Sep 17 00:00:00 2001 From: hwzhuhao <923196325@qq.com> Date: Fri, 27 Sep 2024 14:20:17 +0800 Subject: [PATCH] refactor: update Callback to an abstract class --- api/core/model_runtime/callbacks/base_callback.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/api/core/model_runtime/callbacks/base_callback.py b/api/core/model_runtime/callbacks/base_callback.py index 92da53c9a464df..6bd9325785a2da 100644 --- a/api/core/model_runtime/callbacks/base_callback.py +++ b/api/core/model_runtime/callbacks/base_callback.py @@ -1,3 +1,4 @@ +from abc import ABC, abstractmethod from typing import Optional from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk @@ -13,7 +14,7 @@ } -class Callback: +class Callback(ABC): """ Base class for callbacks. Only for LLM. @@ -21,6 +22,7 @@ class Callback: raise_error: bool = False + @abstractmethod def on_before_invoke( self, llm_instance: AIModel, @@ -48,6 +50,7 @@ def on_before_invoke( """ raise NotImplementedError() + @abstractmethod def on_new_chunk( self, llm_instance: AIModel, @@ -77,6 +80,7 @@ def on_new_chunk( """ raise NotImplementedError() + @abstractmethod def on_after_invoke( self, llm_instance: AIModel, @@ -106,6 +110,7 @@ def on_after_invoke( """ raise NotImplementedError() + @abstractmethod def on_invoke_error( self, llm_instance: AIModel,