-
Notifications
You must be signed in to change notification settings - Fork 7.4k
feat(firebase-ai): add function calling example #2678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.google.firebase.quickstart.ai.feature.text.functioncalling | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import kotlinx.serialization.json.JsonObject | ||
import kotlinx.serialization.json.JsonPrimitive | ||
|
||
/** | ||
* Hypothetical repository that calls an external weather API. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A more accessible option (language-wise) is "Example repository". |
||
*/ | ||
class WeatherRepository { | ||
|
||
companion object { | ||
suspend fun fetchWeather( | ||
city: String, state: String, date: String | ||
): JsonObject = withContext(Dispatchers.IO) { | ||
// For demo purposes, this hypothetical response is | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, I'd rephrase it to something along the lines of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @marinacoelho I copied this from the docs, but we could discuss changing the docs too if it makes more sense |
||
// hardcoded here in the expected format. | ||
return@withContext JsonObject( | ||
mapOf( | ||
"temperature" to JsonPrimitive(38), | ||
"chancePrecipitation" to JsonPrimitive("56%"), | ||
"cloudConditions" to JsonPrimitive("partlyCloudy") | ||
) | ||
) | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid confusion on what string should be sent as "city", "state" and "date", I'd send an empty string on this code sample and add a code comment on the line above, with something along the lines of
// Replace this empty string with the US city of choice
. (Same for state and date).