Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bubble up Analysis error #880

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/how_to/ai_config/custom_analyses.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class WindAnalysis(lmai.Analysis):
text="wind_direction",
kind="labels",
)
wind_table = Table(wind_pipeline)
wind_table = Table(pipeline=wind_pipeline)
return Layout(
views=[
wind_speed_view,
Expand All @@ -82,7 +82,7 @@ uv_df = pd.DataFrame({
"u": np.random.rand(12),
"v": np.random.rand(12)
})
source = lmai.memory["current_source"] = DuckDBSource.from_df({"uv_df": uv_df})
source = lmai.memory["source"] = DuckDBSource.from_df({"uv_df": uv_df})
analysis_agent = lmai.agents.AnalysisAgent(analyses=[WindAnalysis])
ui = lmai.ExplorerUI(llm=llm, agents=[analysis_agent])
ui.servable()
Expand Down
65 changes: 33 additions & 32 deletions lumen/ai/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,39 +967,40 @@ async def respond(
else:
analysis_name = next(iter(analyses))

with self.interface.add_step(title=step_title or "Creating view...", steps_layout=self._steps_layout) as step:
await asyncio.sleep(0.1) # necessary to give it time to render before calling sync function...
analysis_callable = analyses[analysis_name].instance(agents=agents)

data = await get_data(pipeline)
for field in analysis_callable._field_params:
analysis_callable.param[field].objects = list(data.columns)
self._memory["analysis"] = analysis_callable

if analysis_callable.autorun:
if asyncio.iscoroutinefunction(analysis_callable.__call__):
view = await analysis_callable(pipeline)
view = None
with self.interface.param.update(callback_exception="raise"):
with self.interface.add_step(title=step_title or "Creating view...", steps_layout=self._steps_layout) as step:
await asyncio.sleep(0.1) # necessary to give it time to render before calling sync function...
analysis_callable = analyses[analysis_name].instance(agents=agents)

data = await get_data(pipeline)
for field in analysis_callable._field_params:
analysis_callable.param[field].objects = list(data.columns)
self._memory["analysis"] = analysis_callable

if analysis_callable.autorun:
if asyncio.iscoroutinefunction(analysis_callable.__call__):
view = await analysis_callable(pipeline)
else:
view = await asyncio.to_thread(analysis_callable, pipeline)
if isinstance(view, Viewable):
view = Panel(object=view, pipeline=self._memory.get('pipeline'))
spec = view.to_spec()
if isinstance(view, View):
view_type = view.view_type
self._memory["view"] = dict(spec, type=view_type)
elif isinstance(view, Pipeline):
self._memory["pipeline"] = view
# Ensure data reflects processed pipeline
if pipeline is not self._memory['pipeline']:
pipeline = self._memory['pipeline']
if len(data) > 0:
self._memory["data"] = await describe_data(data)
yaml_spec = yaml.dump(spec)
step.stream(f"Generated view\n```yaml\n{yaml_spec}\n```")
step.success_title = "Generated view"
else:
view = await asyncio.to_thread(analysis_callable, pipeline)
if isinstance(view, Viewable):
view = Panel(object=view, pipeline=self._memory.get('pipeline'))
spec = view.to_spec()
if isinstance(view, View):
view_type = view.view_type
self._memory["view"] = dict(spec, type=view_type)
elif isinstance(view, Pipeline):
self._memory["pipeline"] = view
# Ensure data reflects processed pipeline
if pipeline is not self._memory['pipeline']:
pipeline = self._memory['pipeline']
if len(data) > 0:
self._memory["data"] = await describe_data(data)
yaml_spec = yaml.dump(spec)
step.stream(f"Generated view\n```yaml\n{yaml_spec}\n```")
step.success_title = "Generated view"
else:
step.success_title = "Configure the analysis"
view = None
step.success_title = "Configure the analysis"

analysis = self._memory["analysis"]
pipeline = self._memory['pipeline']
Expand Down
Loading