Evaluate a prompt with the PromptArmor API. Args: prompt: the content that you are sending to an LLM session_id: the session id for set of calls to the LLM mode: the mode of the evaluation. Either "input" or "output" source(optional) : the source of this cont
(prompt, session_id: str, mode: str, source=None, destination=None)
| 8 | |
| 9 | |
| 10 | async def evaluate(prompt, session_id: str, mode: str, source=None, destination=None) -> bool: |
| 11 | """ |
| 12 | Evaluate a prompt with the PromptArmor API. |
| 13 | Args: |
| 14 | prompt: the content that you are sending to an LLM |
| 15 | session_id: the session id for set of calls to the LLM |
| 16 | mode: the mode of the evaluation. Either "input" or "output" |
| 17 | source(optional) : the source of this content that you are sending to the LLM |
| 18 | destination (optional) : the destination of this output that will come from the LLM |
| 19 | Returns (bool): |
| 20 | The response from the API. {"containsInjection":true} |
| 21 | """ |
| 22 | if mode not in ["input", "output"]: |
| 23 | raise ValueError("mode must be either 'input' or 'output'") |
| 24 | |
| 25 | if mode == "input": |
| 26 | url = "https://api.aidr.promptarmor.com/v1/analyze/input" |
| 27 | else: |
| 28 | url = "https://api.aidr.promptarmor.com/v1/analyze/output" |
| 29 | |
| 30 | promptarmor_headers = { |
| 31 | "PromptArmor-Auth": f"Bearer {API_KEY}", |
| 32 | # The session ID is unique to each user session(e.g. a workflow or conversation) |
| 33 | "PromptArmor-Session-ID": session_id, |
| 34 | "Content-Type": "application/json", |
| 35 | } |
| 36 | |
| 37 | data = {"content": prompt, "source": source, "destination": destination} |
| 38 | |
| 39 | async with httpx.AsyncClient() as async_client: |
| 40 | response = await async_client.post(url, headers=promptarmor_headers, json=data) |
| 41 | |
| 42 | return response.json().get("detection", None) |
| 43 | |
| 44 | |
| 45 | async def get_promptarmor_flag(prompt, completion, session_id) -> bool | None: |
no test coverage detected
searching dependent graphs…