I'm trying to follow the Quickstart: Get started with the Gemini API in Android
, but I get the following server error:
com.google.ai.client.generativeai.type.ServerException: * GenerateContentRequest.model: unexpected model name format
Here is my code:
@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
val generativeModel = GenerativeModel(
// Use a model that's applicable for your use case (see "Implement basic use cases" below)
modelName = "MODEL_NAME",
// Access your API key as a Build Configuration variable (see "Set up your API key" above)
apiKey = dreambig.apps.aiexpriments.BuildConfig.GOOGLE_AI_API_KEY
)
var story: String by remember {
mutableStateOf("")
}
Column(modifier = Modifier
.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Text(
text = "Hello $name!",
modifier = modifier
)
Button(onClick = {
val prompt = "Write a story about a backpack."
GlobalScope.launch {
val response = generativeModel.generateContent(prompt)
print(response.text)
story = response.text.toString()
}
}) {
Text("Tell me a story")
}
Spacer(modifier = Modifier.padding(16.dp))
Text(story)
}
}
You didn't specify a model.
You need set a valid
modelName
like this example:You can access details about the models from the link below.
Gemini Models