Skip to content

Commit

Permalink
Resolve format issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
BasetEsmaeili committed Jan 18, 2025
1 parent a26c2ac commit 237a835
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ data class Tool(
val functionDeclarations: List<FunctionDeclaration>? = null,
// This is a json object because it is not possible to make a data class with no parameters.
val codeExecution: JsonObject? = null,
val googleSearchRetrieval: GoogleSearchRetrieval? = null
val googleSearchRetrieval: GoogleSearchRetrieval? = null,
)

@Serializable
Expand All @@ -61,20 +61,14 @@ data class FunctionCallingConfig(val mode: Mode) {
@Serializable
data class FunctionDeclaration(val name: String, val description: String, val parameters: Schema)

@Serializable
data class GoogleSearchRetrieval(val dynamicRetrievalConfig: DynamicRetrievalConfig)
@Serializable data class GoogleSearchRetrieval(val dynamicRetrievalConfig: DynamicRetrievalConfig)

@Serializable
data class DynamicRetrievalConfig(
val mode: Mode,
val dynamicThreshold: Float?
) {
data class DynamicRetrievalConfig(val mode: Mode, val dynamicThreshold: Float?) {
@Serializable
enum class Mode {
@SerialName("MODE_DYNAMIC")
DYNAMIC,
@SerialName("MODE_UNSPECIFIED")
UNSPECIFIED
@SerialName("MODE_DYNAMIC") DYNAMIC,
@SerialName("MODE_UNSPECIFIED") UNSPECIFIED
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ internal fun Tool.toInternal() =
com.google.ai.client.generativeai.common.client.Tool(
functionDeclarations?.map { it.toInternal() },
codeExecution = codeExecution?.toInternal(),
googleSearchRetrieval = googleSearchRetrieval?.toInternal()
googleSearchRetrieval = googleSearchRetrieval?.toInternal(),
)

internal fun ToolConfig.toInternal() =
Expand Down Expand Up @@ -193,17 +193,21 @@ internal fun <T> com.google.ai.client.generativeai.type.Schema<T>.toInternal():

internal fun JSONObject.toInternal() = Json.decodeFromString<JsonObject>(toString())

internal fun com.google.ai.client.generativeai.type.GoogleSearchRetrieval.toInternal(): GoogleSearchRetrieval {
internal fun com.google.ai.client.generativeai.type.GoogleSearchRetrieval.toInternal():
GoogleSearchRetrieval {
return GoogleSearchRetrieval(dynamicRetrievalConfig.toInternal())
}

internal fun com.google.ai.client.generativeai.type.DynamicRetrievalConfig.toInternal(): DynamicRetrievalConfig {
internal fun com.google.ai.client.generativeai.type.DynamicRetrievalConfig.toInternal():
DynamicRetrievalConfig {
return DynamicRetrievalConfig(
when (mode) {
DynamicRetrievalMode.DYNAMIC -> com.google.ai.client.generativeai.common.client.DynamicRetrievalConfig.Mode.DYNAMIC
DynamicRetrievalMode.UNSPECIFIED -> com.google.ai.client.generativeai.common.client.DynamicRetrievalConfig.Mode.UNSPECIFIED
DynamicRetrievalMode.DYNAMIC ->
com.google.ai.client.generativeai.common.client.DynamicRetrievalConfig.Mode.DYNAMIC
DynamicRetrievalMode.UNSPECIFIED ->
com.google.ai.client.generativeai.common.client.DynamicRetrievalConfig.Mode.UNSPECIFIED
},
dynamicThreshold
dynamicThreshold,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ package com.google.ai.client.generativeai.type
import androidx.annotation.FloatRange

/*
* Specifies the dynamic retrieval configuration for the given source.
*/
* Specifies the dynamic retrieval configuration for the given source.
*/
data class DynamicRetrievalConfig(
/*
* The mode of the predictor to be used in dynamic retrieval.
*/
val mode: DynamicRetrievalMode,
/*
* (Optional) The threshold to be used in dynamic retrieval. If not set, a system default value is used.
*/
@FloatRange(0.0, 1.0)
val dynamicThreshold: Float? = null
/*
* The mode of the predictor to be used in dynamic retrieval.
*/
val mode: DynamicRetrievalMode,
/*
* (Optional) The threshold to be used in dynamic retrieval. If not set, a system default value is used.
*/
@FloatRange(0.0, 1.0) val dynamicThreshold: Float? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package com.google.ai.client.generativeai.type

/*
* The mode of the predictor to be used in [DynamicRetrievalConfig].
*/
* The mode of the predictor to be used in [DynamicRetrievalConfig].
*/
enum class DynamicRetrievalMode {
DYNAMIC,
UNSPECIFIED
DYNAMIC,
UNSPECIFIED
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,5 @@

package com.google.ai.client.generativeai.type

/**
* Retrieval tool that is powered by Google search.
*/
data class GoogleSearchRetrieval(
val dynamicRetrievalConfig: DynamicRetrievalConfig
)
/** Retrieval tool that is powered by Google search. */
data class GoogleSearchRetrieval(val dynamicRetrievalConfig: DynamicRetrievalConfig)
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Tool
constructor(
val functionDeclarations: List<FunctionDeclaration>? = null,
val codeExecution: JSONObject? = null,
val googleSearchRetrieval: GoogleSearchRetrieval? = null
val googleSearchRetrieval: GoogleSearchRetrieval? = null,
) {
companion object {
@JvmField val CODE_EXECUTION = Tool(codeExecution = JSONObject())
Expand Down

0 comments on commit 237a835

Please sign in to comment.