From 959101a61892f52ece9a3df4d864495c16066431 Mon Sep 17 00:00:00 2001 From: Raja Sekhar Rao Dheekonda <43563047+rdheekonda@users.noreply.github.com> Date: Mon, 29 Apr 2024 11:22:50 -0700 Subject: [PATCH] FIX: used PromptRequestResponse.converted_value instead PromptRequestResponse.converted_value_data_type in GPTV target (#179) Co-authored-by: Raja Sekhar Rao Dheekonda --- doc/code/targets/gpt_v_target.ipynb | 22 ++++++++----------- .../azure_openai_gptv_chat_target.py | 5 ++++- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/doc/code/targets/gpt_v_target.ipynb b/doc/code/targets/gpt_v_target.ipynb index a1f3fde9a..85db71cdc 100644 --- a/doc/code/targets/gpt_v_target.ipynb +++ b/doc/code/targets/gpt_v_target.ipynb @@ -92,17 +92,13 @@ "name": "stdout", "output_type": "stream", "text": [ - "None: assistant: The picture shows a chart with the title \"PyRIT Components\" at the top. The chart is divided into two columns, with \"Interface\" on the left and \"Implementation\" on the right. Underneath the columns, there are five rows, each labeled with a different component of PyRIT. \n", + "None: assistant: The picture is a table listing the components of PyRIT, which stands for \"Python Rapid Information Toolkit\". The table has two columns labeled \"Interface\" and \"Implementation\". Under the Interface column, there are five rows: Target, Datasets, Scoring Engine, Attack Strategy and Memory. Each row in the Interface column has corresponding implementations in the Implementation column.\n", "\n", - "The first row is labeled \"Target\" and includes two types of implementation: \"Local,\" which specifies local model (e.g., ONNX), and \"Remote,\" which mentions API or web app.\n", - "\n", - "The second row is labeled \"Datasets\" and includes two types of implementation as well: \"Static,\" which specifies prompts, and \"Dynamic,\" which mentions prompt templates.\n", - "\n", - "The third row is labeled \"Scoring Engine\" and includes only one type of implementation: PyRIT itself for self-evaluation and API for existing content classifiers.\n", - "\n", - "The fourth row is labeled \"Attack Strategy\" and also has two implementations: \"Single Turn,\" which uses static prompts, and \"Multi-Turn,\" which involves multiple conversations using prompt templates.\n", - "\n", - "The last row is labeled “Memory” with “Storage” specifying JSON and database. There is also “Utils,” mentioning conversation, retrieval and storage, memory sharing, data analysis.\n" + "For the Target interface, there are two types of implementation: Local (local model e.g., ONNX) and Remote (API or web app). \n", + "For the Datasets interface, there are two types of implementation: Static prompts and Dynamic prompt templates.\n", + "For the Scoring Engine interface, there is one type of implementation: PyRIT itself with self-evaluation and API with existing content classifiers.\n", + "For the Attack Strategy interface, there are two types of implementation: Single Turn using static prompts and Multi Turn involving multiple conversations using prompt templates.\n", + "For the Memory interface, there are several types of implementation including Storage (JSON Database), Utils for conversation retrieval and storage, memory sharing and data analysis.\n" ] } ], @@ -126,9 +122,9 @@ "cell_metadata_filter": "-all" }, "kernelspec": { - "display_name": "pyrit-311", + "display_name": "pyrit-dev", "language": "python", - "name": "pyrit-311" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -140,7 +136,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.10.13" } }, "nbformat": 4, diff --git a/pyrit/prompt_target/prompt_chat_target/azure_openai_gptv_chat_target.py b/pyrit/prompt_target/prompt_chat_target/azure_openai_gptv_chat_target.py index d8e5b2310..47f493e43 100644 --- a/pyrit/prompt_target/prompt_chat_target/azure_openai_gptv_chat_target.py +++ b/pyrit/prompt_target/prompt_chat_target/azure_openai_gptv_chat_target.py @@ -196,6 +196,7 @@ async def send_prompt_async(self, *, prompt_request: PromptRequestResponse) -> P Returns: PromptRequestResponse: The updated conversation entry with the response from the prompt target. """ + self.validate_request(prompt_request=prompt_request) request: PromptRequestPiece = prompt_request.request_pieces[0] prompt_req_res_entries = self._memory.get_conversation(conversation_id=request.conversation_id) @@ -300,7 +301,9 @@ def validate_request(self, *, prompt_request: PromptRequestResponse) -> None: if len(prompt_request.request_pieces) > 2: raise ValueError("This target only supports a two prompt request pieces text and image_path.") - converted_prompt_data_types = [request_piece.converted_value for request_piece in prompt_request.request_pieces] + converted_prompt_data_types = [ + request_piece.converted_value_data_type for request_piece in prompt_request.request_pieces + ] for prompt_data_type in converted_prompt_data_types: if prompt_data_type not in ["text", "image_path"]: raise ValueError("This target only supports text and image_path.")