0) { $maxTokens = min($maxTokens, $providerLimit); } return $this->driver($provider)->complete(new AiRequest( task: $task, model: (string) $settings['model'], system: $system, prompt: $prompt, maxTokens: $maxTokens, )); } /** * Build the driver for a provider named in config/ai.php. * * @throws AiException */ public function driver(string $provider): AiDriver { $config = config("ai.providers.$provider"); $class = is_array($config) ? ($config['driver'] ?? null) : null; if (! is_string($class) || ! is_subclass_of($class, AiDriver::class)) { throw new AiException("AI provider [$provider] is not configured.", AiException::SETUP); } return app()->make($class, ['provider' => $provider, 'config' => $config]); } }