Multimodal implements Pipeline
Implements a Google multimodal pipeline for AI models that accept both text and file inputs.
This pipeline retrieves configuration values for the Google Gemini model and API, sets up required headers and parameters (including an access token), and processes SUAprompt instances to format the request payload appropriately.
The pipeline supports output retrieval in multiple formats (text, JSON, array) and also provides streaming methods that yield output chunks.
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 Google Gemini API access token.
- $baseApi : mixed
- The base API endpoint.
- $driver : GuzzleDriver
- The driver instance for making API requests.
- $model : mixed
- The model identifier used for the request.
- $prompt : mixed
- The prompt data, processed from an SUAprompt instance.
Methods
- __construct() : mixed
- Multimodal constructor.
- array() : array<string|int, mixed>
- Retrieves the API response as an associative array.
- 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.
- json() : string
- Retrieves the API response as a JSON-formatted string.
- output() : string
- Executes the API request and returns the generated text output.
- promptClass() : string
- Retrieves the class name of the default associated prompt.
- setApi() : self
- Sets the API endpoint for the driver.
- setModel() : self
- Sets the model for the pipeline.
- setPrompt() : self
- Sets the prompt for the pipeline.
- stream() : Generator
- Executes a streaming API request and yields JSON-encoded output chunks.
- streamArray() : Generator
- Executes a streaming API request and yields output as decoded arrays.
- streamText() : Generator
- Executes a streaming API request and yields text output chunks.
- text() : string
- Retrieves the text output from the API response.
Properties
$accessToken
The Google Gemini API access token.
protected
mixed
$accessToken
$baseApi
The base API endpoint.
protected
mixed
$baseApi
$driver
The driver instance for making API requests.
protected
GuzzleDriver
$driver
$model
The model identifier used for the request.
protected
mixed
$model
$prompt
The prompt data, processed from an SUAprompt instance.
protected
mixed
$prompt
Methods
__construct()
Multimodal constructor.
public
__construct([Driver $driver = new GuzzleDriver() ]) : mixed
Retrieves configuration values for the Google Gemini API (model, endpoint, and access token), initializes the driver (defaulting to GuzzleDriver), sets required header entries, and validates that all required configuration values are present.
Parameters
- $driver : Driver = new GuzzleDriver()
-
An instance implementing the Driver contract.
Tags
array()
Retrieves the API response as an associative array.
public
array() : array<string|int, mixed>
Return values
array<string|int, mixed> —The decoded API response.
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.
json()
Retrieves the API response as a JSON-formatted string.
public
json() : string
Return values
string —The JSON-encoded API response.
output()
Executes the API request and returns the generated text output.
public
output() : string
This method is an alias for text().
Return values
string —The generated text output.
promptClass()
Retrieves the class name of the default associated prompt.
public
promptClass() : string
Return values
stringsetApi()
Sets the API endpoint for the driver.
public
setApi(string $address[, bool $stream = false ]) : self
Builds the full API URL by appending the model identifier, generate endpoint (or stream endpoint), and the access token to the provided base address. Updates the driver's API endpoint and the base API.
Parameters
- $address : string
-
The base API address.
- $stream : bool = false
-
Optional. If true, sets up the endpoint for streaming.
Tags
Return values
selfsetModel()
Sets the model for the pipeline.
public
setModel(mixed $model) : self
Stores the model identifier and updates the API endpoint accordingly.
Parameters
- $model : mixed
-
The model identifier.
Return values
selfsetPrompt()
Sets the prompt for the pipeline.
public
setPrompt(SUAprompt $prompt) : self
Expects a SUAprompt instance. Processes each element in the prompt:
- If the element contains a file pattern and is not of type "role", it converts it into an inline data structure.
- Otherwise, wraps the text in an associative array. The method also extracts a system instruction from a "role" element, if present, and updates the driver's prompt and system_instruction request parameter.
Parameters
- $prompt : SUAprompt
-
A SUAprompt instance.
Tags
Return values
selfstream()
Executes a streaming API request and yields JSON-encoded output chunks.
public
stream() : Generator
Sets the API to streaming mode, processes each output chunk, and yields the JSON-encoded chunk.
Return values
Generator —Yields JSON-encoded data chunks.
streamArray()
Executes a streaming API request and yields output as decoded arrays.
public
streamArray() : Generator
Sets the API to streaming mode, processes each output chunk, and yields the decoded output.
Return values
Generator —Yields decoded output as an array.
streamText()
Executes a streaming API request and yields text output chunks.
public
streamText() : Generator
Sets the API to streaming mode, processes each output chunk, and yields the text content if available in the candidate's content parts.
Return values
Generator —Yields text output chunks.
text()
Retrieves the text output from the API response.
public
text() : string
Decodes the response and returns the text content from the first candidate.
Return values
string —The text output.