Implement hooking system for classes and methods. Cleanup of code

This commit is contained in:
2024-05-03 17:32:45 -03:00
parent 87bb6302ff
commit 1bd9bd62c5
10 changed files with 542 additions and 1914 deletions

View File

@ -169,8 +169,8 @@ The `modify` method allows you to alter instances of a class at the time they ar
connapp.config.modify(modify_config)
```
#### Implementing Hooks with `register_pre_hook` and `register_post_hook`
These methods allow you to define custom logic to be executed before (`register_pre_hook`) or after (`register_post_hook`) the main logic of a method. This is particularly useful for logging, auditing, preprocessing inputs, postprocessing outputs or adding functionalities.
#### Implementing Method Hooks
There are 2 methods that allows you to define custom logic to be executed before (`register_pre_hook`) or after (`register_post_hook`) the main logic of a method. This is particularly useful for logging, auditing, preprocessing inputs, postprocessing outputs or adding functionalities.
- **Usage**: Register hooks to methods to execute additional logic before or after the main method execution.
- **Registration Methods Signature**:
@ -305,7 +305,7 @@ import connpy
conf = connpy.configfile()
organization = 'openai-org'
api_key = "openai-key"
myia = ai(conf, organization, api_key)
myia = connpy.ai(conf, organization, api_key)
input = "go to router 1 and get me the full configuration"
result = myia.ask(input, dryrun = False)
print(result)