DallE implements Pipeline
Implements the Dall-E image generation pipeline using OpenAI's API.
This pipeline requires a prompt of type PNSQFprompt to specify image generation parameters such as prompt text, number of images, size, quality, and response format. It configures the underlying driver (default: GuzzleDriver) with the appropriate API endpoint, model, and headers including the OpenAI access token. The output methods allow retrieval of images in various formats (base64, raw binary, or stored files).
Table of Contents
Interfaces
- Pipeline
- Defines the required methods for Ai Model Pipelines, which are required for compatibility with LaravelNeuro Agent Networking features.
Properties
- $accessToken : mixed
- The OpenAI access token retrieved from configuration.
- $driver : GuzzleDriver
- The driver instance used for HTTP requests.
- $fileType : string
- The file type for the generated image (default: "png").
- $model : mixed
- The model identifier used for the API request.
- $prompt : mixed
- The prompt data, extracted from a PNSQFprompt instance.
Methods
- __construct() : mixed
- DallE constructor.
- b64() : array<string|int, mixed>
- Retrieves the image data as base64-encoded strings.
- driver() : Driver
- Accesses the injected Driver instance.
- driverClass() : string
- Retrieves the class name of the default associated driver.
- getDriver() : Driver
- Retrieves the current driver.
- getModel() : mixed
- Retrieves the current model identifier.
- getPrompt() : mixed
- Retrieves the current prompt.
- output() : mixed
- Executes the API request and returns the output.
- promptClass() : string
- Retrieves the class name of the default associated prompt.
- raw() : array<string|int, mixed>
- Retrieves the image data from the API response.
- setFileType() : self
- Sets the file type for the output image.
- setModel() : self
- Sets the model for the pipeline.
- setPrompt() : self
- Sets the prompt for the pipeline.
- store() : mixed
- Stores the generated image(s) as file(s) and returns file metadata.
- stream() : Generator
- Executes a streaming API request.
Properties
$accessToken
The OpenAI access token retrieved from configuration.
protected
mixed
$accessToken
$driver
The driver instance used for HTTP requests.
protected
GuzzleDriver
$driver
$fileType
The file type for the generated image (default: "png").
protected
string
$fileType
= "png"
$model
The model identifier used for the API request.
protected
mixed
$model
$prompt
The prompt data, extracted from a PNSQFprompt instance.
protected
mixed
$prompt
Methods
__construct()
DallE constructor.
public
__construct([Driver $driver = new GuzzleDriver() ]) : mixed
Retrieves configuration values for the Dall-E model and API endpoint, initializes the underlying driver (defaulting to GuzzleDriver), and sets the required HTTP headers including the OpenAI access token. Throws an exception if any required configuration value is missing.
Parameters
- $driver : Driver = new GuzzleDriver()
-
An instance implementing the Driver contract.
Tags
b64()
Retrieves the image data as base64-encoded strings.
public
b64() : array<string|int, mixed>
Iterates over the response data and collects any base64-encoded JSON values.
Return values
array<string|int, mixed> —An array of base64-encoded image strings.
driver()
Accesses the injected Driver instance.
public
driver() : Driver
Return values
Driver —the Driver instance stored in this instance of the class.
driverClass()
Retrieves the class name of the default associated driver.
public
driverClass() : string
Return values
stringgetDriver()
Retrieves the current driver.
public
getDriver() : Driver
Return values
Driver —The driver instance.
getModel()
Retrieves the current model identifier.
public
getModel() : mixed
Return values
mixed —The model identifier.
getPrompt()
Retrieves the current prompt.
public
getPrompt() : mixed
Return values
mixed —The prompt data.
output()
Executes the API request and returns the output.
public
output([bool $json = true ]) : mixed
This method is an alias for store().
Parameters
- $json : bool = true
-
Optional. If true, returns JSON-encoded file metadata.
Return values
mixed —The file metadata or JSON-encoded representation.
promptClass()
Retrieves the class name of the default associated prompt.
public
promptClass() : string
Return values
stringraw()
Retrieves the image data from the API response.
public
raw() : array<string|int, mixed>
Processes the response data to decode base64 image strings or return URLs.
Return values
array<string|int, mixed> —An array of image data (binary data or URLs).
setFileType()
Sets the file type for the output image.
public
setFileType(string $type) : self
Parameters
- $type : string
-
The file type (e.g., "png").
Return values
selfsetModel()
Sets the model for the pipeline.
public
setModel(mixed $model) : self
Updates both the pipeline property and the driver's model.
Parameters
- $model : mixed
-
The model identifier.
Return values
selfsetPrompt()
Sets the prompt for the pipeline.
public
setPrompt(PNSQFprompt $prompt) : self
Expects a PNSQFprompt instance. Extracts the prompt text and image generation parameters (number, size, quality, and response_format) from the prompt, then updates the driver's request accordingly.
Parameters
- $prompt : PNSQFprompt
-
A PNSQFprompt instance.
Tags
Return values
selfstore()
Stores the generated image(s) as file(s) and returns file metadata.
public
store([bool $json = false ]) : mixed
Iterates over the image data, saving each image using the driver's fileMake method, and returns an array of file metadata. If an image is provided as a URL, it is returned as-is.
Parameters
- $json : bool = false
-
Optional. If true, returns a JSON-encoded string of file metadata.
Return values
mixed —The file metadata array or its JSON-encoded representation.
stream()
Executes a streaming API request.
public
stream() : Generator
This pipeline does not support streaming mode.