SUAprompt extends BasicPrompt
Stands for "System, User, Agent". An extension of BasicPrompt designed for chat-completion pipelines.
SUAprompt allows you to build prompts with distinct roles. It provides methods to push system, agent, and user messages onto the prompt stack.
Table of Contents
Methods
- getPrompt() : string
- Gets the prompt text.
- promptDecode() : static
- Decodes a JSON-encoded prompt string into a BasicPrompt instance.
- promptEncode() : string
- Encodes the prompt data into a JSON string.
- pushAgent() : $this
- Pushes an agent message onto the prompt.
- pushSystem() : $this
- Pushes a system message onto the prompt.
- pushUser() : $this
- Pushes a user message onto the prompt.
- setPrompt() : $this
- Sets the prompt text.
- decoder() : void
- Decodes a JSON-encoded prompt string and reconstructs the SUAprompt.
- encoder() : string
- Encodes the SUAprompt into a JSON string.
Methods
getPrompt()
Gets the prompt text.
public
getPrompt() : string
Return values
string —$this Returns the current prompt string.
promptDecode()
Decodes a JSON-encoded prompt string into a BasicPrompt instance.
public
static promptDecode(string $promptString) : static
This static method creates a new instance of BasicPrompt, decodes the provided JSON string, and sets the prompt data accordingly.
Parameters
- $promptString : string
-
JSON-encoded prompt string.
Return values
static —A new instance of BasicPrompt with the decoded prompt data.
promptEncode()
Encodes the prompt data into a JSON string.
public
promptEncode() : string
This method utilizes the internal encoder to transform the prompt stored in the collection into a JSON representation.
Return values
string —JSON-encoded prompt data.
pushAgent()
Pushes an agent message onto the prompt.
public
pushAgent(string $string) : $this
The agent message is flagged with the "agent" type.
Parameters
- $string : string
-
The agent message text.
Return values
$this —Returns the current instance for chaining.
pushSystem()
Pushes a system message onto the prompt.
public
pushSystem(string $string) : $this
The system message is flagged with the "role" type.
Parameters
- $string : string
-
The system message text.
Return values
$this —Returns the current instance for chaining.
pushUser()
Pushes a user message onto the prompt.
public
pushUser(string $string) : $this
The user message is flagged with the "user" type.
Parameters
- $string : string
-
The user message text.
Return values
$this —Returns the current instance for chaining.
setPrompt()
Sets the prompt text.
public
setPrompt(string $prompt) : $this
Stores the provided prompt text in the collection under the key "prompt".
Parameters
- $prompt : string
-
The prompt text.
Return values
$this —Returns the current instance for method chaining.
decoder()
Decodes a JSON-encoded prompt string and reconstructs the SUAprompt.
protected
decoder(string $prompt) : void
This method decodes the JSON string into its component parts. It pushes the system message, iterates through the "completion" array to alternate between user and agent messages, and finally pushes the final prompt as a user message.
Parameters
- $prompt : string
-
The JSON-encoded prompt string.
encoder()
Encodes the SUAprompt into a JSON string.
protected
encoder() : string
This method iterates over the prompt collection and builds an associative array with keys "role", "completion", and "prompt". The "role" key holds the system message, "completion" collects alternating messages for user and agent, and "prompt" contains the final message.
Return values
string —The JSON-encoded representation of the prompt, formatted with JSON_PRETTY_PRINT.