kambo-1st / huggingface-php

inference.huggingface
20 stars 3 forks source link

Huggingface::client()->inference()->create() causes error which the error handler cannot display, also causing an error #1

Open bunexceptional opened 9 months ago

bunexceptional commented 9 months ago

This is the stack trace I got:

Warning: Undefined array key "message" in [server]/inc/vendor/kambo/huggingface-php/src/Exceptions/ErrorException.php on line 18

Fatal error: Uncaught TypeError: Exception::__construct(): Argument #1 ($message) must be of type string, null given in [server]/inc/vendor/kambo/huggingface-php/src/Exceptions/ErrorException.php:18 Stack trace: #0 [server]/inc/vendor/kambo/huggingface-php/src/Exceptions/ErrorException.php(18): Exception->__construct() #1 [server]/inc/vendor/kambo/huggingface-php/src/Transporters/HttpTransporter.php(66): Kambo\Huggingface\Exceptions\ErrorException->__construct() #2 [server]/inc/vendor/kambo/huggingface-php/src/Resources/Inference.php(24): Kambo\Huggingface\Transporters\HttpTransporter->requestObject() #3 [server]/inc/prefilter.php(105): Kambo\Huggingface\Resources\Inference->create() #4 [server]/post.php(77): classify_img() #5 [server]/post.php(150): makePost() #6 {main} thrown in [server]/inc/vendor/kambo/huggingface-php/src/Exceptions/ErrorException.php on line 18

(where [server] is the path to the HTTP document directory on my machine)

This is my code that uses the library:

$token = HF_TOKEN;
$client = Huggingface::client($token);

$result = $client->inference()->create([
    'model' => 'Falconsai/nsfw_image_detection',
    'inputs' => $imgpath,
    'type' => Type::TEXT_GENERATION,
]);

return $result['label'];

I cannot find any other PHP binding for the Hugging Face API, so I depend on this one. Please help me solve this issue so I can use the model I need.

bunexceptional commented 9 months ago

Actually, the azaharizaman/huggingface-php fork fixes this issue. You should merge it into the main source tree.

bunexceptional commented 9 months ago

Wait, no it doesn't. When I used that fork, I saw an error message that looked like it was related to Hugging Face itself rather than the PHP script. After refreshing, I got the same error message as I did with this version. Oops!