role = $role; $this->parts = $parts; } /** * Gets the role of the content. * * @since 0.1.0 * * @return string The role of the content. */ public function get_role(): string { return $this->role; } /** * Gets the parts of the content. * * @since 0.1.0 * * @return Parts The parts of the content. */ public function get_parts(): Parts { return $this->parts; } /** * Returns the array representation. * * @since 0.1.0 * * @return mixed[] Array representation. */ public function to_array(): array { return array( 'role' => $this->role, 'parts' => $this->parts->to_array(), ); } /** * Creates a Content instance from an array of content data. * * @since 0.1.0 * * @param array $data The content data. * @return Content Content instance. * * @throws InvalidArgumentException Thrown if the data is missing required fields. */ public static function from_array( array $data ): Content { if ( ! isset( $data['role'], $data['parts'] ) ) { throw new InvalidArgumentException( 'Content data must contain role and parts.' ); } return new Content( $data['role'], Parts::from_array( $data['parts'] ) ); } /** * Returns the JSON schema for the expected input. * * @since 0.2.0 * * @return array The JSON schema. */ public static function get_json_schema(): array { return array( 'type' => 'object', 'properties' => array( 'role' => array( 'description' => __( 'The role of the content, i.e. which source it comes from.', 'ai-services' ), 'type' => 'string', 'enum' => array( Content_Role::USER, Content_Role::MODEL, Content_Role::SYSTEM, ), ), 'parts' => array_merge( array( 'description' => __( 'Content parts, including optional multimodal input.', 'ai-services' ) ), Parts::get_json_schema() ), ), 'additionalProperties' => false, ); } }