How to troubleshoot provider configurations in Polyglot
<?php use Cognesy\Polyglot\Inference\Inference; use Cognesy\Http\Exceptions\HttpRequestException; function testApiKey(string $preset): bool { try { $llm = LLMProvider::using($preset); $inference = new Inference($preset); $response = $inference->with( messages: 'Test message', options: ['max_tokens' => 5] )->get(); echo "Connection preset '$preset' is working.\n"; return true; } catch (HttpRequestException $e) { echo "Error with connection '$preset': " . $e->getMessage() . "\n"; return false; } } // Test each connection $presets = ['openai', 'anthropic', 'mistral']; foreach ($presets as $preset) { testApiKey($preset); }
<?php use Cognesy\Polyglot\Inference\Inference; // Enable debug mode $inference = new Inference() ->using('openai') ->withDebugPreset('on'); // Make a request $response = $inference->with( messages: 'Test message with debug enabled' )->get();
<?php function verifyConfig(string $preset): void { try { $provider = new ConfigProvider(); $config = LLMConfig::fromArray($provider->getConfig($preset)); echo "Configuration for '$preset':\n"; echo "API URL: {$config->apiUrl}\n"; echo "Endpoint: {$config->endpoint}\n"; echo "Default Model: {$config->model}\n"; echo "Provider Type: {$config->providerType}\n"; // Check for empty values if (empty($config->apiKey)) { echo "Warning: API key is empty\n"; } if (empty($config->model)) { echo "Warning: Default model is not set\n"; } } catch (\Exception $e) { echo "Error loading configuration for '$preset': " . $e->getMessage() . "\n"; } } // Verify configurations $presets = ['openai', 'anthropic', 'mistral']; foreach ($presets as $preset) { verifyConfig($preset); echo "\n"; }