mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-08 06:00:41 +00:00
docstrings callbacks
(#11456)
Added missed docstrings to the `callbacks/` --------- Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
parent
3c7653bf0f
commit
d17416ec79
@ -250,7 +250,7 @@ class BaseCallbackHandler(
|
||||
CallbackManagerMixin,
|
||||
RunManagerMixin,
|
||||
):
|
||||
"""Base callback handler that can be used to handle callbacks from langchain."""
|
||||
"""Base callback handler that handles callbacks from LangChain."""
|
||||
|
||||
raise_error: bool = False
|
||||
|
||||
@ -288,7 +288,7 @@ class BaseCallbackHandler(
|
||||
|
||||
|
||||
class AsyncCallbackHandler(BaseCallbackHandler):
|
||||
"""Async callback handler that can be used to handle callbacks from langchain."""
|
||||
"""Async callback handler that handles callbacks from LangChain."""
|
||||
|
||||
async def on_llm_start(
|
||||
self,
|
||||
|
@ -17,6 +17,8 @@ from langchain.schema import (
|
||||
|
||||
|
||||
class LabelStudioMode(Enum):
|
||||
"""Label Studio mode enumerator."""
|
||||
|
||||
PROMPT = "prompt"
|
||||
CHAT = "chat"
|
||||
|
||||
@ -24,6 +26,13 @@ class LabelStudioMode(Enum):
|
||||
def get_default_label_configs(
|
||||
mode: Union[str, LabelStudioMode]
|
||||
) -> Tuple[str, LabelStudioMode]:
|
||||
"""Get default Label Studio configs for the given mode.
|
||||
|
||||
Parameters:
|
||||
mode: Label Studio mode ("prompt" or "chat")
|
||||
|
||||
Returns: Tuple of Label Studio config and mode
|
||||
"""
|
||||
_default_label_configs = {
|
||||
LabelStudioMode.PROMPT.value: """
|
||||
<View>
|
||||
|
@ -19,6 +19,8 @@ user_props_ctx = ContextVar[Union[str, None]]("user_props_ctx", default=None)
|
||||
|
||||
|
||||
class UserContextManager:
|
||||
"""Context manager for LLMonitor user context."""
|
||||
|
||||
def __init__(self, user_id: str, user_props: Any = None) -> None:
|
||||
user_ctx.set(user_id)
|
||||
user_props_ctx.set(user_props)
|
||||
@ -32,6 +34,15 @@ class UserContextManager:
|
||||
|
||||
|
||||
def identify(user_id: str, user_props: Any = None) -> UserContextManager:
|
||||
"""Builds an LLMonitor UserContextManager
|
||||
|
||||
Parameters:
|
||||
- `user_id`: The user id.
|
||||
- `user_props`: The user properties.
|
||||
|
||||
Returns:
|
||||
A context manager that sets the user context.
|
||||
"""
|
||||
return UserContextManager(user_id, user_props)
|
||||
|
||||
|
||||
@ -149,7 +160,8 @@ def _parse_lc_messages(messages: Union[List[BaseMessage], Any]) -> List[Dict[str
|
||||
|
||||
|
||||
class LLMonitorCallbackHandler(BaseCallbackHandler):
|
||||
"""Initializes the `LLMonitorCallbackHandler`.
|
||||
"""Callback Handler for LLMonitor`.
|
||||
|
||||
#### Parameters:
|
||||
- `app_id`: The app id of the app you want to report to. Defaults to
|
||||
`None`, which means that `LLMONITOR_APP_ID` will be used.
|
||||
|
@ -1182,7 +1182,7 @@ class AsyncCallbackManagerForRetrieverRun(
|
||||
|
||||
|
||||
class CallbackManager(BaseCallbackManager):
|
||||
"""Callback manager that handles callbacks from langchain."""
|
||||
"""Callback manager that handles callbacks from LangChain."""
|
||||
|
||||
def on_llm_start(
|
||||
self,
|
||||
@ -1450,6 +1450,8 @@ class CallbackManager(BaseCallbackManager):
|
||||
|
||||
|
||||
class CallbackManagerForChainGroup(CallbackManager):
|
||||
"""Callback manager for the chain group."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
handlers: List[BaseCallbackHandler],
|
||||
@ -1784,6 +1786,8 @@ class AsyncCallbackManager(BaseCallbackManager):
|
||||
|
||||
|
||||
class AsyncCallbackManagerForChainGroup(AsyncCallbackManager):
|
||||
"""Async callback manager for the chain group."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
handlers: List[BaseCallbackHandler],
|
||||
|
@ -25,6 +25,8 @@ from langchain.schema.output import ChatGenerationChunk, GenerationChunk
|
||||
|
||||
|
||||
class LogEntry(TypedDict):
|
||||
"""A single entry in the run log."""
|
||||
|
||||
id: str
|
||||
"""ID of the sub-run."""
|
||||
name: str
|
||||
@ -49,6 +51,8 @@ class LogEntry(TypedDict):
|
||||
|
||||
|
||||
class RunState(TypedDict):
|
||||
"""State of the run."""
|
||||
|
||||
id: str
|
||||
"""ID of the run."""
|
||||
streamed_output: List[Any]
|
||||
@ -63,6 +67,8 @@ class RunState(TypedDict):
|
||||
|
||||
|
||||
class RunLogPatch:
|
||||
"""A patch to the run log."""
|
||||
|
||||
ops: List[Dict[str, Any]]
|
||||
"""List of jsonpatch operations, which describe how to create the run state
|
||||
from an empty dict. This is the minimal representation of the log, designed to
|
||||
@ -94,6 +100,8 @@ class RunLogPatch:
|
||||
|
||||
|
||||
class RunLog(RunLogPatch):
|
||||
"""A run log."""
|
||||
|
||||
state: RunState
|
||||
"""Current state of the log, obtained from applying all ops in sequence."""
|
||||
|
||||
@ -118,6 +126,8 @@ class RunLog(RunLogPatch):
|
||||
|
||||
|
||||
class LogStreamCallbackHandler(BaseTracer):
|
||||
"""A tracer that streams run logs to a stream."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
|
Loading…
Reference in New Issue
Block a user