From 33eb4f26259698e51fa71a5268cfb9adddf375c0 Mon Sep 17 00:00:00 2001 From: Praveenk8051 Date: Sat, 25 Jan 2025 07:39:54 +0100 Subject: [PATCH] feat(Add Module class documentation and interface example) --- Readme.md | 4 ++++ docs/module.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 docs/module.md diff --git a/Readme.md b/Readme.md index 20f355e..33547e6 100644 --- a/Readme.md +++ b/Readme.md @@ -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. +## 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 For more detailed information on how to use Agentic Security, including advanced features and customization options, please refer to the official documentation. diff --git a/docs/module.md b/docs/module.md new file mode 100644 index 0000000..4654b3c --- /dev/null +++ b/docs/module.md @@ -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()) +``` +