Skip to content
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
6 changes: 3 additions & 3 deletions examples/cat-lounge/backend/app/cat_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from .cat_state import CatState
from .cat_store import CatStore
from .memory_store import MemoryStore
from .name_suggestions_widget import CatNameSuggestion, build_name_suggestions_widget
from .profile_card_widget import profile_widget_copy_text, render_profile_card
from .widgets.name_suggestions_widget import CatNameSuggestion, build_name_suggestions_widget
from .widgets.profile_card_widget import build_profile_card_widget, profile_widget_copy_text

INSTRUCTIONS: str = """
You are Cozy Cat Companion, a playful caretaker helping the user look after a virtual cat.
Expand Down Expand Up @@ -244,7 +244,7 @@ def mutate(state: CatState) -> None:
state.set_age(age)

state = await _update_state(ctx, mutate)
widget = render_profile_card(state, favorite_toy)
widget = build_profile_card_widget(state, favorite_toy)
await ctx.context.stream_widget(widget, copy_text=profile_widget_copy_text(state))

if state.name == "Unnamed Cat":
Expand Down
113 changes: 0 additions & 113 deletions examples/cat-lounge/backend/app/name_suggestions_widget.py

This file was deleted.

117 changes: 0 additions & 117 deletions examples/cat-lounge/backend/app/profile_card_widget.py

This file was deleted.

30 changes: 7 additions & 23 deletions examples/cat-lounge/backend/app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,15 @@
WidgetItem,
)
from openai.types.responses import ResponseInputContentParam
from pydantic import ValidationError

from .cat_agent import CatAgentContext, cat_agent
from .cat_store import CatStore
from .memory_store import MemoryStore
from .name_suggestions_widget import (
SELECT_CAT_NAME_ACTION_TYPE,
CatNameSelectionPayload,
from .thread_item_converter import BasicThreadItemConverter
from .widgets.name_suggestions_widget import (
CatNameSuggestion,
build_name_suggestions_widget,
)
from .thread_item_converter import BasicThreadItemConverter

logging.basicConfig(level=logging.INFO)

Expand All @@ -60,13 +57,10 @@ async def action(
sender: WidgetItem | None,
context: dict[str, Any],
) -> AsyncIterator[ThreadStreamEvent]:
if action.type == SELECT_CAT_NAME_ACTION_TYPE:
payload = self._parse_select_name_payload(action)
if payload is None:
return
if action.type == "cats.select_name":
async for event in self._handle_select_name_action(
thread,
payload,
action.payload,
sender,
context,
):
Expand Down Expand Up @@ -120,28 +114,18 @@ async def to_message_content(self, _input: Attachment) -> ResponseInputContentPa
raise RuntimeError("File attachments are not supported in this demo.")

# -- Helpers ----------------------------------------------------
def _parse_select_name_payload(
self,
action: Action[str, Any],
) -> CatNameSelectionPayload | None:
try:
return CatNameSelectionPayload.model_validate(action.payload or {})
except ValidationError as exc:
logging.warning("Invalid select name payload: %s", exc)
return None

async def _handle_select_name_action(
self,
thread: ThreadMetadata,
payload: CatNameSelectionPayload,
payload: dict[str, Any],
sender: WidgetItem | None,
context: dict[str, Any],
) -> AsyncIterator[ThreadStreamEvent]:
name = payload.name.strip()
name = payload["name"].strip()
if not name or not sender:
return

options = payload.options or [CatNameSuggestion(name=name)]
options = [CatNameSuggestion(**option) for option in payload["options"]]
current_state = await self.cat_store.load(thread.id)
is_already_named = current_state.name != "Unnamed Cat"
selection = current_state.name if is_already_named else name
Expand Down
Loading