Skip to content

Commit

Permalink
refactor: update Callback to an abstract class (langgenius#8868)
Browse files Browse the repository at this point in the history
  • Loading branch information
hwzhuhao authored and JunXu01 committed Nov 9, 2024
1 parent 072d8f1 commit 2fecb22
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion api/core/model_runtime/callbacks/base_callback.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from abc import ABC, abstractmethod
from typing import Optional

from core.model_runtime.entities.llm_entities import LLMResult, LLMResultChunk
Expand All @@ -13,14 +14,15 @@
}


class Callback:
class Callback(ABC):
"""
Base class for callbacks.
Only for LLM.
"""

raise_error: bool = False

@abstractmethod
def on_before_invoke(
self,
llm_instance: AIModel,
Expand Down Expand Up @@ -48,6 +50,7 @@ def on_before_invoke(
"""
raise NotImplementedError()

@abstractmethod
def on_new_chunk(
self,
llm_instance: AIModel,
Expand Down Expand Up @@ -77,6 +80,7 @@ def on_new_chunk(
"""
raise NotImplementedError()

@abstractmethod
def on_after_invoke(
self,
llm_instance: AIModel,
Expand Down Expand Up @@ -106,6 +110,7 @@ def on_after_invoke(
"""
raise NotImplementedError()

@abstractmethod
def on_invoke_error(
self,
llm_instance: AIModel,
Expand Down

0 comments on commit 2fecb22

Please sign in to comment.