Prompt
A prompt from a person to the model.
Declaration
struct PromptMentioned in
Overview
Prompts can contain content written by you, an outside source, or input directly from people using your app. You can initialize a Prompt from a string literal:
let prompt = Prompt("What are miniature schnauzers known for?")Use PromptBuilder to dynamically control the prompt’s content based on your app’s state. The code below shows that if the Boolean is true, the prompt includes a second line of text:
let responseShouldRhyme = true
let prompt = Prompt {
"Answer the following question from the user: \(userInput)"
if responseShouldRhyme {
"Your response MUST rhyme!"
}
}If your prompt includes input from people, consider wrapping the input in a string template with your own prompt to better steer the model’s response. For more information on handling inputs in your prompts, see Improving the safety of generative model output.
Prompting the same session eventually leads to exceeding the context window size. You can recover from this error by removing entries from the transcript and trying again. For more information on managing the context window size, see Managing the context window.