PHP code example of bradvin / wp-ai-client-streaming

1. Go to this page and download the library: Download bradvin/wp-ai-client-streaming library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bradvin / wp-ai-client-streaming example snippets


add_action(
	'plugins_loaded',
	static function (): void {
		if ( wp_ai_client_streaming_load() ) {
			WP_AI_Client_Streaming_Discovery_Strategy::init();
		}
	},
	PHP_INT_MAX
);

$result = wp_ai_client_stream_prompt(
	$prompt_messages,
	array(
		'streaming_enabled' => true,
	)
)
	->using_model_config( $model_config )
	->generate_result();

$builder = wp_ai_client_prompt( $prompt_messages )->using_model_config( $model_config );
$result  = wp_ai_client_stream( $builder, array( 'streaming_enabled' => true ) )->generate_result();

$diagnostics = WP_AI_Client_Streaming_Transport_Diagnostics::get_default_registry_diagnostics();