docstrings callbacks (#11456)

Added missed docstrings to the `callbacks/`

---------

Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
Leonid Ganeline 2023-10-05 17:13:14 -07:00 committed by GitHub
parent 3c7653bf0f
commit d17416ec79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 4 deletions

View File

@ -250,7 +250,7 @@ class BaseCallbackHandler(
CallbackManagerMixin, CallbackManagerMixin,
RunManagerMixin, 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 raise_error: bool = False
@ -288,7 +288,7 @@ class BaseCallbackHandler(
class AsyncCallbackHandler(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( async def on_llm_start(
self, self,

View File

@ -17,6 +17,8 @@ from langchain.schema import (
class LabelStudioMode(Enum): class LabelStudioMode(Enum):
"""Label Studio mode enumerator."""
PROMPT = "prompt" PROMPT = "prompt"
CHAT = "chat" CHAT = "chat"
@ -24,6 +26,13 @@ class LabelStudioMode(Enum):
def get_default_label_configs( def get_default_label_configs(
mode: Union[str, LabelStudioMode] mode: Union[str, LabelStudioMode]
) -> Tuple[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 = { _default_label_configs = {
LabelStudioMode.PROMPT.value: """ LabelStudioMode.PROMPT.value: """
<View> <View>

View File

@ -19,6 +19,8 @@ user_props_ctx = ContextVar[Union[str, None]]("user_props_ctx", default=None)
class UserContextManager: class UserContextManager:
"""Context manager for LLMonitor user context."""
def __init__(self, user_id: str, user_props: Any = None) -> None: def __init__(self, user_id: str, user_props: Any = None) -> None:
user_ctx.set(user_id) user_ctx.set(user_id)
user_props_ctx.set(user_props) user_props_ctx.set(user_props)
@ -32,6 +34,15 @@ class UserContextManager:
def identify(user_id: str, user_props: Any = None) -> 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) 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): class LLMonitorCallbackHandler(BaseCallbackHandler):
"""Initializes the `LLMonitorCallbackHandler`. """Callback Handler for LLMonitor`.
#### Parameters: #### Parameters:
- `app_id`: The app id of the app you want to report to. Defaults to - `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. `None`, which means that `LLMONITOR_APP_ID` will be used.

View File

@ -1182,7 +1182,7 @@ class AsyncCallbackManagerForRetrieverRun(
class CallbackManager(BaseCallbackManager): class CallbackManager(BaseCallbackManager):
"""Callback manager that handles callbacks from langchain.""" """Callback manager that handles callbacks from LangChain."""
def on_llm_start( def on_llm_start(
self, self,
@ -1450,6 +1450,8 @@ class CallbackManager(BaseCallbackManager):
class CallbackManagerForChainGroup(CallbackManager): class CallbackManagerForChainGroup(CallbackManager):
"""Callback manager for the chain group."""
def __init__( def __init__(
self, self,
handlers: List[BaseCallbackHandler], handlers: List[BaseCallbackHandler],
@ -1784,6 +1786,8 @@ class AsyncCallbackManager(BaseCallbackManager):
class AsyncCallbackManagerForChainGroup(AsyncCallbackManager): class AsyncCallbackManagerForChainGroup(AsyncCallbackManager):
"""Async callback manager for the chain group."""
def __init__( def __init__(
self, self,
handlers: List[BaseCallbackHandler], handlers: List[BaseCallbackHandler],

View File

@ -25,6 +25,8 @@ from langchain.schema.output import ChatGenerationChunk, GenerationChunk
class LogEntry(TypedDict): class LogEntry(TypedDict):
"""A single entry in the run log."""
id: str id: str
"""ID of the sub-run.""" """ID of the sub-run."""
name: str name: str
@ -49,6 +51,8 @@ class LogEntry(TypedDict):
class RunState(TypedDict): class RunState(TypedDict):
"""State of the run."""
id: str id: str
"""ID of the run.""" """ID of the run."""
streamed_output: List[Any] streamed_output: List[Any]
@ -63,6 +67,8 @@ class RunState(TypedDict):
class RunLogPatch: class RunLogPatch:
"""A patch to the run log."""
ops: List[Dict[str, Any]] ops: List[Dict[str, Any]]
"""List of jsonpatch operations, which describe how to create the run state """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 from an empty dict. This is the minimal representation of the log, designed to
@ -94,6 +100,8 @@ class RunLogPatch:
class RunLog(RunLogPatch): class RunLog(RunLogPatch):
"""A run log."""
state: RunState state: RunState
"""Current state of the log, obtained from applying all ops in sequence.""" """Current state of the log, obtained from applying all ops in sequence."""
@ -118,6 +126,8 @@ class RunLog(RunLogPatch):
class LogStreamCallbackHandler(BaseTracer): class LogStreamCallbackHandler(BaseTracer):
"""A tracer that streams run logs to a stream."""
def __init__( def __init__(
self, self,
*, *,