Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import 'package:flutter/material.dart';
import 'package:firebase_ai/firebase_ai.dart';
import 'package:firebase_auth/firebase_auth.dart';
import '../utils/function_call_utils.dart';
import '../widgets/message_widget.dart';

class FunctionCallingPage extends StatefulWidget {
Expand All @@ -31,13 +32,6 @@ class FunctionCallingPage extends StatefulWidget {
State<FunctionCallingPage> createState() => _FunctionCallingPageState();
}

class Location {
final String city;
final String state;

Location(this.city, this.state);
}

class _FunctionCallingPageState extends State<FunctionCallingPage> {
late GenerativeModel _functionCallModel;
late GenerativeModel _autoFunctionCallModel;
Expand Down Expand Up @@ -76,7 +70,7 @@ class _FunctionCallingPageState extends State<FunctionCallingPage> {
'The date for which to get the weather. Date must be in the format: YYYY-MM-DD.',
),
},
callable: _fetchWeatherCallable,
callable: fetchWeatherCallable,
);
_autoFindRestaurantsTool = AutoFunctionDeclaration(
name: 'findRestaurants',
Expand Down Expand Up @@ -148,16 +142,6 @@ class _FunctionCallingPageState extends State<FunctionCallingPage> {
};
}

Future<Map<String, Object?>> _fetchWeatherCallable(
Map<String, Object?> args,
) async {
final locationData = args['location']! as Map<String, Object?>;
final city = locationData['city']! as String;
final state = locationData['state']! as String;
final date = args['date']! as String;
return fetchWeather(Location(city, state), date);
}

void _initializeModel() {
final generationConfig = GenerationConfig(
thinkingConfig: _enableThinking
Expand Down Expand Up @@ -204,23 +188,6 @@ class _FunctionCallingPageState extends State<FunctionCallingPage> {
);
}

// This is a hypothetical API to return a fake weather data collection for
// certain location
Future<Map<String, Object?>> fetchWeather(
Location location,
String date,
) async {
// TODO(developer): Call a real weather API.
// Mock response from the API. In developer live code this would call the
// external API and return what that API returns.
final apiResponse = {
'temperature': 38,
'chancePrecipitation': '56%',
'cloudConditions': 'partly-cloudy',
};
return apiResponse;
}

/// Actual function to demonstrate the function calling feature.
final fetchWeatherTool = FunctionDeclaration(
'fetchWeather',
Expand Down
Loading
Loading