Constructor.
Parameters
$inputWordPressAiClientBuildersInputoptional- Optional initial content.
Default:
null $roleWordPressAiClientMessagesEnumsMessageRoleEnum|nulloptional- Optional role.
Default:
null
Source
public function __construct($input = null, ?MessageRoleEnum $role = null)
{
$this->role = $role;
if ($input === null) {
return;
}
// Handle different input types
if ($input instanceof MessagePart) {
$this->parts[] = $input;
} elseif (is_string($input)) {
$this->withText($input);
} elseif ($input instanceof File) {
$this->withFile($input);
} elseif ($input instanceof FunctionCall) {
$this->withFunctionCall($input);
} elseif ($input instanceof FunctionResponse) {
$this->withFunctionResponse($input);
} elseif (is_array($input) && MessagePart::isArrayShape($input)) {
$this->parts[] = MessagePart::fromArray($input);
} else {
throw new InvalidArgumentException('Input must be a string, MessagePart, MessagePartArrayShape, File, FunctionCall, or FunctionResponse.');
}
}
Changelog
| Version | Description |
|---|---|
| 0.2.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.