[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/php-ai-client/src/Builders/ -> MessageBuilder.php (summary)

(no description)

File Size: 221 lines (7 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

MessageBuilder:: (11 methods):
  __construct()
  __clone()
  usingRole()
  usingUserRole()
  usingModelRole()
  withText()
  withFile()
  withFunctionCall()
  withFunctionResponse()
  withMessageParts()
  get()


Class: MessageBuilder  - X-Ref

Fluent builder for constructing AI messages.

This class provides a fluent interface for building messages with various
content types including text, files, function calls, and function responses.

__construct($input = null, ?MessageRoleEnum $role = null)   X-Ref
Constructor.

param: Input $input Optional initial content.
param: MessageRoleEnum|null $role Optional role.

__clone()   X-Ref
Creates a deep clone of this builder.

Clones all MessagePart objects in the parts array to ensure
the cloned builder is independent of the original.


usingRole(MessageRoleEnum $role)   X-Ref
Sets the role of the message sender.

return: self
param: MessageRoleEnum $role The role to set.

usingUserRole()   X-Ref
Sets the role to user.

return: self

usingModelRole()   X-Ref
Sets the role to model.

return: self

withText(string $text)   X-Ref
Adds text content to the message.

return: self
param: string $text The text to add.

withFile($file, ?string $mimeType = null)   X-Ref
Adds a file to the message.

Accepts:
- File object
- URL string (remote file)
- Base64-encoded data string
- Data URI string (data:mime/type;base64,data)
- Local file path string

return: self
param: string|File $file The file to add.
param: string|null $mimeType Optional MIME type (ignored if File object provided).

withFunctionCall(FunctionCall $functionCall)   X-Ref
Adds a function call to the message.

return: self
param: FunctionCall $functionCall The function call to add.

withFunctionResponse(FunctionResponse $functionResponse)   X-Ref
Adds a function response to the message.

return: self
param: FunctionResponse $functionResponse The function response to add.

withMessageParts(MessagePart ...$parts)   X-Ref
Adds multiple message parts to the message.

return: self
param: MessagePart ...$parts The message parts to add.

get()   X-Ref
Builds and returns the Message object.

return: Message The built message.



Generated : Sat Jun 13 09:38:55 2026 Cross-referenced by PHPXref