log_middleware
¤
Logger Middleware
Classes:
Name | Description |
---|---|
LoggingMiddleware |
Creates a Simple logging middleware for a given task. |
LoggingMiddleware
¤
Bases: TaskMiddleware
Creates a Simple logging middleware for a given task.
Example
@openai.task(middlewares=[LoggingMiddleware])
def generate_a_poem(title: str):
'''
Generate a poem based on the given title
:return: The generated poem
'''
return declarai.magic("poem", title)
Methods:
Name | Description |
---|---|
__call__ |
Once the middleware is called, it executes the task and returns the result. |
_stream |
Re-streams the streaming response while adding the after sideeffects execution to the generator |
after |
After execution of the task, log the task details. |
before |
Before execution of the task, set the start time. |
__call__
¤
__call__() -> Any
Once the middleware is called, it executes the task and returns the result.
Before it executes the task, it calls the before
method, and after it executes the task, it calls the after
method.
Returns:
The result of the task
Source code in src/declarai/middleware/base.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
_stream
¤
_stream() -> Iterator
Re-streams the streaming response while adding the after sideeffects execution to the generator Returns:
Source code in src/declarai/middleware/base.py
27 28 29 30 31 32 33 34 35 |
|
after
¤
after(task: TaskType)
After execution of the task, log the task details. Args: task: the task to be logged
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
the task details like execution time, task name, template, compiled template, result, time. |
Source code in src/declarai/middleware/internal/log_middleware.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
before
¤
before(_)
Before execution of the task, set the start time.
Source code in src/declarai/middleware/internal/log_middleware.py
31 32 33 34 35 |
|