Class Prompt

java.lang.Object
org.springframework.ai.chat.prompt.Prompt
All Implemented Interfaces:
ModelRequest<List<Message>>

public class Prompt extends Object implements 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
  • Constructor Details

  • Method Details

    • getContents

      public String getContents()
    • getOptions

      @Nullable public ChatOptions getOptions()
      Description copied from interface: ModelRequest
      Retrieves the customizable options for AI model interactions.
      Specified by:
      getOptions in interface ModelRequest<List<Message>>
      Returns:
      the customizable options for AI model interactions
    • getInstructions

      public List<Message> getInstructions()
      Description copied from interface: ModelRequest
      Retrieves the instructions or input required by the AI model.
      Specified by:
      getInstructions in interface ModelRequest<List<Message>>
      Returns:
      the instructions or input required by the AI model
    • getSystemMessage

      public SystemMessage getSystemMessage()
      Get the first system message in the prompt. If no system message is found, an empty SystemMessage is returned.
    • getUserMessage

      public UserMessage getUserMessage()
      Get the last user message in the prompt. If no user message is found, an empty UserMessage is returned.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • copy

      public Prompt copy()
    • augmentSystemMessage

      public Prompt augmentSystemMessage(Function<SystemMessage,SystemMessage> systemMessageAugmenter)
      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 Prompt instance with the augmented system message.
    • augmentSystemMessage

      public Prompt augmentSystemMessage(String newSystemText)
      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 Prompt instance with the augmented system message.
    • augmentUserMessage

      public Prompt augmentUserMessage(Function<UserMessage,UserMessage> userMessageAugmenter)
      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 Prompt instance with the augmented user message.
    • augmentUserMessage

      public Prompt augmentUserMessage(String newUserText)
      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 Prompt instance with the augmented user message.
    • mutate

      public Prompt.Builder mutate()
    • builder

      public static Prompt.Builder builder()