tools.dependency_injection
BaseContext
Base class for context classes.
This is the base class for defining various context types that may be used throughout the application. It serves as a parent for specific context classes.
ChatContext
ChatContext class that extends BaseContext.
This class is used to represent a chat context that holds a list of messages.
It inherits from BaseContext
and adds the messages
attribute.
__init__
Initializes the ChatContext with an agent.
Arguments:
agent
- The agent to use for retrieving chat messages.
chat_messages
The messages in the chat.
Returns:
A dictionary of agents and their messages.
last_message
The last message in the chat.
Returns:
The last message in the chat.
Depends
Creates a dependency for injection based on the provided context or type.
Arguments:
x
- The context or dependency to be injected.
Returns:
A FastDepends object that will resolve the dependency for injection.
get_context_params
Gets the names of the context parameters in a function signature.
Arguments:
func
- The function to inspect for context parameters.subclass
- The subclass to search for.
Returns:
A list of parameter names that are instances of the specified subclass.
Field
Represents a description field for use in type annotations.
This class is used to store a description for an annotated field, often used for documenting or validating fields in a context or data model.
__init__
Initializes the Field with a description.
Arguments:
description
- The description text for the field.
inject_params
Injects parameters into a function, removing injected dependencies from its signature.
This function is used to modify a function by injecting dependencies and removing injected parameters from the function’s signature.
Arguments:
f
- The function to modify with dependency injection.
Returns:
The modified function with injected dependencies and updated signature.