Skip to content

Commit

Permalink
Polish suggestions (#6)
Browse files Browse the repository at this point in the history
* fix bugs in suggestions running

- getting agent during suggestions throwing error if no agent
- not properly awaiting run_fn

* redo ux of suggestion card so title and descriptin are indented same

* add y overflow scroll to suggestions panel
  • Loading branch information
riyavsinha authored Feb 23, 2025
1 parent c365ffe commit 12a03db
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion frontend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 15 additions & 11 deletions frontend/src/components/editor/chrome/panels/suggestions-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const SuggestionsPanel: React.FC = () => {
};

return (
<div className="flex flex-col gap-3 p-4">
<div className="flex flex-col gap-3 p-4 overflow-y-auto">
{suggestions.map((suggestion) => (
<div
key={suggestion.id}
Expand All @@ -49,17 +49,21 @@ export const SuggestionsPanel: React.FC = () => {
)}
onClick={() => handleSuggestionClick(suggestion.title)}
>
<div className="flex items-center gap-2">
{suggestion.type === "prompt_warning" ? (
<MessageCircleWarningIcon className="h-6 w-6" />
) : (
<MessageCircleQuestionIcon className="h-6 w-6" />
)}
<h3 className="font-medium">{suggestion.title}</h3>
<div className="flex items-start gap-2">
<div className="flex-shrink-0">
{suggestion.type === "prompt_warning" ? (
<MessageCircleWarningIcon className="h-6 w-6" />
) : (
<MessageCircleQuestionIcon className="h-6 w-6" />
)}
</div>
<div className="flex-1">
<h3 className="font-medium">{suggestion.title}</h3>
<p className="mt-1 text-sm text-muted-foreground">
{suggestion.description}
</p>
</div>
</div>
<p className="mt-1 text-sm text-muted-foreground">
{suggestion.description}
</p>
</div>
))}
</div>
Expand Down
2 changes: 1 addition & 1 deletion marimo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"video",
"vstack",
]
__version__ = "0.0.4"
__version__ = "0.0.5"

import marimo._ai as ai
import marimo._islands as islands
Expand Down
12 changes: 10 additions & 2 deletions marimo/_ai/agents.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations

import asyncio
import inspect
import uuid
from dataclasses import dataclass
from enum import Enum
Expand Down Expand Up @@ -49,6 +51,10 @@ class Agent:
suggestions_fn: Optional[Callable[..., List[Suggestion]]] = None


def is_coroutine_function(fn: Callable[..., Any]) -> bool:
return asyncio.iscoroutinefunction(fn) or inspect.iscoroutinefunction(fn)


@mddoc
def register_agent(agent: Agent) -> None:
"""Register an LLM agent."""
Expand All @@ -69,7 +75,9 @@ async def run_agent(prompt: str, name: Optional[str] = None) -> Any:
try:
_registry = get_context().agent_registry
agent = _registry.get_agent(name)
result = agent.run_fn(prompt)
return result
if is_coroutine_function(agent.run_fn):
return await agent.run_fn(prompt)
else:
return agent.run_fn(prompt)
except ContextNotInitializedError:
pass
4 changes: 3 additions & 1 deletion marimo/_runtime/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def get_agent(
raise ValueError(f"Agent name '{name}' is not registered.")
return self._agents[name]
else:
if len(self._agents) != 1:
if len(self._agents) == 0:
return None
elif len(self._agents) > 1:
raise ValueError(
"No agent name provided and multiple agents are registered."
)
Expand Down
8 changes: 3 additions & 5 deletions marimo/_runtime/runner/hooks_post_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,8 @@ async def _broadcast_suggestions(
return

agent_name = cell.agent_name
suggestion_fn = (
get_context().agent_registry.get_agent(agent_name).suggestions_fn
)
if suggestion_fn is None:
agent = get_context().agent_registry.get_agent(agent_name)
if agent is None or agent.suggestions_fn is None:
return

async def _update_suggestions(
Expand All @@ -236,7 +234,7 @@ async def _update_suggestions(
suggestions = await suggestion_fn()
Suggestions(suggestions=suggestions).broadcast()

asyncio.create_task(_update_suggestions(suggestion_fn))
asyncio.create_task(_update_suggestions(agent.suggestions_fn))


@kernel_tracer.start_as_current_span("store_reference_to_output")
Expand Down
2 changes: 1 addition & 1 deletion openapi/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2182,7 +2182,7 @@ components:
type: object
info:
title: marimo API
version: 0.0.1
version: 0.0.5
openapi: 3.1.0
paths:
/@file/{filename_and_length}:
Expand Down

0 comments on commit 12a03db

Please sign in to comment.