Skip to content

Commit

Permalink
Formatting changes and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
rlazo committed Jul 16, 2024
1 parent 7fd4a8b commit faea6a2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
1 change: 1 addition & 0 deletions .changes/generativeai/club-bite-carpenter-country.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"MAJOR","changes":["Improve usability of the Schema type in Java"]}
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,6 @@ import com.google.ai.client.generativeai.type.generationConfig

suspend fun json_controlled_generation() {
// [START json_controlled_generation]
val jsonSchema = Schema(
name = "recipes",
description = "List of recipes",
type = FunctionType.ARRAY,
items = Schema(
name = "recipe",
description = "A recipe",
type = FunctionType.OBJECT,
properties = mapOf(
"recipeName" to Schema(
name = "recipeName",
description = "Name of the recipe",
type = FunctionType.STRING,
nullable = false
),
),
required = listOf("recipeName")
),
)

val generativeModel =
GenerativeModel(
// Specify a Gemini model appropriate for your use case
Expand All @@ -58,13 +38,30 @@ suspend fun json_controlled_generation() {
apiKey = BuildConfig.apiKey,
generationConfig = generationConfig {
responseMimeType = "application/json"
responseSchema = jsonSchema
responseSchema = Schema(
name = "recipes",
description = "List of recipes",
type = FunctionType.ARRAY,
items = Schema(
name = "recipe",
description = "A recipe",
type = FunctionType.OBJECT,
properties = mapOf(
"recipeName" to Schema(
name = "recipeName",
description = "Name of the recipe",
type = FunctionType.STRING,
nullable = false
),
),
required = listOf("recipeName")
),
)
})

val prompt = "List a few popular cookie recipes."
val response = generativeModel.generateContent(prompt)
print(response.text)

// [END json_controlled_generation]
}

Expand All @@ -87,6 +84,5 @@ suspend fun json_no_schema() {
""".trimIndent()
val response = generativeModel.generateContent(prompt)
print(response.text)

// [END json_no_schema]
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
class ControlledGeneration {
void jsonControlledGeneration() {
// [START json_controlled_generation]

Schema<List<String>> schema =
new Schema(
/* name */ "recipes",
Expand Down

0 comments on commit faea6a2

Please sign in to comment.