$model_params Optional. Additional model parameters. See * {@see Mock_AI_Service::get_model()} for the list of available * parameters. Default empty array. * @param array $request_options Optional. The request options. Default empty array. * * @throws InvalidArgumentException Thrown if the model parameters are invalid. */ public function __construct( Model_Metadata $metadata, array $model_params = array(), array $request_options = array() ) { $this->set_model_metadata( $metadata ); $this->set_text_generation_config_from_model_params( $model_params ); $this->set_system_instruction_from_model_params( $model_params ); $this->set_request_options( $request_options ); } /** * Sends a request to generate text content. * * @since 0.7.0 * * @param Content[] $contents Prompts for the content to generate. * @param array $request_options The request options. * @return Candidates The response candidates with generated text content - usually just one. * * @throws Generative_AI_Exception Thrown if the request fails or the response is invalid. */ protected function send_generate_text_request( array $contents, array $request_options ): Candidates { return $this->resolve_expected_candidates( $contents ); } /** * Sends a request to generate text content, streaming the response. * * @since 0.7.0 * * @param Content[] $contents Prompts for the content to generate. * @param array $request_options The request options. * @return Generator Generator that yields the chunks of response candidates with generated text * content - usually just one candidate. * * @throws Generative_AI_Exception Thrown if the request fails or the response is invalid. */ protected function send_stream_generate_text_request( array $contents, array $request_options ): Generator { $candidates = $this->resolve_expected_candidates( $contents ); yield $candidates; } /** * Gets the default candidates to return for AI requests where no expected response was provided. * * @since 0.7.0 * * @return Candidates The default candidates. */ protected function get_default_candidates(): Candidates { return $this->parse_candidates( 'This is the default AI response to a mock request for which no expected response was provided.' ); } }