Base
base
Base classes used across callbacks submodules
Callback
Bases: ABC
Base class for a callback in LLMeter
Callbacks support extending LLMeter functionality by running additional code at defined points in the test Run lifecycle: For example, logging experiments to MLFlow, or estimating costs associated with test runs or individual model invocations.
A Callback object may implement multiple of the defined lifecycle hooks (such as
before_invoke, after_run, etc). Callbacks must support serializing their configuration to
a file (by implementing save_to_file), and loading back (via load_from_file).
after_invoke
async
after_invoke(response)
Lifecycle hook called after every Endpoint.invoke() request in a Run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
InvocationResponse
|
The InvocationResponse (already annotated with initial information e.g. timing and token counts) |
required |
Returns:
None: If you'd like to add information to the response logged in the Run, modify it
in-place.
Source code in llmeter/callbacks/base.py
38 39 40 41 42 43 44 45 46 47 48 | |
after_run
async
after_run(result)
Lifecycle hook called at the end of each Runner.run()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
Result
|
The Result of the overall run (including all individual model invocations) |
required |
Returns:
None: If you'd like to modify the run result, edit the argument in-place.
Source code in llmeter/callbacks/base.py
63 64 65 66 67 68 69 70 71 | |
before_invoke
async
before_invoke(payload)
Lifecycle hook called before every Endpoint.invoke() request in a Run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
dict
|
The payload to be sent to the endpoint. |
required |
Returns:
None: If you'd like to modify the request payload, edit the dictionary in-place.
Source code in llmeter/callbacks/base.py
28 29 30 31 32 33 34 35 36 | |
before_run
async
before_run(run_config)
Lifecycle hook called at the start of each Runner.run()
This function will be called after the initial Runner configuration is prepared, and before creating clients or starting to send requests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_config
|
_RunConfig
|
The configuration that will be used to run the test. |
required |
Returns: None: If you'd like to modify the current run's configuration, edit it in-place.
Source code in llmeter/callbacks/base.py
50 51 52 53 54 55 56 57 58 59 60 61 | |
load_from_file
staticmethod
load_from_file(path)
Load (any type of) Callback from file
Callback.load_from_file() attempts to detect the type of Callback saved in a given file,
and use the relevant implementation's _load_from_file method to load it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
PathLike | str
|
(Local or Cloud) path where the callback is saved |
required |
Returns:
callback: A loaded Callback - for example an MlflowCallback.
Source code in llmeter/callbacks/base.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
save_to_file
save_to_file(path)
Save this Callback to file
Individual Callbacks implement this method to save their configuration to a file that will
be re-loadable with the equivalent _load_from_file() method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
PathLike | str
|
(Local or Cloud) path where the callback is saved |
required |
Source code in llmeter/callbacks/base.py
73 74 75 76 77 78 79 80 81 82 | |