Skip to content

Commit 9981a8b

Browse files
authored
Use WidgetTemplate from chatkit-python for news guide widgets (#37)
* use widget files for news guide * use logger * types * bump versions; fix bugs
1 parent 83d4698 commit 9981a8b

File tree

10 files changed

+26
-93
lines changed

10 files changed

+26
-93
lines changed

examples/news-guide/backend/app/agents/event_finder_agent.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async def search_events_by_date(
6565
ctx: RunContextWrapper[EventFinderContext],
6666
date: str,
6767
) -> dict[str, Any]:
68-
logger.info("[TOOL CALL] search_events_by_date", date)
68+
logger.info("[TOOL CALL] search_events_by_date: %s", date)
6969
if not date:
7070
raise ValueError("Provide a valid date in YYYY-MM-DD format.")
7171
await ctx.context.stream(ProgressUpdateEvent(text=f"Looking up events on {date}"))
@@ -78,7 +78,7 @@ async def search_events_by_day_of_week(
7878
ctx: RunContextWrapper[EventFinderContext],
7979
day: str,
8080
) -> dict[str, Any]:
81-
logger.info("[TOOL CALL] search_events_by_day_of_week", day)
81+
logger.info("[TOOL CALL] search_events_by_day_of_week: %s", day)
8282
if not day:
8383
raise ValueError("Provide a day of the week to search for (e.g., Saturday).")
8484
await ctx.context.stream(ProgressUpdateEvent(text=f"Checking {day} events"))
@@ -93,7 +93,7 @@ async def search_events_by_keyword(
9393
ctx: RunContextWrapper[EventFinderContext],
9494
keywords: List[str],
9595
) -> dict[str, Any]:
96-
logger.info("[TOOL CALL] search_events_by_keyword", keywords)
96+
logger.info("[TOOL CALL] search_events_by_keyword: %s", keywords)
9797
tokens = [keyword.strip() for keyword in keywords if keyword and keyword.strip()]
9898
if not tokens:
9999
raise ValueError("Provide at least one keyword to search for.")
@@ -118,7 +118,7 @@ async def show_event_list_widget(
118118
events: List[EventRecord],
119119
message: str | None = None,
120120
):
121-
logger.info("[TOOL CALL] show_event_list_widget", events)
121+
logger.info("[TOOL CALL] show_event_list_widget: %s", events)
122122
records: List[EventRecord] = [event for event in events if event]
123123

124124
# Gracefully handle case where agent mistakenly calls this tool with no events.

examples/news-guide/backend/app/server.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
WidgetItem,
2626
WidgetRootUpdated,
2727
)
28-
from chatkit.widgets import ListView
2928
from openai.types.responses import ResponseInputContentParam
3029

3130
from .agents.event_finder_agent import EventFinderContext, event_finder_agent
@@ -157,13 +156,7 @@ async def _handle_view_event_details_action(
157156
record = self.event_store.get_event(selected_event_id) if selected_event_id else None
158157

159158
# If the event is already selected, no need to show the details again.
160-
if (
161-
is_selected
162-
or not record
163-
or not event_ids
164-
or not sender
165-
or not isinstance(sender.widget, ListView)
166-
):
159+
if is_selected or not record or not event_ids or not sender:
167160
return
168161

169162
records: list[EventRecord] = []

examples/news-guide/backend/app/widgets/article_list_widget.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
from datetime import datetime
99
from typing import Any
1010

11-
from chatkit.widgets import WidgetRoot
11+
from chatkit.widgets import WidgetRoot, WidgetTemplate
1212

1313
from ..data.article_store import ArticleMetadata
14-
from .widget_template import WidgetTemplate
1514

1615

1716
def _format_date(value: datetime) -> str:

examples/news-guide/backend/app/widgets/event_list_widget.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
from itertools import groupby
99
from typing import Any, Iterable, Mapping
1010

11-
from chatkit.widgets import WidgetRoot
11+
from chatkit.widgets import WidgetRoot, WidgetTemplate
1212

1313
from ..data.event_store import EventRecord
14-
from .widget_template import WidgetTemplate
1514

1615
CATEGORY_COLORS: dict[str, str] = {
1716
"community": "purple-400",

examples/news-guide/backend/app/widgets/preview_widgets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from typing import Any
22

3+
from chatkit.widgets import BasicRoot, WidgetTemplate
4+
35
from ..data.article_store import ArticleMetadata
4-
from .widget_template import BasicRoot, WidgetTemplate
56

67
AUTHOR_PROFILES: dict[str, dict[str, str]] = {
78
"elowen-wilder": {

examples/news-guide/backend/app/widgets/widget_template.py

Lines changed: 0 additions & 62 deletions
This file was deleted.

examples/news-guide/backend/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ dependencies = [
88
"fastapi>=0.114.1,<0.116",
99
"uvicorn[standard]>=0.36,<0.37",
1010
"openai>=1.40",
11-
"openai-chatkit>=1.1.2,<2",
11+
"openai-chatkit>=1.4.0,<2",
1212
"jinja2",
1313
]
1414

examples/news-guide/backend/uv.lock

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/news-guide/frontend/package-lock.json

Lines changed: 10 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/news-guide/frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"npm": ">=9"
1515
},
1616
"dependencies": {
17-
"@openai/chatkit-react": "^1.0.0",
17+
"@openai/chatkit-react": "^1.3.0",
1818
"clsx": "^2.1.1",
1919
"lucide-react": "^0.544.0",
2020
"react": "^19.2.0",

0 commit comments

Comments
 (0)