SkinnyDevi / webui_tavernai_charas

A TavernUI Character extension for oobabooga's Text Generation WebUI
Apache License 2.0
59 stars 2 forks source link

TavernAIService : AttributeError: 'str' object has no attribute 'get' on entry.get("id") #11

Closed baptisterajaut closed 7 months ago

baptisterajaut commented 7 months ago

Good day gents. Look like tavern ai broke something somewhere? Or i'm confused. The extension doesn't start anymore.

Traceback :

│ text-generation-webui/extensions/webui_tavernai_charas/script.py:29 in ui                                                                                                                                           │
│            
│   28 def ui():                                                              
│ ❱ 29     charas_ui.mount_ui()                                               
│   30       
│            
│ text-generation-webui/extensions/webui_tavernai_charas/ui/main.py:23 in mount_ui                                                                                                                                    │
│            
│   22         with gr.TabItem("Online Characters"):                          
│ ❱ 23             featured_ui()                                              
│   24       
│            
  ... 2 frames hidden ...                                                                                                          │
│            
│ text-generation-webui/extensions/webui_tavernai_charas/ui/featured.py:101 in create_tavernai_chara_display                                                                                                          │
│            
│   100         label="",                                                     
│ ❱ 101         samples=compile_html_online_chara_cards(samples()),           
│   102         elem_classes=["tavernai_downloaded_container tavernai_card_display"],                                                                                                                                                       │
│            
│ text-generation-webui/extensions/webui_tavernai_charas/ui/featured.py:280 in <lambda>                                                                                                                               │
│            
│   279         f"Category - {cat1.name_view.capitalize()}",                  
│ ❱ 280         lambda: TavernAIService.fetch_category_cards(                 
│   281             category=cat1.name, nsfw=CONFIG.allow_nsfw                
│            
│ text-generation-webui/extensions/webui_tavernai_charas/services/tavernai_service.py:295 in fetch_category_cards                                                                                                     │
│            
│   294      
│ ❱ 295         return TavernAIService.__parseAmount(amount=amount, decoded=response)                                                                                                                                                       │
│   296      
│            
│ text-generation-webui/extensions/webui_tavernai_charas/services/tavernai_service.py:428 in __parseAmount                                                                                                            │
│            
│   427      
│ ❱ 428             cards.append(TavernAICard.from_dict(entry))               
│   429             count += 1                                                
│            
│ text-generation-webui/extensions/webui_tavernai_charas/services/tavernai_service.py:142 in from_dict                                                                                                                │
│            
│   141         return TavernAICard(                                          
│ ❱ 142             entry.get("id"),                                          
│   143             entry.get("public_id"),                                   
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
AttributeError: 'str' object has no attribute 'get'
baptisterajaut commented 7 months ago

So just to check i added :

  try:
                cards.append(TavernAICard.from_dict(entry))
            except:
                print(f"{entry} is brokey?");
            count += 1

which produce

results is brokey?
count is brokey?
results is brokey?
count is brokey?
results is brokey?
count is brokey?
results is brokey?
count is brokey?
results is brokey?
count is brokey?

and the categories don't appear in the extension. So api change?

Zumilee commented 7 months ago

Same here

hammam12345 commented 7 months ago

same here, and i'm new to these stuff and i don't know how to add characters so if anyone knows a different way please tell me

SkinnyDevi commented 7 months ago

Hi there! Thanks for the issue and the insight. I'll be looking to fix this in the upcoming days, so please be patient. If you do encounter any more ways that it could be fixed, it would help me if you post them here. Thanks!

glitchexe commented 7 months ago

When parsing the returned values entry eventually gets the string results as it's value, which is not a dict.

Dirty hack to fix; check the type(entry) is a dict before making a TavernAICard:

@@ -416,7 +415,7 @@ class TavernAIService:
     @staticmethod
     def __parseAmount(decoded, amount):
         if amount == -1:
-            return [TavernAICard.from_dict(entry) for entry in decoded]
+            return [TavernAICard.from_dict(entry) for entry in decoded if type(entry) is dict]

         cards: list[TavernAICard] = []
         count = 0
@@ -424,9 +423,10 @@ class TavernAIService:
         for entry in decoded:
             if count >= amount:
                 break
-
-            cards.append(TavernAICard.from_dict(entry))
-            count += 1
+
+            if type(entry) is dict:
+                cards.append(TavernAICard.from_dict(entry))
+                count += 1

         return cards

It doesn't fix everything but it at least allows the extension to start. Some categories etc. are not showing correctly with this change.

SkinnyDevi commented 7 months ago

Bug has been found! It was certainly a slight change in the TavernAI API when fetching specific category cards. Thanks for the insight to all!

SkinnyDevi commented 7 months ago

Update has been released. Please update the extension!