From c2671fd6f127c8c810a3b9c4b49d1a069b400552 Mon Sep 17 00:00:00 2001 From: Alexander Myasoedov Date: Sun, 9 Mar 2025 21:23:13 +0200 Subject: [PATCH] fix(minor docs update): --- docs/http_spec.md | 30 +++++++++++++----------------- docs/probe_data.md | 26 ++++++++------------------ 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/docs/http_spec.md b/docs/http_spec.md index ff7ff0e..6623c5a 100644 --- a/docs/http_spec.md +++ b/docs/http_spec.md @@ -33,7 +33,7 @@ The `LLMSpec` class is the core of the HTTP specification. It provides the follo ### Methods - **`from_string(http_spec: str) -> LLMSpec`**: Parses an HTTP specification string into an `LLMSpec` object. -- **`validate(prompt: str, encoded_image: str, encoded_audio: str, files: dict) -> None`**: Validates the request parameters based on the specified modality. +- **`validate(prompt: str, encoded_image: str, encoded_audio: str, files: dict) -> null`**: Validates the request parameters based on the specified modality. - **`probe(prompt: str, encoded_image: str = "", encoded_audio: str = "", files: dict = {}) -> httpx.Response`**: Sends an HTTP request using the specified parameters. - **`verify() -> httpx.Response`**: Verifies the HTTP specification by sending a test request. @@ -52,12 +52,11 @@ Authorization: Bearer sk-xxxxxxxxx Content-Type: application/json { - "model": "gpt-3.5-turbo", - "messages": [{"role": "user", "content": "<>"}], - "temperature": 0.7 + "model": "gpt-3.5-turbo", + "messages": [{"role": "user", "content": "<>"}], + "temperature": 0.7 } """ - spec = LLMSpec.from_string(http_spec) response = await spec.probe("What is the capital of France?") ``` @@ -71,12 +70,11 @@ Authorization: Bearer sk-xxxxxxxxx Content-Type: application/json { - "model": "gpt-4-vision-preview", - "messages": [{"role": "user", "content": "What is in this image? <>"}], - "temperature": 0.7 + "model": "gpt-4-vision-preview", + "messages": [{"role": "user", "content": "What is in this image? <>"}], + "temperature": 0.7 } """ - spec = LLMSpec.from_string(http_spec) encoded_image = encode_image_base64_by_url("https://example.com/image.jpg") response = await spec.probe("What is in this image?", encoded_image=encoded_image) @@ -91,12 +89,11 @@ Authorization: Bearer sk-xxxxxxxxx Content-Type: application/json { - "model": "whisper-large-v3", - "messages": [{"role": "user", "content": "Transcribe this audio: <>"}], - "temperature": 0.7 + "model": "whisper-large-v3", + "messages": [{"role": "user", "content": "Transcribe this audio: <>"}], + "temperature": 0.7 } """ - spec = LLMSpec.from_string(http_spec) encoded_audio = encode_audio_base64_by_url("https://example.com/audio.mp3") response = await spec.probe("Transcribe this audio:", encoded_audio=encoded_audio) @@ -111,12 +108,11 @@ Authorization: Bearer sk-xxxxxxxxx Content-Type: multipart/form-data { - "model": "gpt-3.5-turbo", - "messages": [{"role": "user", "content": "Process this file: <>"}], - "temperature": 0.7 + "model": "gpt-3.5-turbo", + "messages": [{"role": "user", "content": "Process this file: <>"}], + "temperature": 0.7 } """ - spec = LLMSpec.from_string(http_spec) files = {"file": ("document.txt", open("document.txt", "rb"))} response = await spec.probe("Process this file:", files=files) diff --git a/docs/probe_data.md b/docs/probe_data.md index 4a3b6c2..a5e59b8 100644 --- a/docs/probe_data.md +++ b/docs/probe_data.md @@ -54,20 +54,15 @@ The `probe_data` module is a core component of the Agentic Security project, res - **Classes:** - `PromptSelectionInterface`: Abstract base class for prompt selection strategies. - - Methods: - `select_next_prompt(current_prompt: str, passed_guard: bool) -> str`: Selects next prompt - `select_next_prompts(current_prompt: str, passed_guard: bool) -> list[str]`: Selects multiple prompts - - `update_rewards(previous_prompt: str, current_prompt: str, reward: float, passed_guard: bool) -> None`: Updates rewards - + - `update_rewards(previous_prompt: str, current_prompt: str, reward: float, passed_guard: bool) -> null`: Updates rewards - `RandomPromptSelector`: Basic random selection with history tracking. - - Parameters: - `prompts: list[str]`: List of available prompts - `history_size: int = 3`: Size of history to prevent cycles - - `CloudRLPromptSelector`: Cloud-based RL implementation with fallback. - - Parameters: - `prompts: list[str]`: List of available prompts - `api_url: str`: URL of RL service @@ -75,9 +70,7 @@ The `probe_data` module is a core component of the Agentic Security project, res - `history_size: int = 300`: Size of history - `timeout: int = 5`: Request timeout - `run_id: str = ""`: Unique run identifier - - `QLearningPromptSelector`: Local Q-learning implementation. - - Parameters: - `prompts: list[str]`: List of available prompts - `learning_rate: float = 0.1`: Learning rate @@ -86,13 +79,11 @@ The `probe_data` module is a core component of the Agentic Security project, res - `exploration_decay: float = 0.995`: Exploration decay rate - `min_exploration: float = 0.01`: Minimum exploration rate - `history_size: int = 300`: Size of history - - - `Module`: Main class that uses CloudRLPromptSelector. - - - Parameters: - - `prompt_groups: list[str]`: Groups of prompts - - `tools_inbox: asyncio.Queue`: Queue for tool communication - - `opts: dict = {}`: Configuration options +- **Module**: Main class that uses CloudRLPromptSelector. + - Parameters: + - `prompt_groups: list[str]`: Groups of prompts + - `tools_inbox: asyncio.Queue`: Queue for tool communication + - `opts: dict = {}`: Configuration options ## Usage Examples @@ -119,10 +110,9 @@ from agentic_security.probe_data.modules.rl_model import QLearningPromptSelector prompts = ["What is AI?", "Explain machine learning"] selector = QLearningPromptSelector(prompts) - current_prompt = "What is AI?" -next_prompt = selector.select_next_prompt(current_prompt, passed_guard=True) -selector.update_rewards(current_prompt, next_prompt, reward=1.0, passed_guard=True) +next_prompt = selector.select_next_prompt(current_prompt, passed_guard=true) +selector.update_rewards(current_prompt, next_prompt, reward=1.0, passed_guard=true) ``` ## Conclusion