diff --git a/includes/Classifai/Providers/OpenAI/OpenAI.php b/includes/Classifai/Providers/OpenAI/OpenAI.php index e35c7bb89..8e4e27b4c 100644 --- a/includes/Classifai/Providers/OpenAI/OpenAI.php +++ b/includes/Classifai/Providers/OpenAI/OpenAI.php @@ -13,11 +13,11 @@ trait OpenAI { /** - * OpenAI completions URL + * OpenAI model URL * * @var string */ - protected $completions_url = 'https://api.openai.com/v1/completions'; + protected $model_url = 'https://api.openai.com/v1/models'; /** * Add our OpenAI API settings field. @@ -139,18 +139,7 @@ protected function authenticate_credentials( string $api_key = '' ) { // Make request to ensure credentials work. $request = new APIRequest( $api_key ); - $response = $request->post( - $this->completions_url, - [ - 'body' => wp_json_encode( - [ - 'model' => 'ada', - 'prompt' => 'hi', - 'max_tokens' => 1, - ] - ), - ] - ); + $response = $request->get( $this->model_url ); return ! is_wp_error( $response ) ? true : $response; } diff --git a/tests/test-plugin/e2e-test-plugin.php b/tests/test-plugin/e2e-test-plugin.php index acc213ac3..aeb47bb52 100644 --- a/tests/test-plugin/e2e-test-plugin.php +++ b/tests/test-plugin/e2e-test-plugin.php @@ -19,6 +19,8 @@ function classifai_test_mock_http_requests( $preempt, $parsed_args, $url ) { if ( strpos( $url, 'http://e2e-test-nlu-server.test/v1/analyze' ) !== false ) { $response = file_get_contents( __DIR__ . '/nlu.json' ); + } elseif ( strpos( $url, 'https://api.openai.com/v1/models' ) !== false ) { + $response = file_get_contents( __DIR__ . '/models.json' ); } elseif ( strpos( $url, 'https://api.openai.com/v1/completions' ) !== false ) { $response = file_get_contents( __DIR__ . '/chatgpt.json' ); } elseif ( strpos( $url, 'https://api.openai.com/v1/chat/completions' ) !== false ) { diff --git a/tests/test-plugin/models.json b/tests/test-plugin/models.json new file mode 100644 index 000000000..f6784a569 --- /dev/null +++ b/tests/test-plugin/models.json @@ -0,0 +1,23 @@ +{ + "object": "list", + "data": [ + { + "id": "model-id-0", + "object": "model", + "created": 1686935002, + "owned_by": "organization-owner" + }, + { + "id": "model-id-1", + "object": "model", + "created": 1686935002, + "owned_by": "organization-owner" + }, + { + "id": "model-id-2", + "object": "model", + "created": 1686935002, + "owned_by": "openai" + } + ] +}