PNSQFprompt extends BasicPrompt
PNSQFprompt stands for "prompt, number, size, quality, format" and is specifically designed for image generation pipelines.
PNSQFprompt extends BasicPrompt to provide methods for setting and retrieving image generation parameters such as prompt text, the number of images, image size, quality, and response format. The encoder method builds a custom NSQF block appended to the prompt, and the decoder method extracts these parameters from a JSON-encoded string.
Table of Contents
Methods
- __construct() : mixed
- PNSQFprompt constructor.
- getFormat() : mixed
- Retrieves the response format.
- getNumber() : mixed
- Retrieves the number of images to generate.
- getPrompt() : mixed
- Retrieves the prompt text.
- getQuality() : mixed
- Retrieves the quality setting.
- getSize() : mixed
- Retrieves the image size.
- promptDecode() : static
- Decodes a JSON-encoded prompt string into a BasicPrompt instance.
- promptEncode() : string
- Encodes the prompt data into a JSON string.
- setFormat() : $this
- Sets the response format.
- setNumber() : $this
- Sets the number of images to generate.
- setPrompt() : $this
- Sets the prompt text.
- setQuality() : $this
- Sets the quality of the generated image.
- setSize() : $this
- Sets the image size.
- decoder() : void
- Decodes a JSON-encoded prompt string and sets the image generation parameters.
- encoder() : string
- Encodes the prompt and image generation parameters into a JSON string.
Methods
__construct()
PNSQFprompt constructor.
public
__construct() : mixed
Initializes the prompt with default image generation parameters:
- prompt: "Create an image for me."
- number: 1
- size: "1024x1024"
- quality: STANDARD (from PNSQFquality enum)
- response_format: "url"
getFormat()
Retrieves the response format.
public
getFormat() : mixed
Return values
mixed —The response format.
getNumber()
Retrieves the number of images to generate.
public
getNumber() : mixed
Return values
mixed —The number of images.
getPrompt()
Retrieves the prompt text.
public
getPrompt() : mixed
Return values
mixed —The prompt text.
getQuality()
Retrieves the quality setting.
public
getQuality() : mixed
Return values
mixed —The quality value.
getSize()
Retrieves the image size.
public
getSize() : mixed
Return values
mixed —The image size as a string (e.g., "1024x1024").
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.
setFormat()
Sets the response format.
public
setFormat(string $string) : $this
Parameters
- $string : string
-
The response format (e.g., "url").
Return values
$this —Returns the current instance for method chaining.
setNumber()
Sets the number of images to generate.
public
setNumber(int $number) : $this
Parameters
- $number : int
-
The number of images.
Return values
$this —Returns the current instance for method chaining.
setPrompt()
Sets the prompt text.
public
setPrompt(string $string) : $this
Parameters
- $string : string
-
The prompt text.
Return values
$this —Returns the current instance for method chaining.
setQuality()
Sets the quality of the generated image.
public
setQuality([PNSQFquality $enum = PNSQFquality::STANDARD ]) : $this
Parameters
- $enum : PNSQFquality = PNSQFquality::STANDARD
-
The quality value, defaults to PNSQFquality::STANDARD.
Return values
$this —Returns the current instance for method chaining.
setSize()
Sets the image size.
public
setSize(int $x[, int $y = -1 ]) : $this
Accepts width and height parameters. If the height is not provided or is -1, the width is used for both dimensions.
Parameters
- $x : int
-
The width of the image.
- $y : int = -1
-
The height of the image (optional, defaults to -1).
Return values
$this —Returns the current instance for method chaining.
decoder()
Decodes a JSON-encoded prompt string and sets the image generation parameters.
protected
decoder(string $prompt) : void
Extracts the NSQF block from the prompt using a regular expression, splits it into the number, size, quality, and response format components, and then uses the corresponding setters to update the prompt.
Parameters
- $prompt : string
-
The JSON-encoded prompt string.
encoder()
Encodes the prompt and image generation parameters into a JSON string.
protected
encoder() : string
Constructs an NSQF block in the following format: {{NSQF:number,size,quality,format}} which is appended to the prompt text. The resulting string is then JSON-encoded.
Return values
string —The JSON-encoded representation of the prompt with NSQF parameters.