Skip to content
Open
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
1 change: 0 additions & 1 deletion packages/firebase_ai/firebase_ai/example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ class _FunctionCallingPageState extends State<FunctionCallingPage> {
late GenerativeModel _functionCallModel;
late GenerativeModel _autoFunctionCallModel;
late GenerativeModel _parallelAutoFunctionCallModel;
late GenerativeModel _complexJSONSchemaModel;
late GenerativeModel _refSchemaModel;
late GenerativeModel _codeExecutionModel;
late final AutoFunctionDeclaration _autoFetchWeatherTool;
late final AutoFunctionDeclaration _autoPlanVacationTool;
late final AutoFunctionDeclaration _autoProcessTransactionTool;
final List<MessageData> _messages = <MessageData>[];
bool _loading = false;
bool _enableThinking = false;
Expand Down Expand Up @@ -113,6 +117,73 @@ class _FunctionCallingPageState extends State<FunctionCallingPage> {
return getRestaurantMenu(restaurantName);
},
);
_autoPlanVacationTool = AutoFunctionDeclaration(
name: 'planVacation',
description:
'Plans a complex vacation itinerary combining flights, hotels, and activities.',
useJSONSchema: true,
parameters: {
'destination':
Schema.string(description: 'The city or country to travel to.'),
'travelers': Schema.integer(
description: 'Number of travelers.', minimum: 1, maximum: 10),
'travelClass': Schema.enumString(
enumValues: ['ECONOMY', 'BUSINESS', 'FIRST'],
description: 'The preferred travel class.',
),
'budget':
Schema.number(description: 'Total budget for the trip in USD.'),
'activities': Schema.array(
items: Schema.string(),
description: 'A list of preferred activities.',
minItems: 1,
),
'accommodations': Schema.object(
description: 'Hotel preferences.',
properties: {
'hotelType': Schema.string(),
'stars': Schema.integer(minimum: 1, maximum: 5),
'amenities': Schema.array(items: Schema.string()),
},
optionalProperties: ['amenities'],
),
},
callable: (args) async {
return {
'status': 'SUCCESS',
'itineraryId': 'TRIP-98765',
'destination': args['destination'],
'estimatedCost': 3500.0,
'message': 'Vacation planned successfully!',
};
},
);
_autoProcessTransactionTool = AutoFunctionDeclaration(
name: 'processTransaction',
description:
'Processes a financial transaction using a predefined transaction model reference.',
useJSONSchema: true,
parameters: {
'baseTransaction': Schema.object(
description: 'The base transaction block.',
properties: {
'amount': Schema.number(),
'transactionId': Schema.integer(),
},
),
'transaction': Schema.ref('#/properties/baseTransaction'),
},
callable: (args) async {
final transaction = args['transaction'] as Map<String, dynamic>?;
return {
'status': 'SUCCESS',
'amountProcessed': transaction?['amount'],
'transactionId': transaction?['transactionId'],
'message':
'Transaction processed successfully using the reference schema!',
};
},
);
_initializeModel();
}

Expand Down Expand Up @@ -202,6 +273,20 @@ class _FunctionCallingPageState extends State<FunctionCallingPage> {
Tool.codeExecution(),
],
);
_complexJSONSchemaModel = aiClient.generativeModel(
model: 'gemini-2.5-flash',
generationConfig: generationConfig,
tools: [
Tool.functionDeclarations([_autoPlanVacationTool]),
],
);
_refSchemaModel = aiClient.generativeModel(
model: 'gemini-2.5-flash',
generationConfig: generationConfig,
tools: [
Tool.functionDeclarations([_autoProcessTransactionTool]),
],
);
}

// This is a hypothetical API to return a fake weather data collection for
Expand Down Expand Up @@ -375,6 +460,28 @@ class _FunctionCallingPageState extends State<FunctionCallingPage> {
),
],
),
const SizedBox(height: 8),
Row(
children: [
Expanded(
child: ElevatedButton(
onPressed: !_loading
? _testComplexJSONSchemaAutoFunctionCalling
: null,
child: const Text('Complex JSON Schema FC'),
),
),
const SizedBox(width: 8),
Expanded(
child: ElevatedButton(
onPressed: !_loading
? _testRefSchemaAutoFunctionCalling
: null,
child: const Text('Ref Schema FC'),
),
),
],
),
],
),
),
Expand Down Expand Up @@ -608,6 +715,56 @@ class _FunctionCallingPageState extends State<FunctionCallingPage> {
});
}

Future<void> _testComplexJSONSchemaAutoFunctionCalling() async {
await _runTest(() async {
final chat = _complexJSONSchemaModel.startChat();
const prompt =
'I want to plan a vacation to Paris for 2 people. We want to fly Business class, our budget is 5500 USD. We want to do wine tasting and museum tours. We prefer a 4-star boutique hotel with free breakfast.';

_messages.add(MessageData(text: prompt, fromUser: true));
setState(() {});

final response = await chat.sendMessage(Content.text(prompt));

final thought = response.thoughtSummary;
if (thought != null) {
_messages
.add(MessageData(text: thought, fromUser: false, isThought: true));
}

if (response.text case final text?) {
_messages.add(MessageData(text: text));
} else {
_messages.add(MessageData(text: 'No text response from model.'));
}
});
}

Future<void> _testRefSchemaAutoFunctionCalling() async {
await _runTest(() async {
final chat = _refSchemaModel.startChat();
const prompt =
r'Process a transaction of \$50.00 for a pair of shoes. The transaction ID is 98765.';

_messages.add(MessageData(text: prompt, fromUser: true));
setState(() {});

final response = await chat.sendMessage(Content.text(prompt));

final thought = response.thoughtSummary;
if (thought != null) {
_messages
.add(MessageData(text: thought, fromUser: false, isThought: true));
}

if (response.text case final text?) {
_messages.add(MessageData(text: text));
} else {
_messages.add(MessageData(text: 'No text response from model.'));
}
});
}

void _showError(String message) {
showDialog<void>(
context: context,
Expand Down
1 change: 0 additions & 1 deletion packages/firebase_ai/firebase_ai/example/macos/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ flutter_macos_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
Expand Down

This file was deleted.

Loading
Loading