Skip to content

Commit d7deefe

Browse files
authored
Search hotel. (#301)
1 parent 6a1b0c1 commit d7deefe

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

examples/travel_app/lib/src/tools/list_hotels_tool.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,25 @@ class ListHotelsTool extends AiTool<Map<String, Object?>> {
130130
return onListHotels(search).toJson();
131131
}
132132
}
133+
134+
HotelSearchResult onListHotels(HotelSearch search) {
135+
// Mock implementation
136+
return HotelSearchResult(
137+
listings: [
138+
HotelListing(
139+
name: 'The Grand Flutter Hotel',
140+
location: 'Mountain View, CA',
141+
pricePerNight: 250.0,
142+
listingId: '1',
143+
images: ['assets/travel_images/brooklyn_bridge_new_york.jpg'],
144+
),
145+
HotelListing(
146+
name: 'The Dart Inn',
147+
location: 'Sunnyvale, CA',
148+
pricePerNight: 150.0,
149+
listingId: '2',
150+
images: ['assets/travel_images/eiffel_tower_construction_1888.jpg'],
151+
),
152+
],
153+
);
154+
}

examples/travel_app/lib/src/travel_planner_page.dart

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:flutter_genui_firebase_ai/flutter_genui_firebase_ai.dart';
1111

1212
import 'asset_images.dart';
1313
import 'catalog.dart';
14+
import 'tools/list_hotels_tool.dart';
1415
import 'widgets/conversation.dart';
1516

1617
Future<void> loadImagesJson() async {
@@ -45,7 +46,8 @@ class TravelPlannerPage extends StatefulWidget {
4546
State<TravelPlannerPage> createState() => _TravelPlannerPageState();
4647
}
4748

48-
class _TravelPlannerPageState extends State<TravelPlannerPage> {
49+
class _TravelPlannerPageState extends State<TravelPlannerPage>
50+
with AutomaticKeepAliveClientMixin {
4951
late final GenUiManager _genUiManager;
5052
late final AiClient _aiClient;
5153
late final StreamSubscription<UserMessage> _userMessageSubscription;
@@ -70,12 +72,11 @@ class _TravelPlannerPageState extends State<TravelPlannerPage> {
7072
_userMessageSubscription = _genUiManager.onSubmit.listen(
7173
_handleUserMessageFromUi,
7274
);
75+
final tools = _genUiManager.getTools();
76+
tools.add(ListHotelsTool(onListHotels: onListHotels));
7377
_aiClient =
7478
widget.aiClient ??
75-
FirebaseAiClient(
76-
tools: _genUiManager.getTools(),
77-
systemInstruction: prompt,
78-
);
79+
FirebaseAiClient(tools: tools, systemInstruction: prompt);
7980
_genUiManager.surfaceUpdates.listen((update) {
8081
setState(() {
8182
switch (update) {
@@ -187,6 +188,7 @@ class _TravelPlannerPageState extends State<TravelPlannerPage> {
187188

188189
@override
189190
Widget build(BuildContext context) {
191+
super.build(context);
190192
return SafeArea(
191193
child: Center(
192194
child: Column(
@@ -214,6 +216,9 @@ class _TravelPlannerPageState extends State<TravelPlannerPage> {
214216
),
215217
);
216218
}
219+
220+
@override
221+
bool get wantKeepAlive => true;
217222
}
218223

219224
class _ChatInput extends StatelessWidget {
@@ -330,6 +335,10 @@ to the user.
330335
involves booking every accommodation, transport and activity in the itinerary
331336
one step at a time.
332337
338+
When booking accommodation, you should use the `listHotels` tool to search
339+
for hotels. You can then show the user the different options in a
340+
`travelCarousel`.
341+
333342
Here, you should just focus on one item at a time, using an `inputGroup`
334343
with chips to ask the user for preferences, and the `travelCarousel` to show
335344
the user different options. When the user chooses an option, you can confirm
@@ -368,7 +377,7 @@ update existing content.
368377
at the bottom of the conversation.
369378
- Updating surfaces: You should update surfaces when you are running an
370379
iterative search flow, e.g. the user is adjusting filter values and generating
371-
an itinerary or a booking accomodation etc. This is less confusing for the user
380+
an itinerary or a booking accommodation etc. This is less confusing for the user
372381
because it avoids confusing the conversation with many versions of the same
373382
itinerary etc.
374383
@@ -389,7 +398,7 @@ carousel. If there are only 2 or 3 obvious options, just think of some relevant
389398
alternatives that the user might be interested in.
390399
391400
- Guiding the user: When the user has completes some action, e.g. they confirm
392-
they want to book some accomodation or activity, always show a trailhead
401+
they want to book some accommodation or activity, always show a trailhead
393402
suggesting what the user might want to do next (e.g. book the next detail in the
394403
itinerary, repeat a search, research some related topic) so that they can click
395404
rather than typing.

0 commit comments

Comments
 (0)