refactor: update Callback to an abstract class (#8868)
This commit is contained in:
parent
850492dafa
commit
f97607370a
1 changed files with 6 additions and 1 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
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
|
||||||
|
|
@ -13,7 +14,7 @@ _TEXT_COLOR_MAPPING = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Callback:
|
class Callback(ABC):
|
||||||
"""
|
"""
|
||||||
Base class for callbacks.
|
Base class for callbacks.
|
||||||
Only for LLM.
|
Only for LLM.
|
||||||
|
|
@ -21,6 +22,7 @@ class Callback:
|
||||||
|
|
||||||
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,
|
||||||
|
|
@ -48,6 +50,7 @@ class Callback:
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def on_new_chunk(
|
def on_new_chunk(
|
||||||
self,
|
self,
|
||||||
llm_instance: AIModel,
|
llm_instance: AIModel,
|
||||||
|
|
@ -77,6 +80,7 @@ class Callback:
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def on_after_invoke(
|
def on_after_invoke(
|
||||||
self,
|
self,
|
||||||
llm_instance: AIModel,
|
llm_instance: AIModel,
|
||||||
|
|
@ -106,6 +110,7 @@ class Callback:
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def on_invoke_error(
|
def on_invoke_error(
|
||||||
self,
|
self,
|
||||||
llm_instance: AIModel,
|
llm_instance: AIModel,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue