Removing extra StdOutCallbackHandler overridden methods (#14136)

Unnecessarily overridden methods:

- Give the idea the subclass is doing something special (when it isn't)
- Block CTRL-click to the actual method

This PR removes some unnecessarily overridden methods in
`StdOutCallbackHandler`

Supercedes https://github.com/langchain-ai/langchain/pull/12858
This commit is contained in:
James Braza 2023-12-03 12:38:49 -05:00 committed by GitHub
parent ac449f186b
commit 3833882ab7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,14 +1,13 @@
"""Callback Handler that prints to std out.""" """Callback Handler that prints to std out."""
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING, Any, Dict, List, Optional from typing import TYPE_CHECKING, Any, Dict, Optional
from langchain_core.callbacks.base import BaseCallbackHandler from langchain_core.callbacks.base import BaseCallbackHandler
from langchain_core.utils import print_text from langchain_core.utils import print_text
if TYPE_CHECKING: if TYPE_CHECKING:
from langchain_core.agents import AgentAction, AgentFinish from langchain_core.agents import AgentAction, AgentFinish
from langchain_core.outputs import LLMResult
class StdOutCallbackHandler(BaseCallbackHandler): class StdOutCallbackHandler(BaseCallbackHandler):
@ -18,24 +17,6 @@ class StdOutCallbackHandler(BaseCallbackHandler):
"""Initialize callback handler.""" """Initialize callback handler."""
self.color = color self.color = color
def on_llm_start(
self, serialized: Dict[str, Any], prompts: List[str], **kwargs: Any
) -> None:
"""Print out the prompts."""
pass
def on_llm_end(self, response: LLMResult, **kwargs: Any) -> None:
"""Do nothing."""
pass
def on_llm_new_token(self, token: str, **kwargs: Any) -> None:
"""Do nothing."""
pass
def on_llm_error(self, error: BaseException, **kwargs: Any) -> None:
"""Do nothing."""
pass
def on_chain_start( def on_chain_start(
self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any
) -> None: ) -> None:
@ -47,19 +28,6 @@ class StdOutCallbackHandler(BaseCallbackHandler):
"""Print out that we finished a chain.""" """Print out that we finished a chain."""
print("\n\033[1m> Finished chain.\033[0m") print("\n\033[1m> Finished chain.\033[0m")
def on_chain_error(self, error: BaseException, **kwargs: Any) -> None:
"""Do nothing."""
pass
def on_tool_start(
self,
serialized: Dict[str, Any],
input_str: str,
**kwargs: Any,
) -> None:
"""Do nothing."""
pass
def on_agent_action( def on_agent_action(
self, action: AgentAction, color: Optional[str] = None, **kwargs: Any self, action: AgentAction, color: Optional[str] = None, **kwargs: Any
) -> Any: ) -> Any:
@ -81,10 +49,6 @@ class StdOutCallbackHandler(BaseCallbackHandler):
if llm_prefix is not None: if llm_prefix is not None:
print_text(f"\n{llm_prefix}") print_text(f"\n{llm_prefix}")
def on_tool_error(self, error: BaseException, **kwargs: Any) -> None:
"""Do nothing."""
pass
def on_text( def on_text(
self, self,
text: str, text: str,