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.orchestrator import PromptSendingOrchestrator
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)

orchestrator = PromptSendingOrchestrator(objective_target=target)
response = await orchestrator.send_prompts_async(prompt_list=["Hello! Who are you?"])  # type: ignore
await orchestrator.print_conversations_async()  # type: ignore
Conversation ID: 380b5455-a9c1-4dda-92ae-189c2219aee4
user: Hello! Who are you?
assistant:  I am Ramos, I am the Rector Montessori for Hallas. And now I am going to tell you, today we are going to make music. Let's see. What are we going to do to make our music. Okay, we are going to play the drums. Good morning children. I am in Prahya Alakshmi, I am one of the directors in placement. And today we are going to show you how to make a beautiful book marker. And this is what we are going to do. This is what we are going to use. This is matching cross. Generally people give this for your birthday, for Christmas. And this is for everyone. For morning walker,