Core API Reference¶
This page provides detailed documentation for the core GUM module.
Main Class¶
gum.gum
¶
Attributes¶
Classes¶
gum(user_name: str, model: str, *observers: Observer, propose_prompt: str | None = None, similar_prompt: str | None = None, revise_prompt: str | None = None, audit_prompt: str | None = None, data_directory: str = '~/.cache/gum', db_name: str = 'gum.db', max_concurrent_updates: int = 4, verbosity: int = logging.INFO, audit_enabled: bool = False, api_base: str | None = None, api_key: str | None = None)
¶
A class for managing general user models.
This class provides functionality for observing user behavior, generating and managing propositions about user behavior, and maintaining relationships between observations and propositions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_name
|
str
|
The name of the user being modeled. |
required |
*observers
|
Observer
|
Variable number of observer instances to track user behavior. |
()
|
propose_prompt
|
str
|
Custom prompt for proposition generation. |
None
|
similar_prompt
|
str
|
Custom prompt for similarity analysis. |
None
|
revise_prompt
|
str
|
Custom prompt for proposition revision. |
None
|
audit_prompt
|
str
|
Custom prompt for auditing. |
None
|
data_directory
|
str
|
Directory for storing data. Defaults to "~/.cache/gum". |
'~/.cache/gum'
|
db_name
|
str
|
Name of the database file. Defaults to "gum.db". |
'gum.db'
|
max_concurrent_updates
|
int
|
Maximum number of concurrent updates. Defaults to 4. |
4
|
verbosity
|
int
|
Logging verbosity level. Defaults to logging.INFO. |
INFO
|
audit_enabled
|
bool
|
Whether to enable auditing. Defaults to False. |
False
|
Source code in gum/gum.py
Attributes¶
Session = None
instance-attribute
¶
audit_enabled = audit_enabled
instance-attribute
¶
audit_prompt = audit_prompt or AUDIT_PROMPT
instance-attribute
¶
client = AsyncOpenAI(base_url=api_base or os.getenv('GUM_LM_API_BASE'), api_key=api_key or os.getenv('GUM_LM_API_KEY') or os.getenv('OPENAI_API_KEY') or 'None')
instance-attribute
¶
engine = None
instance-attribute
¶
logger = logging.getLogger('gum')
instance-attribute
¶
model = model
instance-attribute
¶
observers: list[Observer] = list(observers)
instance-attribute
¶
propose_prompt = propose_prompt or PROPOSE_PROMPT
instance-attribute
¶
revise_prompt = revise_prompt or REVISE_PROMPT
instance-attribute
¶
similar_prompt = similar_prompt or SIMILAR_PROMPT
instance-attribute
¶
update_handlers: list[Callable[[Observer, Update], None]] = []
instance-attribute
¶
user_name = user_name
instance-attribute
¶
Functions¶
__aenter__()
async
¶
Async context manager entry point.
Returns:
Name | Type | Description |
---|---|---|
gum |
The instance of the gum class. |
__aexit__(exc_type, exc, tb)
async
¶
Async context manager exit point.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exc_type
|
The type of exception if any. |
required | |
exc
|
The exception instance if any. |
required | |
tb
|
The traceback if any. |
required |
Source code in gum/gum.py
add_observer(observer: Observer)
¶
Add an observer to track user behavior.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observer
|
Observer
|
The observer to add. |
required |
connect_db()
async
¶
Initialize the database connection if not already connected.
query(user_query: str, *, limit: int = 3, mode: str = 'OR', start_time: datetime | None = None, end_time: datetime | None = None) -> list[tuple[Proposition, float]]
async
¶
Query the database for propositions matching the user query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_query
|
str
|
The query string to search for. |
required |
limit
|
int
|
Maximum number of results to return. Defaults to 3. |
3
|
mode
|
str
|
Search mode ("OR" or "AND"). Defaults to "OR". |
'OR'
|
start_time
|
datetime
|
Start time for filtering results. Defaults to None. |
None
|
end_time
|
datetime
|
End time for filtering results. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
list[tuple[Proposition, float]]
|
list[tuple[Proposition, float]]: List of tuples containing propositions and their relevance scores. |
Source code in gum/gum.py
register_update_handler(fn: Callable[[Observer, Update], None])
¶
Register a custom update handler function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn
|
Callable[[Observer, Update], None]
|
The handler function to register. |
required |
remove_observer(observer: Observer)
¶
Remove an observer from tracking.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
observer
|
Observer
|
The observer to remove. |
required |
start_update_loop()
¶
stop_update_loop()
async
¶
Stop the asynchronous update loop and clean up resources.