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
22 changes: 22 additions & 0 deletions examples/travel_app/lib/src/tools/list_hotels_tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,25 @@ class ListHotelsTool extends AiTool<Map<String, Object?>> {
return onListHotels(search).toJson();
}
}

HotelSearchResult onListHotels(HotelSearch search) {
// Mock implementation
return HotelSearchResult(
listings: [
HotelListing(
name: 'The Grand Flutter Hotel',
location: 'Mountain View, CA',
pricePerNight: 250.0,
listingId: '1',
images: ['assets/travel_images/brooklyn_bridge_new_york.jpg'],
),
HotelListing(
name: 'The Dart Inn',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the name. I'd stay there. :-)

location: 'Sunnyvale, CA',
pricePerNight: 150.0,
listingId: '2',
images: ['assets/travel_images/eiffel_tower_construction_1888.jpg'],
),
],
);
}
23 changes: 16 additions & 7 deletions examples/travel_app/lib/src/travel_planner_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:flutter_genui_firebase_ai/flutter_genui_firebase_ai.dart';

import 'asset_images.dart';
import 'catalog.dart';
import 'tools/list_hotels_tool.dart';
import 'widgets/conversation.dart';

Future<void> loadImagesJson() async {
Expand Down Expand Up @@ -45,7 +46,8 @@ class TravelPlannerPage extends StatefulWidget {
State<TravelPlannerPage> createState() => _TravelPlannerPageState();
}

class _TravelPlannerPageState extends State<TravelPlannerPage> {
class _TravelPlannerPageState extends State<TravelPlannerPage>
with AutomaticKeepAliveClientMixin {
late final GenUiManager _genUiManager;
late final AiClient _aiClient;
late final StreamSubscription<UserMessage> _userMessageSubscription;
Expand All @@ -70,12 +72,11 @@ class _TravelPlannerPageState extends State<TravelPlannerPage> {
_userMessageSubscription = _genUiManager.onSubmit.listen(
_handleUserMessageFromUi,
);
final tools = _genUiManager.getTools();
tools.add(ListHotelsTool(onListHotels: onListHotels));
_aiClient =
widget.aiClient ??
FirebaseAiClient(
tools: _genUiManager.getTools(),
systemInstruction: prompt,
);
FirebaseAiClient(tools: tools, systemInstruction: prompt);
_genUiManager.surfaceUpdates.listen((update) {
setState(() {
switch (update) {
Expand Down Expand Up @@ -187,6 +188,7 @@ class _TravelPlannerPageState extends State<TravelPlannerPage> {

@override
Widget build(BuildContext context) {
super.build(context);
return SafeArea(
child: Center(
child: Column(
Expand Down Expand Up @@ -214,6 +216,9 @@ class _TravelPlannerPageState extends State<TravelPlannerPage> {
),
);
}

@override
bool get wantKeepAlive => true;
}

class _ChatInput extends StatelessWidget {
Expand Down Expand Up @@ -330,6 +335,10 @@ to the user.
involves booking every accommodation, transport and activity in the itinerary
one step at a time.

When booking accommodation, you should use the `listHotels` tool to search
for hotels. You can then show the user the different options in a
`travelCarousel`.

Here, you should just focus on one item at a time, using an `inputGroup`
with chips to ask the user for preferences, and the `travelCarousel` to show
the user different options. When the user chooses an option, you can confirm
Expand Down Expand Up @@ -368,7 +377,7 @@ update existing content.
at the bottom of the conversation.
- Updating surfaces: You should update surfaces when you are running an
iterative search flow, e.g. the user is adjusting filter values and generating
an itinerary or a booking accomodation etc. This is less confusing for the user
an itinerary or a booking accommodation etc. This is less confusing for the user
because it avoids confusing the conversation with many versions of the same
itinerary etc.

Expand All @@ -389,7 +398,7 @@ carousel. If there are only 2 or 3 obvious options, just think of some relevant
alternatives that the user might be interested in.

- Guiding the user: When the user has completes some action, e.g. they confirm
they want to book some accomodation or activity, always show a trailhead
they want to book some accommodation or activity, always show a trailhead
suggesting what the user might want to do next (e.g. book the next detail in the
itinerary, repeat a search, research some related topic) so that they can click
rather than typing.
Expand Down
Loading