| from abc import ABC, abstractmethod | |||||
| from typing import Optional | from typing import Optional | ||||
| from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk | from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk | ||||
| } | } | ||||
| class Callback: | |||||
| class Callback(ABC): | |||||
| """ | """ | ||||
| Base class for callbacks. | Base class for callbacks. | ||||
| Only for LLM. | Only for LLM. | ||||
| raise_error: bool = False | raise_error: bool = False | ||||
| @abstractmethod | |||||
| def on_before_invoke( | def on_before_invoke( | ||||
| self, | self, | ||||
| llm_instance: AIModel, | llm_instance: AIModel, | ||||
| """ | """ | ||||
| raise NotImplementedError() | raise NotImplementedError() | ||||
| @abstractmethod | |||||
| def on_new_chunk( | def on_new_chunk( | ||||
| self, | self, | ||||
| llm_instance: AIModel, | llm_instance: AIModel, | ||||
| """ | """ | ||||
| raise NotImplementedError() | raise NotImplementedError() | ||||
| @abstractmethod | |||||
| def on_after_invoke( | def on_after_invoke( | ||||
| self, | self, | ||||
| llm_instance: AIModel, | llm_instance: AIModel, | ||||
| """ | """ | ||||
| raise NotImplementedError() | raise NotImplementedError() | ||||
| @abstractmethod | |||||
| def on_invoke_error( | def on_invoke_error( | ||||
| self, | self, | ||||
| llm_instance: AIModel, | llm_instance: AIModel, |