Skip to content

Several small changes to enums API #6294

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

Merged
merged 5 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ import com.google.firebase.vertexai.common.shared.FunctionCall
import com.google.firebase.vertexai.common.shared.FunctionCallPart
import com.google.firebase.vertexai.common.shared.FunctionResponse
import com.google.firebase.vertexai.common.shared.FunctionResponsePart
import com.google.firebase.vertexai.common.shared.HarmBlockThreshold
import com.google.firebase.vertexai.type.BlobPart
import com.google.firebase.vertexai.type.BlockReason
import com.google.firebase.vertexai.type.BlockThreshold
import com.google.firebase.vertexai.type.Candidate
import com.google.firebase.vertexai.type.Citation
import com.google.firebase.vertexai.type.CitationMetadata
Expand All @@ -41,6 +39,7 @@ import com.google.firebase.vertexai.type.FunctionCallingConfig
import com.google.firebase.vertexai.type.FunctionDeclaration
import com.google.firebase.vertexai.type.GenerateContentResponse
import com.google.firebase.vertexai.type.GenerationConfig
import com.google.firebase.vertexai.type.HarmBlockThreshold
import com.google.firebase.vertexai.type.HarmCategory
import com.google.firebase.vertexai.type.HarmProbability
import com.google.firebase.vertexai.type.HarmSeverity
Expand Down Expand Up @@ -138,13 +137,16 @@ internal fun ToolConfig.toInternal() =
)
)

internal fun BlockThreshold.toInternal() =
internal fun HarmBlockThreshold.toInternal() =
when (this) {
BlockThreshold.NONE -> HarmBlockThreshold.BLOCK_NONE
BlockThreshold.ONLY_HIGH -> HarmBlockThreshold.BLOCK_ONLY_HIGH
BlockThreshold.MEDIUM_AND_ABOVE -> HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE
BlockThreshold.LOW_AND_ABOVE -> HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
BlockThreshold.UNSPECIFIED -> HarmBlockThreshold.UNSPECIFIED
HarmBlockThreshold.NONE ->
com.google.firebase.vertexai.common.shared.HarmBlockThreshold.BLOCK_NONE
HarmBlockThreshold.ONLY_HIGH ->
com.google.firebase.vertexai.common.shared.HarmBlockThreshold.BLOCK_ONLY_HIGH
HarmBlockThreshold.MEDIUM_AND_ABOVE ->
com.google.firebase.vertexai.common.shared.HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE
HarmBlockThreshold.LOW_AND_ABOVE ->
com.google.firebase.vertexai.common.shared.HarmBlockThreshold.BLOCK_LOW_AND_ABOVE
}

internal fun Tool.toInternal() =
Expand Down Expand Up @@ -258,8 +260,7 @@ internal fun com.google.firebase.vertexai.common.server.FinishReason?.toPublic()
com.google.firebase.vertexai.common.server.FinishReason.SAFETY -> FinishReason.SAFETY
com.google.firebase.vertexai.common.server.FinishReason.STOP -> FinishReason.STOP
com.google.firebase.vertexai.common.server.FinishReason.OTHER -> FinishReason.OTHER
com.google.firebase.vertexai.common.server.FinishReason.UNSPECIFIED -> FinishReason.UNSPECIFIED
com.google.firebase.vertexai.common.server.FinishReason.UNKNOWN -> FinishReason.UNKNOWN
else -> FinishReason.UNKNOWN
}

internal fun com.google.firebase.vertexai.common.shared.HarmCategory.toPublic() =
Expand All @@ -270,7 +271,7 @@ internal fun com.google.firebase.vertexai.common.shared.HarmCategory.toPublic()
HarmCategory.SEXUALLY_EXPLICIT
com.google.firebase.vertexai.common.shared.HarmCategory.DANGEROUS_CONTENT ->
HarmCategory.DANGEROUS_CONTENT
com.google.firebase.vertexai.common.shared.HarmCategory.UNKNOWN -> HarmCategory.UNKNOWN
else -> HarmCategory.UNKNOWN
}

internal fun com.google.firebase.vertexai.common.server.HarmProbability.toPublic() =
Expand All @@ -280,9 +281,7 @@ internal fun com.google.firebase.vertexai.common.server.HarmProbability.toPublic
com.google.firebase.vertexai.common.server.HarmProbability.LOW -> HarmProbability.LOW
com.google.firebase.vertexai.common.server.HarmProbability.NEGLIGIBLE ->
HarmProbability.NEGLIGIBLE
com.google.firebase.vertexai.common.server.HarmProbability.UNSPECIFIED ->
HarmProbability.UNSPECIFIED
com.google.firebase.vertexai.common.server.HarmProbability.UNKNOWN -> HarmProbability.UNKNOWN
else -> HarmProbability.UNKNOWN
}

internal fun com.google.firebase.vertexai.common.server.HarmSeverity.toPublic() =
Expand All @@ -291,16 +290,14 @@ internal fun com.google.firebase.vertexai.common.server.HarmSeverity.toPublic()
com.google.firebase.vertexai.common.server.HarmSeverity.MEDIUM -> HarmSeverity.MEDIUM
com.google.firebase.vertexai.common.server.HarmSeverity.LOW -> HarmSeverity.LOW
com.google.firebase.vertexai.common.server.HarmSeverity.NEGLIGIBLE -> HarmSeverity.NEGLIGIBLE
com.google.firebase.vertexai.common.server.HarmSeverity.UNSPECIFIED -> HarmSeverity.UNSPECIFIED
com.google.firebase.vertexai.common.server.HarmSeverity.UNKNOWN -> HarmSeverity.UNKNOWN
else -> HarmSeverity.UNKNOWN
}

internal fun com.google.firebase.vertexai.common.server.BlockReason.toPublic() =
when (this) {
com.google.firebase.vertexai.common.server.BlockReason.UNSPECIFIED -> BlockReason.UNSPECIFIED
com.google.firebase.vertexai.common.server.BlockReason.SAFETY -> BlockReason.SAFETY
com.google.firebase.vertexai.common.server.BlockReason.OTHER -> BlockReason.OTHER
com.google.firebase.vertexai.common.server.BlockReason.UNKNOWN -> BlockReason.UNKNOWN
else -> BlockReason.UNKNOWN
}

internal fun com.google.firebase.vertexai.common.GenerateContentResponse.toPublic():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ enum class FinishReason {
/** A new and not yet supported value. */
UNKNOWN,

/** Reason is unspecified. */
UNSPECIFIED,

/** Model finished successfully and stopped. */
STOP,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ package com.google.firebase.vertexai.type
* Represents a response measuring model input.
*
* @property totalTokens A count of the tokens in the input
* @property totalBillableCharacters A count of the characters that are billable in the input
* @property totalBillableCharacters A count of the characters that are billable in the input, if
* available.
*/
class CountTokensResponse(val totalTokens: Int, val totalBillableCharacters: Int) {
class CountTokensResponse(val totalTokens: Int, val totalBillableCharacters: Int? = null) {
operator fun component1() = totalTokens

operator fun component2() = totalBillableCharacters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ package com.google.firebase.vertexai.type
/**
* Represents the threshold for some [HarmCategory] that is allowed and blocked by [SafetySetting].
*/
enum class BlockThreshold {
/** The threshold was not specified. */
UNSPECIFIED,

enum class HarmBlockThreshold {
/** Content with negligible harm is allowed. */
LOW_AND_ABOVE,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ enum class HarmProbability {
/** A new and not yet supported value. */
UNKNOWN,

/** Probability for harm is unspecified. */
UNSPECIFIED,

/** Probability for harm is negligible. */
NEGLIGIBLE,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ enum class HarmSeverity {
/** A new and not yet supported value. */
UNKNOWN,

/** Severity for harm is unspecified. */
UNSPECIFIED,

/** Severity for harm is negligible. */
NEGLIGIBLE,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ enum class BlockReason {
/** A new and not yet supported value. */
UNKNOWN,

/** Content was blocked for an unspecified reason. */
UNSPECIFIED,

/** Content was blocked for violating provided [SafetySetting]. */
SAFETY,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
package com.google.firebase.vertexai.type

/**
* A configuration for a [BlockThreshold] of some [HarmCategory] allowed and blocked in responses.
* A configuration for a [HarmBlockThreshold] of some [HarmCategory] allowed and blocked in
* responses.
*
* @param harmCategory The relevant [HarmCategory].
* @param threshold The threshold form harm allowable.
*/
class SafetySetting(val harmCategory: HarmCategory, val threshold: BlockThreshold) {}
class SafetySetting(val harmCategory: HarmCategory, val threshold: HarmBlockThreshold) {}
Loading