Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

OpenAI Completions - optional

Once you are configured, then you will be able to get completions for your text.

from pyrit.executor.attack import PromptSendingAttack
from pyrit.output import output_attack_async
from pyrit.prompt_target import OpenAICompletionTarget
from pyrit.setup import IN_MEMORY, initialize_pyrit_async

await initialize_pyrit_async(memory_db_type=IN_MEMORY)  # type: ignore

# Note that max_tokens will default to 16 for completions, so you may want to set the upper limit of allowed tokens for a longer response.
target = OpenAICompletionTarget(max_tokens=2048)

attack = PromptSendingAttack(objective_target=target)
result = await attack.execute_async(objective="Hello! Who are you?")  # type: ignore
await output_attack_async(result)
Found default environment files: ['./.pyrit/.env', './.pyrit/.env.local']
Loaded environment file: ./.pyrit/.env
Loaded environment file: ./.pyrit/.env.local
No new upgrade operations detected.

════════════════════════════════════════════════════════════════════════════════════════════════════
                                  ❓ ATTACK RESULT: UNDETERMINED ❓                                   
════════════════════════════════════════════════════════════════════════════════════════════════════

 Attack Summary 
────────────────────────────────────────────────────────────────────────────────────────────────────
  📋 Basic Information
    • Objective: Hello! Who are you?
    • Attack Type: PromptSendingAttack
    • Conversation ID: 7c3a9dfe-cccb-4304-94f1-fe2982026000

  ⚡ Execution Metrics
    • Turns Executed: 1
    • Execution Time: 2.79s

  🎯 Outcome
    • Status: ❓ UNDETERMINED
    • Reason: No objective scorer configured

 Conversation History with Objective Target 
────────────────────────────────────────────────────────────────────────────────────────────────────

────────────────────────────────────────────────────────────────────────────────────────────────────
🔹 Turn 1 - USER
────────────────────────────────────────────────────────────────────────────────────────────────────
  Hello! Who are you?

────────────────────────────────────────────────────────────────────────────────────────────────────
🔸 ASSISTANT
────────────────────────────────────────────────────────────────────────────────────────────────────
   Can I join your group?"
  
    And he joined the group by mistake.
  
    What the f*ck?
  
    Yeah, f*cked up. Rolled the dice and it wound up fucking up.
  
    Chad, ask them what they think's going on.
  
    Don't go with the groups. Don't go with the groups.
  
    You'll all lose.
  
    Wait, so... We're voting Leo.
  
    Yep, correct.
  
    Okay.
  
    We're all voting Leo.
  
    It will be the whole round.
  
    But right now they just think that you're the imposter?
  
    Yeah, they just think I'm the imposter. He was like, "Wait, hello, who are you?" I was like,
      "You're in my group." He was like, "Oh, shit."
  
    Oh my God, he literally said, "Oh, shit, no."

────────────────────────────────────────────────────────────────────────────────────────────────────

────────────────────────────────────────────────────────────────────────────────────────────────────
                            Report generated at: 2026-05-21 23:10:35 UTC