Class Prompt
java.lang.Object
org.springframework.ai.chat.prompt.Prompt
- All Implemented Interfaces:
ModelRequest<List<Message>>
The Prompt class represents a prompt used in AI model requests. A prompt consists of
one or more messages and additional chat options.
- Author:
- Mark Pollack, luocongqiu, Thomas Vitale
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionPrompt(String contents, @Nullable ChatOptions chatOptions) Prompt(List<Message> messages, @Nullable ChatOptions chatOptions) Prompt(Message message, @Nullable ChatOptions chatOptions) -
Method Summary
Modifier and TypeMethodDescriptionaugmentSystemMessage(String newSystemText) Augments the last system message in the prompt with the provided text.augmentSystemMessage(Function<SystemMessage, SystemMessage> systemMessageAugmenter) Augments the first system message in the prompt with the provided function.augmentUserMessage(String newUserText) Augments the last user message in the prompt with the provided text.augmentUserMessage(Function<UserMessage, UserMessage> userMessageAugmenter) Augments the last user message in the prompt with the provided function.static Prompt.Builderbuilder()copy()booleanRetrieves the instructions or input required by the AI model.Get the last user or tool response message in the prompt.@Nullable ChatOptionsRetrieves the customizable options for AI model interactions.Get the first system message in the prompt.Get all system messages in the prompt.Get the last user message in the prompt.Get all user messages in the prompt.inthashCode()mutate()toString()
-
Constructor Details
-
Prompt
-
Prompt
-
Prompt
-
Prompt
-
Prompt
-
Prompt
-
Prompt
-
-
Method Details
-
getContents
-
getOptions
Description copied from interface:ModelRequestRetrieves the customizable options for AI model interactions.- Specified by:
getOptionsin interfaceModelRequest<List<Message>>- Returns:
- the customizable options for AI model interactions
-
getInstructions
Description copied from interface:ModelRequestRetrieves the instructions or input required by the AI model.- Specified by:
getInstructionsin interfaceModelRequest<List<Message>>- Returns:
- the instructions or input required by the AI model
-
getSystemMessage
Get the first system message in the prompt. If no system message is found, an empty SystemMessage is returned. -
getUserMessage
Get the last user message in the prompt. If no user message is found, an empty UserMessage is returned. -
getLastUserOrToolResponseMessage
Get the last user or tool response message in the prompt. If no user or tool response message is found, an empty UserMessage is returned. -
getSystemMessages
Get all system messages in the prompt.- Returns:
- a list of all system messages in the prompt
-
getUserMessages
Get all user messages in the prompt.- Returns:
- a list of all user messages in the prompt
-
toString
-
equals
-
hashCode
public int hashCode() -
copy
-
augmentSystemMessage
Augments the first system message in the prompt with the provided function. If no system message is found, a new one is created with the provided text.- Returns:
- a new
Promptinstance with the augmented system message.
-
augmentSystemMessage
Augments the last system message in the prompt with the provided text. If no system message is found, a new one is created with the provided text.- Returns:
- a new
Promptinstance with the augmented system message.
-
augmentUserMessage
Augments the last user message in the prompt with the provided function. If no user message is found, a new one is created with the provided text.- Returns:
- a new
Promptinstance with the augmented user message.
-
augmentUserMessage
Augments the last user message in the prompt with the provided text. If no user message is found, a new one is created with the provided text.- Returns:
- a new
Promptinstance with the augmented user message.
-
mutate
-
builder
-