Skip to content

Commit

Permalink
apply documentation update
Browse files Browse the repository at this point in the history
  • Loading branch information
cynthiajoan committed Sep 25, 2024
1 parent 06e76f4 commit 36a96e4
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,17 @@ class _ChatWidgetState extends State<ChatWidget> {
Future<Map<String, Object?>> getWeather(
Map<String, Object?> arguments,
) async {
final jsonResponse = {
/// Possible external api call
/// apiResponse = await requests.post(weather_api_url, data={'location': arguments['location']})
/// Mock up apiResponse
final apiResponse = {
'location': arguments['location'],
'temperature': 38,
'chancePrecipitation': '56%',
'cloudConditions': 'partly-cloudy',
};
return jsonResponse;
return apiResponse;
}

final getWeatherTool = FunctionDeclaration(
Expand Down Expand Up @@ -539,12 +543,13 @@ class _ChatWidgetState extends State<ChatWidget> {
if (functionCalls.isNotEmpty) {
final functionCall = functionCalls.first;
final functionResult = switch (functionCall.name) {
// Forward arguments to the hypothetical API.
// Forward the structured input data prepared by the model
// to the hypothetical external API.
'getCurrentWeather' => await getWeather(functionCall.args),
// Throw an exception if the model attempted to call a function that was
// not declared.
_ => throw UnimplementedError(
'Function not implemented: ${functionCall.name}',
'Function not declared to the model: ${functionCall.name}',
)
};
// Send the response to the model so that it can use the result to generate
Expand Down

0 comments on commit 36a96e4

Please sign in to comment.