nextcloud / text2image_helper

A Smart Picker for interfacing with text-to-image providers in Nextcloud
1 stars 1 forks source link

Undefined array key 0 at /var/www/nextcloud/lib/private/TextToImage/Manager.php#231 #21

Closed SystemKeeper closed 10 months ago

SystemKeeper commented 11 months ago

NC 28.0.1

Installed:

In the admin settings everything is green. At first I thought its because the downloaded model had only 400MB, but after re-downloading the model, the same error still exists.

{
    "reqId": "nHI3pbXAIOyRY8OJD4iL",
    "level": 3,
    "time": "2023-12-18T21:49:02+01:00",
    "remoteAddr": "172.31.2.89",
    "user": "marcel.mueller",
    "app": "PHP",
    "method": "POST",
    "url": "/apps/text2image_helper/process_prompt",
    "message": "Undefined array key 0 at /var/www/nextcloud/lib/private/TextToImage/Manager.php#231",
    "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
    "version": "28.0.1.0",
    "data": {
        "app": "PHP"
    }
}
{
    "reqId": "nHI3pbXAIOyRY8OJD4iL",
    "level": 3,
    "time": "2023-12-18T21:49:02+01:00",
    "remoteAddr": "172.31.2.89",
    "user": "marcel.mueller",
    "app": "index",
    "method": "POST",
    "url": "/apps/text2image_helper/process_prompt",
    "message": "{\"Exception\":\"Exception\",\"Message\":\"Call to a member function getExpectedRuntime() on null in file '/var/www/nextcloud/lib/private/TextToImage/Manager.php' line 231\",\"Code\":0,\"Trace\":[{\"file\":\"/var/www/nextcloud/lib/private/AppFramework/App.php\",\"line\":184,\"function\":\"dispatch\",\"class\":\"OC\\\\AppFramework\\\\Http\\\\Dispatcher\",\"type\":\"->\"},{\"file\":\"/var/www/nextcloud/lib/private/Route/Router.php\",\"line\":315,\"function\":\"main\",\"class\":\"OC\\\\AppFramework\\\\App\",\"type\":\"::\"},{\"file\":\"/var/www/nextcloud/lib/base.php\",\"line\":1069,\"function\":\"match\",\"class\":\"OC\\\\Route\\\\Router\",\"type\":\"->\"},{\"file\":\"/var/www/nextcloud/index.php\",\"line\":39,\"function\":\"handleRequest\",\"class\":\"OC\",\"type\":\"::\"}],\"File\":\"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php\",\"Line\":169,\"Previous\":{\"Exception\":\"Error\",\"Message\":\"Call to a member function getExpectedRuntime() on null\",\"Code\":0,\"Trace\":[{\"file\":\"/var/www/nextcloud/apps/text2image_helper/lib/Service/Text2ImageHelperService.php\",\"line\":91,\"function\":\"runOrScheduleTask\",\"class\":\"OC\\\\TextToImage\\\\Manager\",\"type\":\"->\"},{\"file\":\"/var/www/nextcloud/apps/text2image_helper/lib/Controller/Text2ImageHelperController.php\",\"line\":44,\"function\":\"processPrompt\",\"class\":\"OCA\\\\Text2ImageHelper\\\\Service\\\\Text2ImageHelperService\",\"type\":\"->\"},{\"file\":\"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php\",\"line\":230,\"function\":\"processPrompt\",\"class\":\"OCA\\\\Text2ImageHelper\\\\Controller\\\\Text2ImageHelperController\",\"type\":\"->\"},{\"file\":\"/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php\",\"line\":137,\"function\":\"executeController\",\"class\":\"OC\\\\AppFramework\\\\Http\\\\Dispatcher\",\"type\":\"->\"},{\"file\":\"/var/www/nextcloud/lib/private/AppFramework/App.php\",\"line\":184,\"function\":\"dispatch\",\"class\":\"OC\\\\AppFramework\\\\Http\\\\Dispatcher\",\"type\":\"->\"},{\"file\":\"/var/www/nextcloud/lib/private/Route/Router.php\",\"line\":315,\"function\":\"main\",\"class\":\"OC\\\\AppFramework\\\\App\",\"type\":\"::\"},{\"file\":\"/var/www/nextcloud/lib/base.php\",\"line\":1069,\"function\":\"match\",\"class\":\"OC\\\\Route\\\\Router\",\"type\":\"->\"},{\"file\":\"/var/www/nextcloud/index.php\",\"line\":39,\"function\":\"handleRequest\",\"class\":\"OC\",\"type\":\"::\"}],\"File\":\"/var/www/nextcloud/lib/private/TextToImage/Manager.php\",\"Line\":231},\"message\":\"Call to a member function getExpectedRuntime() on null in file '/var/www/nextcloud/lib/private/TextToImage/Manager.php' line 231\",\"exception\":{},\"CustomMessage\":\"Call to a member function getExpectedRuntime() on null in file '/var/www/nextcloud/lib/private/TextToImage/Manager.php' line 231\"}",
    "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
    "version": "28.0.1.0"
}
MB-Finski commented 11 months ago

Thanks for the report! We explicitly check in process_prompt that a provider is available so this is likely not an issue in the text2image_helper, per se. Digging deeper on Manager.php makes me wonder if the array key can be assumed to be 0 in https://github.com/nextcloud/server/blob/6fa377e90e269b1610aab2b40bba3e3ab78f0b4b/lib/private/TextToImage/Manager.php#L231C4-L232C24. Looking at the getProviders() source code it seems like sometimes the array keys may be the class strings so we should do array_values() or array_shift() get the first provider in the Manager.php, maybe? Wdyt, @marcelklehr ?

MB-Finski commented 11 months ago

... and the downloaded models for text2image_stablediffusion should be ~13gb, IIRC, if everything went fine (I was never able to automatically download the models using the text2image_stablediffusion cli command, for whatever reason.)

SystemKeeper commented 11 months ago

should be ~13gb, IIRC

Yep, after re-trying the download it was about that size. But checking again today:

root@nextcloud:/var/www/nextcloud# du -sh apps/text2image_stablediffusion/
453M    apps/text2image_stablediffusion/

Not sure what happend here, I'll take a look later

MB-Finski commented 11 months ago

I think my suspicion from above is correct. So the reason we didn't catch this while testing these apps with Marcel is likely that the 0 key is defined if the text2image provider is explicitly chosen in the settings. In this case the json decoded id of the selected provider is used in Manager::getPreferredProviders() as a filter and [$provider] is returned. We would have played around with the settings repeatedly while testing these apps with Marcel so we didn't notice that $providers with the class strings as keys is passed through if the user has not explicitly selected the provider in the settings before. AFAICT this requires a PR for server repo to fix.

(You should be able to quickly work around this issue by toggling the default provider for this task type under artificial intelligence settings.)

MB-Finski commented 11 months ago

I suppose the fix could be as simple as this: https://github.com/nextcloud/server/tree/fix/text-to-image-manager

SystemKeeper commented 11 months ago

Thanks a lot, I'll test this later!

I am now downloading the models for the third time :-( It downloads successfully (the folder is roughly 13GB), but after a while, the folder is only 430 MB in size. Could not finding of a provider lead to a deletion of the model? Sorry, might even be totally unrelated to this issue, but it's weird. I received "Successful" in all cases:

# su - www-data -s /bin/bash -c 'php8.2 -d display_errors=stderr /var/www/nextcloud/occ text2image_stablediffusion:download-models'
Downloading models
Successful

🤔

marcelklehr commented 11 months ago

Updating the app removes the models

SystemKeeper commented 11 months ago

Updating the app removes the models

But I did not update anything? This morning I

after returning to this, the model vanished. I'll try again, to be sure

SystemKeeper commented 11 months ago

I guess the issue is this: https://github.com/nextcloud/text2image_stablediffusion/issues/5