OpenAI Completions - optional

OpenAI Completions - optional#

Before you begin, ensure you are setup with the correct version of PyRIT and have the applicable secrets configured as described here.

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

from pyrit.common import IN_MEMORY, initialize_pyrit
from pyrit.executor.attack import ConsoleAttackResultPrinter, PromptSendingAttack
from pyrit.prompt_target import OpenAICompletionTarget

initialize_pyrit(memory_db_type=IN_MEMORY)

# 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 ConsoleAttackResultPrinter().print_conversation_async(result=result)  # type: ignore
────────────────────────────────────────────────────────────────────────────────────────────────────
🔹 Turn 1 - USER
────────────────────────────────────────────────────────────────────────────────────────────────────
  Hello! Who are you?

────────────────────────────────────────────────────────────────────────────────────────────────────
🔸 ASSISTANT
────────────────────────────────────────────────────────────────────────────────────────────────────
   It isn't winter in December. I am stepfather. Commander of Hikaru's bi-col university troops. Oh,
      you're just giving your autograph to yourself? Hahahaha! You're one funny, Maroon. So, who's the
      lucky person getting the autograph? It's me, Commander. It's you? Well, it's you. You! Well,
      it's my privilege to sign this parchment. Of course, I'm doing this one for free. But just to
      make your investment worthwhile, tell me, how long did you study at the bi-col university? Hey,
      Commander, don't think you know everything. What? How long did you study at the bi-col
      university? So, what? It's more than four years! Oh, well done! [crying] Army! Commander, come
      on, don't cry, Commander. I didn't know you were still capable of teaching. Sir Commander,
      whenever you say or do is always afterthought. You're pathetic! Why do you turn into a crybaby
      in front of her? What is it with me? It is the girl that I like. That's why. There are many
      times that us girls are misunderstood. So it's not your intention. I'm really sorry. Anyway, Sir
      Commander, are you done crying? I'm still not hungry since earlier. And I've been trying to hold
      back my going to the loo earlier. Because I allowed you to tag along.
  
    Amir?
  
    What? The chapel of the Holy Rosary. What's wrong with it? I'm not sure, Commander. It's just...
      What? No, it's okay. I'm just weirded out by the place because of what happened earlier. Well,
      Amir, you were the one who dared me to. So, it's okay, Amir. I'll take care of you. It's okay.
      I'll just stay here. Okay. The chandelier is just there. Be discreet, okay? Okay. [knocking] Sit
      down.
  
    Mm-hmm.
  
    Mm-hmm.
  
    Good evening.
  
    Good evening. Give us a nice new thing. Can I help you, sir? Nice. That's why, when you do
      something, it's always worth it. You're the new Dean. How? I'm just a clerk. I'm the one who
      takes care of the chapel. You're the one who's beautiful. Pat, Pat. That's beautiful. It could
      make you get goosebumps.
  
    Lieutenant Mark Dolorit.
  
    Pleased to meet you, sir. Ma'am Grace, where is she? You saw her, didn't you? She's busy with her
      teaching. As usual. What about that girl? In front of you, sir. Her. Isn't everything clear for
      you? You're in a place like this. Right? Don't be suspicious. What's that? You should be more
      suspicious and wiser. Sooner than later. You made her a priest. A nun. Of course not, ma'am. I
      did not send anyone there. What? You didn't expect th

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