Browse Source

refactor: update Callback to an abstract class (#8868)

tags/0.9.0
zhuhao 1 year ago
parent
commit
f97607370a
No account linked to committer's email address
1 changed files with 6 additions and 1 deletions
  1. 6
    1
      api/core/model_runtime/callbacks/base_callback.py

+ 6
- 1
api/core/model_runtime/callbacks/base_callback.py View File

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,

Loading…
Cancel
Save