microsoft / lida

Automatic Generation of Visualizations and Infographics using Large Language Models
https://microsoft.github.io/lida/
MIT License
2.57k stars 260 forks source link

TypeError: asdict() should be called on dataclass instances #96

Open Mukkkki opened 5 months ago

Mukkkki commented 5 months ago

When trying to execute the code goals = lida.goals(summary, n=2, textgen_config=text_gen) for goal_dict in goals: for key, value in goal_dict.items(): print(f"{key}: {value}")

<llmx.generators.text.hf_textgen.HFTextGenerator object at 0x7f3c894ba680>


TypeError Traceback (most recent call last) Cell In[3], line 1 ----> 1 goals = lida.goals(summary, n=2, textgen_config=text_gen) 2 for goal_dict in goals: 3 for key, value in goal_dict.items():

File ~/venv/lib/python3.10/site-packages/lida/components/manager.py:177, in Manager.goals(self, summary, textgen_config, n, persona) 174 if isinstance(persona, str): 175 persona = Persona(persona=persona, rationale="") --> 177 return self.goal.generate(summary=summary, text_gen=self.text_gen, 178 textgen_config=textgen_config, n=n, persona=persona)

File ~/venv/lib/python3.10/site-packages/lida/components/goal.py:51, in GoalExplorer.generate(self, summary, textgen_config, text_gen, n, persona) 43 user_prompt += f"""\n The generated goals SHOULD BE FOCUSED ON THE INTERESTS AND PERSPECTIVE of a '{persona.persona} persona, who is insterested in complex, insightful goals about the data. \n""" 45 messages = [ 46 {"role": "system", "content": SYSTEM_INSTRUCTIONS}, 47 {"role": "assistant", 48 "content": 49 f"{user_prompt}\n\n {FORMAT_INSTRUCTIONS} \n\n. The generated {n} goals are: \n "}] ---> 51 result: list[Goal] = text_gen.generate(messages=messages, config=textgen_config) 53 try: 54 json_string = clean_code_snippet(result.text[0]["content"])

File ~/venv/lib/python3.10/site-packages/llmx/generators/text/hf_textgen.py:171, in HFTextGenerator.generate(self, messages, config, kwargs) 168 config.model = self.model_name 169 print(config) 170 cache_key_params = { --> 171 asdict(config), 172 **kwargs, 173 "messages": messages, 174 "dialogue_type": self.dialogue_type} 175 if use_cache: 176 response = cache_request(cache=self.cache, params=(cache_key_params))

File /usr/lib/python3.10/dataclasses.py:1237, in asdict(obj, dict_factory) 1218 """Return the fields of a dataclass instance as a new dictionary mapping 1219 field names to field values. 1220 (...) 1234 tuples, lists, and dicts. 1235 """ 1236 if not _is_dataclass_instance(obj): -> 1237 raise TypeError("asdict() should be called on dataclass instances") 1238 return _asdict_inner(obj, dict_factory)

TypeError: asdict() should be called on dataclass instances

Mukkkki commented 5 months ago

goals = lida.goals(summary, n=2, textgen_config=text_gen)

for goal in goals: display(goal)

This all give the same above error , any idea how to resolve this issues , using hugging face model which was shown as dummy example in tutorial notebook