BlafKing / sd-civitai-browser-plus

Extension to access CivitAI via WebUI: download, delete, scan for updates, list installed models, assign tags, and boost downloads with multi-threading.
GNU Affero General Public License v3.0
289 stars 44 forks source link

[Bug]: Only Latest Version of Model Shown #252

Closed RedFoxNightfox closed 4 months ago

RedFoxNightfox commented 4 months ago

Describe the bug.

when getting info on a model, only the latest version is able to be selected

Steps to reproduce the problem.

  1. Go to Browse
  2. Type search term
  3. Press search button
  4. select model
  5. click the "version" dropdown

Expected behavior

Expected behaviour is to show all versions available

System info

Console logs

[DEBUG] CivitAI Browser+: https://civitai.com/api/v1/models?limit=100&sort=Newest&period=AllTime&query=meinaunreal
[DEBUG] CivitAI Browser+: MeinaUnreal NSFW is: False
[DEBUG] CivitAI Browser+: MeinaUnrealxHassakuHentaiMix NSFW is: False

Additional information

There is supposed to be more versions here:

image

also, browsing models floods the console with debug messages now. Is that really needed?

BlafKing commented 4 months ago

Thanks for reporting.

Unfortunately, this issue is caused by the CivitAI API, I've also noticed that currently, it only returns the latest version. Can't do anything about this problem unfortunately, there is a bug report for it on the CivitAI github here

And the debug messages shouldn't appear on other people their instances, thanks for letting me know! I'll investigate why you can see them πŸ‘πŸ»

BlafKing commented 4 months ago

The printing of debug messages should be fixed in the latest commit, silly oversight of meπŸ˜…

I'll leave this bug report open, until the single version per model issue is fixed πŸ‘πŸ»

Number6UK commented 4 months ago

As a temporary workaround, would it be possible to use the URL of the model and version to download the specific version? In essennce, completely bypass the "search" part of the API.

e.g.

DreamshaperXL (model ID 112902) has numerous versions, one of which is "Lightning DPM++ SDE" which has a model version ID of 354657 The URL for that exact version is: https://civitai.com/models/112902?modelVersionId=354657

If it were possible to enter the URL into the extension's search field, could we then retrieve that version as if it had been selected from the normal dropdown?

This would also be useful when trying to download a model with a very generic name and generic/no tags, that you know the URL of, but turns up many pages of search results. At the moment this means either:

If we could give a direct URL, then this would make downloading such models via the extension easier, and also workaround the current issue.

Alternatively, perhaps getting it from its hash might work? I can see that the individual versions have their hashes in the API return data, plus there appears to already be an API endpoint for retrieving the version from its hash, and it would have the advantage that if someone has downloaded a model from elsewhere (so no metadata saved along with it), they could then see if there's a CivitAI version of it which they could use to add the image(s) and metadata as the extension does for models/versions downloaded by it directly.

hakaserver commented 4 months ago

This would also be useful when trying to download a model with a very generic name and generic/no tags, that you know the URL of, but turns up many pages of search results. At the moment this means either:

  • Going through tens or hundreds of results found by the browser extension (harder now that paging has been removed by the changes) and looking for the model visually by the cover image
  • Fiddling with the search paramters in the browser, maybe trying to search it from the author's username (which isn't too bad if they don't have hundreds of models posted, but you still have to remember to go and change your search parameters back to model name afterwards.)

Just to let you know, you can search a specific model by its URL. If you search the address you provided it will give only DreamShaperXL as a result. It functions exactly as you described there in terms of searching a specific model between many similarly named ones.

However, it currently cannot retrieve the exact version you mentioned since it is still only searching for the model page itself, not the specific model version. I don't know if it would be possible to immediately retrieve the exact model ID and version ID when searching with a URL containing the ?modelVersionId=XXXXXX parameter, but it could very well be a solution if Civitai API takes too long to be fixed (50+ open bug reports apparently).

Number6UK commented 4 months ago

Just to let you know, you can search a specific model by its URL. If you search the address you provided it will give only DreamShaperXL as a result. It functions exactly as you described there in terms of searching a specific model between many similarly named ones.

So it does! Thanks for the info, that will ease things on those badly named/tagged ones.

However, it currently cannot retrieve the exact version you mentioned since it is still only searching for the model page itself, not the specific model version. I don't know if it would be possible to immediately retrieve the exact model ID and version ID when searching with a URL containing the ?modelVersionId=XXXXXX parameter, but it could very well be a solution if Civitai API takes too long to be fixed (50+ open bug reports apparently).

I've just done an experiement wth the API, using the model-versions ID endpoint request on that DreamshaperXL Lightning model version ID, and it appears to retrieve it successfully:

https://civitai.com/api/v1/model-versions/354657

Whether the data is in exactly the right format for the extension I'm not sure, but I might have a look through the extension's code and see if I can get it working locally. If I do, I'll figure out how to do a pull request (finally - I've been meaning to learn how to do it for years. but something more 'urgent' always comes up.) Whilst I'm not a Python coder, I reckon I can understand enough of it to give it a shot.

Number6UK commented 4 months ago

Haven't got a workaround in place yet (kind of learning Python and how the extension does things, as I go…) however I think I've identified what's broken in the API response.

The API is returning a an object called "modelVersions", which contains the correct number of versions available (e.g. 9 for Dreamshaper XL) however, as we already know and can see from the extension front-end, they're all for whatever version is the most recently published.

I'll carry on doing what I'm doing, but it seems to me that this is most likely a simple error with a for-loop over at the CivitAI API backend. They're looping through the versions, but instead of returning the current iteration, they're only returning the first one over and over. It could be a two minute fix on their side. There's a good chance they'll fix it long before I get a workaround in place, but I'm happy to continue as it's a great learning experience in any case.

Number6UK commented 4 months ago

It looks like @JustMaier may have found the source of the bug over at CivitAI - looks like he's swapped two SQL statements around - and has committed a fix. Hopefully that will resolve the problem.

Seeing as the API results (and possibly the structure) may change, I'll hold off for the moment on any of the deeper stuff, though I'm still going to try implementing the code to get a specific model version by URL as I've already written the code to parse the URL correctly, and just need to figure out the differences in the returned data compared to when it gets the parent model (different level of nesting, etc.) Seeing as that's technically unrelated to the bug, I won't post any more udpates on the progress of that in this bug report, but open a separate feature request when I get a bit further with the code.

RedFoxNightfox commented 4 months ago

API has been fixed, gonna close this now.