holoviz / lumen

Illuminate your data.
https://lumen.holoviz.org
BSD 3-Clause "New" or "Revised" License
172 stars 19 forks source link

Attempts to serialize before assignment #581

Closed droumis closed 2 months ago

droumis commented 2 months ago

lumen/ai/assistant.py

python 3.12

In the code below, if obj itself has the 'visible' attribute True, then this breaks as o never is assigned to.

All I did was run the dashboard and click on a prompt to generate this issue

    def _serialize(self, obj):
        if isinstance(obj, (Tabs, Column)):
            for o in obj:
                if hasattr(o, "visible") and o.visible:
                    break
            return self._serialize(o)
Code ```python import pathlib import lumen as lm import lumen.ai as lmai import panel as pn from lumen.sources.duckdb import DuckDBSource pn.extension("tabulator", "codeeditor", inline=False, template="fast") llm = lmai.llm.OpenAI() lmai.memory["current_source"] = DuckDBSource( tables=["read_parquet('windturbines.parq')"], uri=":memory:", initializers=["INSTALL httpfs;", "LOAD httpfs;"], ) assistant = lmai.Assistant( llm=llm, agents=[ lmai.agents.SourceAgent, lmai.agents.TableAgent, lmai.agents.TableListAgent, lmai.agents.SQLAgent, lmai.agents.PipelineAgent, lmai.agents.hvPlotAgent, lmai.agents.ChatAgent, ], ) assistant.servable("Lumen.ai") assistant.controls().servable(area="sidebar") ```
ahuang11 commented 2 months ago

I think the case o isn't assigned to is if obj is empty. I think it would need len(obj) > 0, but strange that it broke on running the dashboard.

    def _serialize(self, obj):
        if isinstance(obj, (Tabs, Column)) and len(obj) > 0:
            for o in obj:
                if hasattr(o, "visible") and o.visible:
                    break
            return self._serialize(o)
droumis commented 2 months ago

The actual error was a missing openai API key