Debugging LLM interactions is essential for troubleshooting and optimizing your applications.
Polyglot debug mode provides a simple way to enable debugging for LLM interactions. Debugging is essential for troubleshooting and optimizing your applications. It allows you to inspect the requests sent to the LLM and the responses received, helping you identify issues and improve performance.
Polyglot provides a simple way to enable debug mode:
Copy
<?phpuse Cognesy\Polyglot\Inference\Inference;// Enable debug mode when creating the inference object$inference = (new Inference()) ->withDebugPreset('on');// Make a request - debug output will show the request and response details$response = $inference->with( messages: 'What is the capital of France?')->get();
You can manually add debugging middleware to inspect raw HTTP requests and responses.In this example we’re using built-in middleware, but you can also create your own custom middleware.
Copy
<?phpuse Cognesy\Http\Middleware\Debug\DebugMiddleware;use Cognesy\Http\HttpClient;use Cognesy\Polyglot\Inference\Inference;// Create a custom debug middleware with specific options$debugMiddleware = new DebugMiddleware([ 'requestUrl' => true, 'requestHeaders' => true, 'requestBody' => true, 'responseHeaders' => true, 'responseBody' => true,]);// Create an HTTP client with the debug middleware$httpClient = new HttpClient();$httpClient->withMiddleware($debugMiddleware);// Use the HTTP client with Inference$inference = new Inference();$inference->withHttpClient($httpClient);// Make a request$response = $inference->with( messages: 'What is the capital of France?')->get();