Documentation

GuzzleDriver implements Driver

A concrete implementation of the Driver interface that uses GuzzleHttp to send API requests.

This driver supports both standard and streaming requests, and can also handle file responses via Laravel's Storage facade.

Table of Contents

Interfaces

Driver
Defines the required methods for Ai Model Drivers, which are attached to Pipelines via dependency injection. The default driver is the WebRequest GuzzleDriver

Properties

$api  : string
The API endpoint URL.
$client  : Client|bool
The GuzzleHttp client instance.
$debug  : bool
When true, debug information is printed during the request.
$error  : mixed
Stores any error encountered during the API request.
$headers  : array<string|int, mixed>
An associative array of headers to send with the request.
$promptKey  : string
The key used in the request payload to store the prompt.
$request  : mixed
The request payload or parameters.
$requestType  : RequestType
The type of request being made.
$response  : mixed
The API response.
$stream  : bool
Indicates whether the response should be streamed.

Methods

debug()  : self
Enables or disables debug mode.
fileMake()  : array<string|int, mixed>
Saves file data to a designated disk using Laravel's Storage facade.
getApi()  : string
Retrieves the API endpoint URL.
getClient()  : Client|bool
Retrieves the current Guzzle client instance.
getHeaders()  : array<string|int, mixed>
Retrieves the current header array.
getModel()  : string|null
Retrieves the model from the request payload.
getPrompt()  : mixed
Retrieves the prompt from the request payload.
getRequest()  : mixed
Retrieves the entire request payload or a specific key.
getRequestType()  : RequestType
Retrieves the current request type.
getSystemPrompt()  : mixed
Retrieves the system prompt from the request payload.
modifyRequest()  : self
Modifies the request payload.
output()  : mixed
Executes the API request and returns the response body.
setApi()  : self
Sets the API endpoint URL.
setClient()  : self
Sets a custom Guzzle client.
setHeaderEntry()  : self
Sets a header entry to be sent with the API request.
setModel()  : self
Sets the model for the request.
setPrompt()  : self
Sets the prompt for the request.
setRequestType()  : self
Sets the request type.
setSystemPrompt()  : self
Sets the system prompt for the request.
stream()  : Generator
Executes a streaming API request.
unsetHeaderEntry()  : self
Removes a header entry.
connect()  : ResponseInterface
Executes the API request using the Guzzle client.

Properties

$client

The GuzzleHttp client instance.

protected Client|bool $client = false

False if not yet initialized.

$debug

When true, debug information is printed during the request.

protected bool $debug = false

$error

Stores any error encountered during the API request.

protected mixed $error = false

$headers

An associative array of headers to send with the request.

protected array<string|int, mixed> $headers = []

$promptKey

The key used in the request payload to store the prompt.

protected string $promptKey = "prompt"

$request

The request payload or parameters.

protected mixed $request

$requestType

The type of request being made.

protected RequestType $requestType = \LaravelNeuro\Enums\RequestType::JSON

Defaults to JSON. MULTIPART is used for file streams.

$stream

Indicates whether the response should be streamed.

protected bool $stream = false

Methods

debug()

Enables or disables debug mode.

public debug([bool $set = true ]) : self

When enabled, prints request data and headers for debugging purposes.

Parameters
$set : bool = true

True to enable debug mode, false to disable.

Return values
self

fileMake()

Saves file data to a designated disk using Laravel's Storage facade.

public fileMake(string $fileName, mixed $data) : array<string|int, mixed>

This method is useful for handling file responses (e.g., images or audio) by storing the data on a configured disk.

Parameters
$fileName : string

The name to save the file as.

$data : mixed

The file data to be saved.

Return values
array<string|int, mixed>

An associative array of file metadata:

  • "fileName": The saved file name.
  • "diskName": The disk where the file is stored.
  • "fileSize": The file size in bytes.
  • "mimeType": The MIME type of the file.

getApi()

Retrieves the API endpoint URL.

public getApi() : string
Return values
string

The API endpoint.

getClient()

Retrieves the current Guzzle client instance.

public getClient() : Client|bool
Return values
Client|bool

The Guzzle client or false if not initialized.

getHeaders()

Retrieves the current header array.

public getHeaders() : array<string|int, mixed>
Return values
array<string|int, mixed>

An associative array of header entries.

getModel()

Retrieves the model from the request payload.

public getModel() : string|null
Return values
string|null

The model identifier, or null if not set.

getPrompt()

Retrieves the prompt from the request payload.

public getPrompt() : mixed
Return values
mixed

The prompt, or null if not set.

getRequest()

Retrieves the entire request payload or a specific key.

public getRequest([string|null $key = null ]) : mixed
Parameters
$key : string|null = null

Optional key to retrieve from the request.

Return values
mixed

The entire request payload or the value at the specified key.

getSystemPrompt()

Retrieves the system prompt from the request payload.

public getSystemPrompt() : mixed
Return values
mixed

The system prompt, or null if not set.

modifyRequest()

Modifies the request payload.

public modifyRequest(mixed $key_or_array[, mixed $value = null ]) : self

If an array is provided, appends it to the request array. Otherwise, sets the given key to the provided value.

Parameters
$key_or_array : mixed

The key to set or an array to merge.

$value : mixed = null

The value to assign if a key is provided.

Return values
self

output()

Executes the API request and returns the response body.

public output() : mixed

This method leverages the connect() method and retrieves the response body.

Return values
mixed

The response body.

setApi()

Sets the API endpoint URL.

public setApi(string $address) : self
Parameters
$address : string

The API endpoint.

Return values
self

setClient()

Sets a custom Guzzle client.

public setClient([array<string|int, mixed> $options = [] ]) : self

Typically not required as a new Client is created if none is set.

Parameters
$options : array<string|int, mixed> = []

The options for the Guzzle client constructor.

Return values
self

setHeaderEntry()

Sets a header entry to be sent with the API request.

public setHeaderEntry(string $key, string $value) : self
Parameters
$key : string

The header name.

$value : string

The header value.

Return values
self

setModel()

Sets the model for the request.

public setModel(mixed $model) : self
Parameters
$model : mixed

The model identifier.

Return values
self

setPrompt()

Sets the prompt for the request.

public setPrompt(mixed $prompt[, string $key = "prompt" ]) : self
Parameters
$prompt : mixed

The prompt text.

$key : string = "prompt"

Optional key to use for the prompt (defaults to "prompt").

Return values
self

setRequestType()

Sets the request type.

public setRequestType(RequestType $requestType) : self
Parameters
$requestType : RequestType

The request type to set.

Return values
self

setSystemPrompt()

Sets the system prompt for the request.

public setSystemPrompt(mixed $system) : self
Parameters
$system : mixed

The system prompt.

Return values
self

stream()

Executes a streaming API request.

public stream() : Generator

Enables streaming mode and returns a generator that yields JSON-encoded data chunks from the API response. Useful for handling responses that include large or streaming payloads.

Return values
Generator

Yields JSON-encoded data chunks.

unsetHeaderEntry()

Removes a header entry.

public unsetHeaderEntry(string $key) : self
Parameters
$key : string

The header name to remove.

Return values
self

connect()

Executes the API request using the Guzzle client.

private connect(string $method) : ResponseInterface

Builds the request based on the current request type (JSON or MULTIPART) and handles streaming if enabled. Debug information is printed if debug mode is active.

Parameters
$method : string

The HTTP method to use (typically 'POST').

Tags
throws
Exception

If the request fails.

Return values
ResponseInterface

The API response.


        
On this page

Search results