feat(Add Module class documentation and interface example)

This commit is contained in:
Praveenk8051 committed 2025-01-25 07:39:54 +01:00
1 parent f7f4ee840b
commit 33eb4f2625
2 files changed
+49

No files matched your search

+4
View File
@@ -376,6 +376,10 @@ This sample GitHub Action is designed to perform automated security scans
This setup ensures a continuous integration approach towards maintaining security in your projects. This setup ensures a continuous integration approach towards maintaining security in your projects.
## Module Class
The `Module` class is designed to manage prompt processing and interaction with external AI models and tools. It supports fetching, processing, and posting prompts asynchronously for model vulnerabilities. Check out [module.md](https://github.com/msoedov/agentic_security/blob/main/docs/module.md) for details.
## Documentation ## Documentation
For more detailed information on how to use Agentic Security, including advanced features and customization options, please refer to the official documentation. For more detailed information on how to use Agentic Security, including advanced features and customization options, please refer to the official documentation.
+45
View File
@@ -0,0 +1,45 @@
## Module Interface Documentation
The `Module` class interface provides a standardized way to create and use modules in the `agentic_security` project.
Here is an example of a module that implements the `ModuleProtocol` interface. This example shows how to create a module that processes prompts and sends results to a queue.
```python
from typing import List, Dict, Any, AsyncGenerator
import asyncio
from .module_protocol import ModuleProtocol
class ModuleProtocol(ModuleProtocol):
def __init__(self, prompt_groups: List[Any], tools_inbox: asyncio.Queue, opts: Dict[str, Any]):
self.prompt_groups = prompt_groups
self.tools_inbox = tools_inbox
self.opts = opts
async def apply(self) -> AsyncGenerator[str, None]:
for group in self.prompt_groups:
await asyncio.sleep(1)
result = f"Processed {group}"
await self.tools_inbox.put(result)
yield result
```
#### Usage Example
```python
import asyncio
import ModuleProtocol
tools_inbox = asyncio.Queue()
prompt_groups = ["group1", "group2"]
opts = {"max_prompts": 1000, "batch_size": 100}
module = ModuleProtocol(prompt_groups, tools_inbox, opts)
async def main():
async for result in module.apply():
print(result)
asyncio.run(main())
```