diff --git a/firebase-vertexai/firebase-vertexai.gradle.kts b/firebase-vertexai/firebase-vertexai.gradle.kts index 9bdabd0f0ce..018a41429d1 100644 --- a/firebase-vertexai/firebase-vertexai.gradle.kts +++ b/firebase-vertexai/firebase-vertexai.gradle.kts @@ -16,6 +16,9 @@ @file:Suppress("UnstableApiUsage") +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + + plugins { id("firebase-library") id("kotlin-android") @@ -66,6 +69,21 @@ android { } } +// Enable Kotlin "Explicit API Mode". This causes the Kotlin compiler to fail if any +// classes, methods, or properties have implicit `public` visibility. This check helps +// avoid accidentally leaking elements into the public API, requiring that any public +// element be explicitly declared as `public`. +// https://github.com/Kotlin/KEEP/blob/master/proposals/explicit-api-mode.md +// https://chao2zhang.medium.com/explicit-api-mode-for-kotlin-on-android-b8264fdd76d1 +tasks.withType().all { + if (!name.contains("test", ignoreCase = true)) { + if (!kotlinOptions.freeCompilerArgs.contains("-Xexplicit-api=strict")) { + kotlinOptions.freeCompilerArgs += "-Xexplicit-api=strict" + } + } +} + + dependencies { val ktorVersion = "2.3.2" diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/Chat.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/Chat.kt index e44adea961a..59c507c47a0 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/Chat.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/Chat.kt @@ -42,7 +42,10 @@ import kotlinx.coroutines.flow.onEach * @param model The model to use for the interaction * @property history The previous interactions with the model */ -class Chat(private val model: GenerativeModel, val history: MutableList = ArrayList()) { +public class Chat( + private val model: GenerativeModel, + public val history: MutableList = ArrayList() +) { private var lock = Semaphore(1) /** @@ -53,7 +56,7 @@ class Chat(private val model: GenerativeModel, val history: MutableList * @throws InvalidStateException if the prompt is not coming from the 'user' role * @throws InvalidStateException if the [Chat] instance has an active request. */ - suspend fun sendMessage(prompt: Content): GenerateContentResponse { + public suspend fun sendMessage(prompt: Content): GenerateContentResponse { prompt.assertComesFromUser() attemptLock() try { @@ -72,7 +75,7 @@ class Chat(private val model: GenerativeModel, val history: MutableList * @param prompt The text to be converted into a single piece of [Content] to send to the model. * @throws InvalidStateException if the [Chat] instance has an active request. */ - suspend fun sendMessage(prompt: String): GenerateContentResponse { + public suspend fun sendMessage(prompt: String): GenerateContentResponse { val content = content { text(prompt) } return sendMessage(content) } @@ -83,7 +86,7 @@ class Chat(private val model: GenerativeModel, val history: MutableList * @param prompt The image to be converted into a single piece of [Content] to send to the model. * @throws InvalidStateException if the [Chat] instance has an active request. */ - suspend fun sendMessage(prompt: Bitmap): GenerateContentResponse { + public suspend fun sendMessage(prompt: Bitmap): GenerateContentResponse { val content = content { image(prompt) } return sendMessage(content) } @@ -96,7 +99,7 @@ class Chat(private val model: GenerativeModel, val history: MutableList * @throws InvalidStateException if the prompt is not coming from the 'user' role * @throws InvalidStateException if the [Chat] instance has an active request. */ - fun sendMessageStream(prompt: Content): Flow { + public fun sendMessageStream(prompt: Content): Flow { prompt.assertComesFromUser() attemptLock() @@ -149,7 +152,7 @@ class Chat(private val model: GenerativeModel, val history: MutableList * @return A [Flow] which will emit responses as they are returned from the model. * @throws InvalidStateException if the [Chat] instance has an active request. */ - fun sendMessageStream(prompt: String): Flow { + public fun sendMessageStream(prompt: String): Flow { val content = content { text(prompt) } return sendMessageStream(content) } @@ -161,7 +164,7 @@ class Chat(private val model: GenerativeModel, val history: MutableList * @return A [Flow] which will emit responses as they are returned from the model. * @throws InvalidStateException if the [Chat] instance has an active request. */ - fun sendMessageStream(prompt: Bitmap): Flow { + public fun sendMessageStream(prompt: Bitmap): Flow { val content = content { image(prompt) } return sendMessageStream(content) } diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseVertexAI.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseVertexAI.kt index c19326a1682..145dd90b121 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseVertexAI.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseVertexAI.kt @@ -31,7 +31,7 @@ import com.google.firebase.vertexai.type.Tool import com.google.firebase.vertexai.type.ToolConfig /** Entry point for all _Vertex AI for Firebase_ functionality. */ -class FirebaseVertexAI +public class FirebaseVertexAI internal constructor( private val firebaseApp: FirebaseApp, private val location: String, @@ -51,7 +51,7 @@ internal constructor( * @param systemInstruction contains a [Content] that directs the model to behave a certain way */ @JvmOverloads - fun generativeModel( + public fun generativeModel( modelName: String, generationConfig: GenerationConfig? = null, safetySettings: List? = null, @@ -77,13 +77,13 @@ internal constructor( ) } - companion object { + public companion object { /** The [FirebaseVertexAI] instance for the default [FirebaseApp] */ @JvmStatic - val instance: FirebaseVertexAI + public val instance: FirebaseVertexAI get() = getInstance(location = "us-central1") - @JvmStatic fun getInstance(app: FirebaseApp): FirebaseVertexAI = getInstance(app) + @JvmStatic public fun getInstance(app: FirebaseApp): FirebaseVertexAI = getInstance(app) /** * Returns the [FirebaseVertexAI] instance for the provided [FirebaseApp] and [location] @@ -93,7 +93,7 @@ internal constructor( */ @JvmStatic @JvmOverloads - fun getInstance(app: FirebaseApp = Firebase.app, location: String): FirebaseVertexAI { + public fun getInstance(app: FirebaseApp = Firebase.app, location: String): FirebaseVertexAI { val multiResourceComponent = app[FirebaseVertexAIMultiResourceComponent::class.java] return multiResourceComponent.get(location) } @@ -101,11 +101,11 @@ internal constructor( } /** Returns the [FirebaseVertexAI] instance of the default [FirebaseApp]. */ -val Firebase.vertexAI: FirebaseVertexAI +public val Firebase.vertexAI: FirebaseVertexAI get() = FirebaseVertexAI.instance /** Returns the [FirebaseVertexAI] instance of a given [FirebaseApp]. */ -fun Firebase.vertexAI( +public fun Firebase.vertexAI( app: FirebaseApp = Firebase.app, location: String = "us-central1" ): FirebaseVertexAI = FirebaseVertexAI.getInstance(app, location) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/GenerativeModel.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/GenerativeModel.kt index 50769073fa5..3f3fc260c71 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/GenerativeModel.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/GenerativeModel.kt @@ -50,7 +50,7 @@ import kotlinx.coroutines.tasks.await /** * A controller for communicating with the API of a given multimodal model (for example, Gemini). */ -class GenerativeModel +public class GenerativeModel internal constructor( private val modelName: String, private val generationConfig: GenerationConfig? = null, @@ -128,7 +128,7 @@ internal constructor( * @return A [GenerateContentResponse]. Function should be called within a suspend context to * properly manage concurrency. */ - suspend fun generateContent(vararg prompt: Content): GenerateContentResponse = + public suspend fun generateContent(vararg prompt: Content): GenerateContentResponse = try { controller.generateContent(constructRequest(*prompt)).toPublic().validate() } catch (e: Throwable) { @@ -141,7 +141,7 @@ internal constructor( * @param prompt [Content] to send to the model. * @return A [Flow] which will emit responses as they are returned from the model. */ - fun generateContentStream(vararg prompt: Content): Flow = + public fun generateContentStream(vararg prompt: Content): Flow = controller .generateContentStream(constructRequest(*prompt)) .catch { throw FirebaseVertexAIException.from(it) } @@ -154,7 +154,7 @@ internal constructor( * @return A [GenerateContentResponse] after some delay. Function should be called within a * suspend context to properly manage concurrency. */ - suspend fun generateContent(prompt: String): GenerateContentResponse = + public suspend fun generateContent(prompt: String): GenerateContentResponse = generateContent(content { text(prompt) }) /** @@ -163,7 +163,7 @@ internal constructor( * @param prompt The text to be converted into a single piece of [Content] to send to the model. * @return A [Flow] which will emit responses as they are returned from the model. */ - fun generateContentStream(prompt: String): Flow = + public fun generateContentStream(prompt: String): Flow = generateContentStream(content { text(prompt) }) /** @@ -173,7 +173,7 @@ internal constructor( * @return A [GenerateContentResponse] after some delay. Function should be called within a * suspend context to properly manage concurrency. */ - suspend fun generateContent(prompt: Bitmap): GenerateContentResponse = + public suspend fun generateContent(prompt: Bitmap): GenerateContentResponse = generateContent(content { image(prompt) }) /** @@ -182,11 +182,12 @@ internal constructor( * @param prompt The image to be converted into a single piece of [Content] to send to the model. * @return A [Flow] which will emit responses as they are returned from the model. */ - fun generateContentStream(prompt: Bitmap): Flow = + public fun generateContentStream(prompt: Bitmap): Flow = generateContentStream(content { image(prompt) }) /** Creates a [Chat] instance which internally tracks the ongoing conversation with the model */ - fun startChat(history: List = emptyList()): Chat = Chat(this, history.toMutableList()) + public fun startChat(history: List = emptyList()): Chat = + Chat(this, history.toMutableList()) /** * Counts the amount of tokens in a prompt. @@ -194,7 +195,7 @@ internal constructor( * @param prompt A group of [Content] to count tokens of. * @return A [CountTokensResponse] containing the amount of tokens in the prompt. */ - suspend fun countTokens(vararg prompt: Content): CountTokensResponse { + public suspend fun countTokens(vararg prompt: Content): CountTokensResponse { try { return controller.countTokens(constructCountTokensRequest(*prompt)).toPublic() } catch (e: Throwable) { @@ -208,7 +209,7 @@ internal constructor( * @param prompt The text to be converted to a single piece of [Content] to count the tokens of. * @return A [CountTokensResponse] containing the amount of tokens in the prompt. */ - suspend fun countTokens(prompt: String): CountTokensResponse { + public suspend fun countTokens(prompt: String): CountTokensResponse { return countTokens(content { text(prompt) }) } @@ -218,7 +219,7 @@ internal constructor( * @param prompt The image to be converted to a single piece of [Content] to count the tokens of. * @return A [CountTokensResponse] containing the amount of tokens in the prompt. */ - suspend fun countTokens(prompt: Bitmap): CountTokensResponse { + public suspend fun countTokens(prompt: Bitmap): CountTokensResponse { return countTokens(content { image(prompt) }) } @@ -247,7 +248,7 @@ internal constructor( ?.let { throw ResponseStoppedException(this) } } - companion object { + private companion object { private val TAG = GenerativeModel::class.java.simpleName } } diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/common/shared/Types.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/common/shared/Types.kt index b70603c5de0..f6c1bc22b88 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/common/shared/Types.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/common/shared/Types.kt @@ -41,7 +41,7 @@ internal enum class HarmCategory { @SerialName("HARM_CATEGORY_DANGEROUS_CONTENT") DANGEROUS_CONTENT } -typealias Base64 = String +internal typealias Base64 = String @ExperimentalSerializationApi @Serializable diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/java/ChatFutures.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/java/ChatFutures.kt index ee20e462be5..d6b1a4e5e22 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/java/ChatFutures.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/java/ChatFutures.kt @@ -29,7 +29,7 @@ import org.reactivestreams.Publisher * * @see from */ -abstract class ChatFutures internal constructor() { +public abstract class ChatFutures internal constructor() { /** * Generates a response from the backend with the provided [Content], and any previous ones @@ -37,17 +37,17 @@ abstract class ChatFutures internal constructor() { * * @param prompt A [Content] to send to the model. */ - abstract fun sendMessage(prompt: Content): ListenableFuture + public abstract fun sendMessage(prompt: Content): ListenableFuture /** * Generates a streaming response from the backend with the provided [Content]. * * @param prompt A [Content] to send to the model. */ - abstract fun sendMessageStream(prompt: Content): Publisher + public abstract fun sendMessageStream(prompt: Content): Publisher /** Returns the [Chat] instance that was used to create this instance */ - abstract fun getChat(): Chat + public abstract fun getChat(): Chat private class FuturesImpl(private val chat: Chat) : ChatFutures() { override fun sendMessage(prompt: Content): ListenableFuture = @@ -59,9 +59,9 @@ abstract class ChatFutures internal constructor() { override fun getChat(): Chat = chat } - companion object { + public companion object { /** @return a [ChatFutures] created around the provided [Chat] */ - @JvmStatic fun from(chat: Chat): ChatFutures = FuturesImpl(chat) + @JvmStatic public fun from(chat: Chat): ChatFutures = FuturesImpl(chat) } } diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/java/GenerativeModelFutures.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/java/GenerativeModelFutures.kt index 1144df72d1a..fe43e0b69a2 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/java/GenerativeModelFutures.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/java/GenerativeModelFutures.kt @@ -31,41 +31,45 @@ import org.reactivestreams.Publisher * * @see from */ -abstract class GenerativeModelFutures internal constructor() { +public abstract class GenerativeModelFutures internal constructor() { /** * Generates a response from the backend with the provided [Content]. * * @param prompt A group of [Content] to send to the model. */ - abstract fun generateContent(vararg prompt: Content): ListenableFuture + public abstract fun generateContent( + vararg prompt: Content + ): ListenableFuture /** * Generates a streaming response from the backend with the provided [Content]. * * @param prompt A group of [Content] to send to the model. */ - abstract fun generateContentStream(vararg prompt: Content): Publisher + public abstract fun generateContentStream( + vararg prompt: Content + ): Publisher /** * Counts the number of tokens used in a prompt. * * @param prompt A group of [Content] to count tokens of. */ - abstract fun countTokens(vararg prompt: Content): ListenableFuture + public abstract fun countTokens(vararg prompt: Content): ListenableFuture /** Creates a chat instance which internally tracks the ongoing conversation with the model */ - abstract fun startChat(): ChatFutures + public abstract fun startChat(): ChatFutures /** * Creates a chat instance which internally tracks the ongoing conversation with the model * * @param history an existing history of context to use as a starting point */ - abstract fun startChat(history: List): ChatFutures + public abstract fun startChat(history: List): ChatFutures /** Returns the [GenerativeModel] instance that was used to create this object */ - abstract fun getGenerativeModel(): GenerativeModel + public abstract fun getGenerativeModel(): GenerativeModel private class FuturesImpl(private val model: GenerativeModel) : GenerativeModelFutures() { override fun generateContent( @@ -86,9 +90,9 @@ abstract class GenerativeModelFutures internal constructor() { override fun getGenerativeModel(): GenerativeModel = model } - companion object { + public companion object { /** @return a [GenerativeModelFutures] created around the provided [GenerativeModel] */ - @JvmStatic fun from(model: GenerativeModel): GenerativeModelFutures = FuturesImpl(model) + @JvmStatic public fun from(model: GenerativeModel): GenerativeModelFutures = FuturesImpl(model) } } diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Candidate.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Candidate.kt index 5538c24e139..a5ac3d83716 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Candidate.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Candidate.kt @@ -19,23 +19,23 @@ package com.google.firebase.vertexai.type import java.util.Calendar /** A response generated by the model. */ -class Candidate +public class Candidate internal constructor( - val content: Content, - val safetyRatings: List, - val citationMetadata: CitationMetadata?, - val finishReason: FinishReason? + public val content: Content, + public val safetyRatings: List, + public val citationMetadata: CitationMetadata?, + public val finishReason: FinishReason? ) /** Safety rating corresponding to a generated content. */ -class SafetyRating +public class SafetyRating internal constructor( - val category: HarmCategory, - val probability: HarmProbability, - val probabilityScore: Float = 0f, - val blocked: Boolean? = null, - val severity: HarmSeverity? = null, - val severityScore: Float? = null + public val category: HarmCategory, + public val probability: HarmProbability, + public val probabilityScore: Float = 0f, + public val blocked: Boolean? = null, + public val severity: HarmSeverity? = null, + public val severityScore: Float? = null ) /** @@ -44,7 +44,7 @@ internal constructor( * @property citations A list of individual cited sources and the parts of the content to which they * apply. */ -class CitationMetadata internal constructor(val citations: List) +public class CitationMetadata internal constructor(public val citations: List) /** * Provides citation information for sourcing of content provided by the model between a given @@ -59,18 +59,18 @@ class CitationMetadata internal constructor(val citations: List) * @property license The license the cited source work is distributed under, if specified. * @property publicationDate Publication date of the attribution, if available. */ -class Citation +public class Citation internal constructor( - val title: String? = null, - val startIndex: Int = 0, - val endIndex: Int, - val uri: String? = null, - val license: String? = null, - val publicationDate: Calendar? = null + public val title: String? = null, + public val startIndex: Int = 0, + public val endIndex: Int, + public val uri: String? = null, + public val license: String? = null, + public val publicationDate: Calendar? = null ) /** The reason for content finishing. */ -enum class FinishReason { +public enum class FinishReason { /** A new and not yet supported value. */ UNKNOWN, diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Content.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Content.kt index 89f07cbb20a..74bcf8e5f7d 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Content.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Content.kt @@ -26,46 +26,51 @@ import android.graphics.Bitmap * * @see content */ -class Content @JvmOverloads constructor(val role: String? = "user", val parts: List) { +public class Content +@JvmOverloads +constructor(public val role: String? = "user", public val parts: List) { /** Builder class to facilitate constructing complex [Content] objects. */ - class Builder { + public class Builder { /** The producer of the content. By default, it's "user". */ - var role: String? = "user" + public var role: String? = "user" /** * Mutable list of [Part] comprising a single [Content]. * * Prefer using the provided helper methods over adding elements to the list directly. */ - var parts: MutableList = arrayListOf() + public var parts: MutableList = arrayListOf() /** Adds a new [Part] to [parts]. */ - @JvmName("addPart") fun part(data: T) = apply { parts.add(data) } + @JvmName("addPart") + public fun part(data: T): Content.Builder = apply { parts.add(data) } /** Wraps the provided text inside a [TextPart] and adds it to [parts] list. */ - @JvmName("addText") fun text(text: String) = part(TextPart(text)) + @JvmName("addText") public fun text(text: String): Content.Builder = part(TextPart(text)) /** * Wraps the provided [bytes] and [mimeType] inside a [InlineDataPart] and adds it to the * [parts] list. */ @JvmName("addInlineData") - fun inlineData(mimeType: String, bytes: ByteArray) = part(InlineDataPart(mimeType, bytes)) + public fun inlineData(mimeType: String, bytes: ByteArray): Content.Builder = + part(InlineDataPart(mimeType, bytes)) /** Wraps the provided [image] inside an [ImagePart] and adds it to the [parts] list. */ - @JvmName("addImage") fun image(image: Bitmap) = part(ImagePart(image)) + @JvmName("addImage") public fun image(image: Bitmap): Content.Builder = part(ImagePart(image)) /** * Wraps the provided Google Cloud Storage for Firebase [uri] and [mimeType] inside a * [FileDataPart] and adds it to the [parts] list. */ @JvmName("addFileData") - fun fileData(uri: String, mimeType: String) = part(FileDataPart(uri, mimeType)) + public fun fileData(uri: String, mimeType: String): Content.Builder = + part(FileDataPart(uri, mimeType)) /** Returns a new [Content] using the defined [role] and [parts]. */ - fun build(): Content = Content(role, parts) + public fun build(): Content = Content(role, parts) } } @@ -81,7 +86,7 @@ class Content @JvmOverloads constructor(val role: String? = "user", val parts: L * ) * ``` */ -fun content(role: String? = "user", init: Content.Builder.() -> Unit): Content { +public fun content(role: String? = "user", init: Content.Builder.() -> Unit): Content { val builder = Content.Builder() builder.role = role builder.init() diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/CountTokensResponse.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/CountTokensResponse.kt index ac4ee804715..cb8b17009b1 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/CountTokensResponse.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/CountTokensResponse.kt @@ -23,8 +23,11 @@ package com.google.firebase.vertexai.type * @property totalBillableCharacters A count of the characters that are billable in the input, if * available. */ -class CountTokensResponse(val totalTokens: Int, val totalBillableCharacters: Int? = null) { - operator fun component1() = totalTokens +public class CountTokensResponse( + public val totalTokens: Int, + public val totalBillableCharacters: Int? = null +) { + public operator fun component1(): Int = totalTokens - operator fun component2() = totalBillableCharacters + public operator fun component2(): Int? = totalBillableCharacters } diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Exceptions.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Exceptions.kt index f841da4432a..cc78e8a9168 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Exceptions.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Exceptions.kt @@ -22,10 +22,10 @@ import com.google.firebase.vertexai.internal.util.toPublic import kotlinx.coroutines.TimeoutCancellationException /** Parent class for any errors that occur from the [FirebaseVertexAI] SDK. */ -sealed class FirebaseVertexAIException(message: String, cause: Throwable? = null) : +public sealed class FirebaseVertexAIException(message: String, cause: Throwable? = null) : RuntimeException(message, cause) { - companion object { + internal companion object { /** * Converts a [Throwable] to a [FirebaseVertexAIException]. @@ -33,7 +33,7 @@ sealed class FirebaseVertexAIException(message: String, cause: Throwable? = null * Will populate default messages as expected, and propagate the provided [cause] through the * resulting exception. */ - fun from(cause: Throwable): FirebaseVertexAIException = + internal fun from(cause: Throwable): FirebaseVertexAIException = when (cause) { is FirebaseVertexAIException -> cause is FirebaseCommonAIException -> @@ -68,15 +68,15 @@ sealed class FirebaseVertexAIException(message: String, cause: Throwable? = null } /** Something went wrong while trying to deserialize a response from the server. */ -class SerializationException(message: String, cause: Throwable? = null) : +public class SerializationException(message: String, cause: Throwable? = null) : FirebaseVertexAIException(message, cause) /** The server responded with a non 200 response code. */ -class ServerException(message: String, cause: Throwable? = null) : +public class ServerException(message: String, cause: Throwable? = null) : FirebaseVertexAIException(message, cause) /** The server responded that the API Key is not valid. */ -class InvalidAPIKeyException(message: String, cause: Throwable? = null) : +public class InvalidAPIKeyException(message: String, cause: Throwable? = null) : FirebaseVertexAIException(message, cause) /** @@ -87,7 +87,10 @@ class InvalidAPIKeyException(message: String, cause: Throwable? = null) : * @property response the full server response for the request. */ // TODO(rlazo): Add secondary constructor to pass through the message? -class PromptBlockedException(val response: GenerateContentResponse, cause: Throwable? = null) : +public class PromptBlockedException( + public val response: GenerateContentResponse, + cause: Throwable? = null +) : FirebaseVertexAIException( "Prompt was blocked: ${response.promptFeedback?.blockReason?.name}", cause, @@ -101,7 +104,7 @@ class PromptBlockedException(val response: GenerateContentResponse, cause: Throw * (countries and territories) where the API is available. */ // TODO(rlazo): Add secondary constructor to pass through the message? -class UnsupportedUserLocationException(cause: Throwable? = null) : +public class UnsupportedUserLocationException(cause: Throwable? = null) : FirebaseVertexAIException("User location is not supported for the API use.", cause) /** @@ -109,7 +112,7 @@ class UnsupportedUserLocationException(cause: Throwable? = null) : * * Usually indicative of consumer error. */ -class InvalidStateException(message: String, cause: Throwable? = null) : +public class InvalidStateException(message: String, cause: Throwable? = null) : FirebaseVertexAIException(message, cause) /** @@ -117,7 +120,10 @@ class InvalidStateException(message: String, cause: Throwable? = null) : * * @property response the full server response for the request */ -class ResponseStoppedException(val response: GenerateContentResponse, cause: Throwable? = null) : +public class ResponseStoppedException( + public val response: GenerateContentResponse, + cause: Throwable? = null +) : FirebaseVertexAIException( "Content generation stopped. Reason: ${response.candidates.first().finishReason?.name}", cause, @@ -128,7 +134,7 @@ class ResponseStoppedException(val response: GenerateContentResponse, cause: Thr * * Usually occurs due to a user specified [timeout][RequestOptions.timeout]. */ -class RequestTimeoutException(message: String, cause: Throwable? = null) : +public class RequestTimeoutException(message: String, cause: Throwable? = null) : FirebaseVertexAIException(message, cause) /** @@ -137,7 +143,7 @@ class RequestTimeoutException(message: String, cause: Throwable? = null) : * For a list of valid locations, see * [Vertex AI locations.](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#available-regions) */ -class InvalidLocationException(location: String, cause: Throwable? = null) : +public class InvalidLocationException(location: String, cause: Throwable? = null) : FirebaseVertexAIException("Invalid location \"${location}\"", cause) /** @@ -145,9 +151,9 @@ class InvalidLocationException(location: String, cause: Throwable? = null) : * in the * [Firebase documentation.](https://firebase.google.com/docs/vertex-ai/faq-and-troubleshooting#required-apis) */ -class ServiceDisabledException(message: String, cause: Throwable? = null) : +public class ServiceDisabledException(message: String, cause: Throwable? = null) : FirebaseVertexAIException(message, cause) /** Catch all case for exceptions not explicitly expected. */ -class UnknownException(message: String, cause: Throwable? = null) : +public class UnknownException(message: String, cause: Throwable? = null) : FirebaseVertexAIException(message, cause) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/FunctionCallingConfig.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/FunctionCallingConfig.kt index ba09940c49c..30021c0fac9 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/FunctionCallingConfig.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/FunctionCallingConfig.kt @@ -16,8 +16,6 @@ package com.google.firebase.vertexai.type -import com.google.firebase.vertexai.common.client.FunctionCallingConfig - /** * Contains configuration for function calling from the model. This can be used to force function * calling predictions or disable them. @@ -27,7 +25,7 @@ import com.google.firebase.vertexai.common.client.FunctionCallingConfig * should match [FunctionDeclaration.name]. With [Mode.ANY], model will predict a function call from * the set of function names provided. */ -class FunctionCallingConfig +public class FunctionCallingConfig internal constructor( internal val mode: Mode, internal val allowedFunctionNames: List? = null @@ -51,23 +49,23 @@ internal constructor( NONE } - companion object { + public companion object { /** * The default behavior for function calling. The model calls functions to answer queries at its * discretion */ - @JvmStatic fun auto() = FunctionCallingConfig(Mode.AUTO) + @JvmStatic public fun auto(): FunctionCallingConfig = FunctionCallingConfig(Mode.AUTO) /** The model always predicts a provided function call to answer every query. */ @JvmStatic @JvmOverloads - fun any(allowedFunctionNames: List? = null) = + public fun any(allowedFunctionNames: List? = null): FunctionCallingConfig = FunctionCallingConfig(Mode.ANY, allowedFunctionNames) /** * The model will never predict a function call to answer a query. This can also be achieved by * not passing any tools to the model. */ - @JvmStatic fun none() = FunctionCallingConfig(Mode.NONE) + @JvmStatic public fun none(): FunctionCallingConfig = FunctionCallingConfig(Mode.NONE) } } diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/FunctionDeclaration.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/FunctionDeclaration.kt index f1c0bbd0090..119a36d3eab 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/FunctionDeclaration.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/FunctionDeclaration.kt @@ -36,11 +36,11 @@ package com.google.firebase.vertexai.type * @param optionalParameters A list of parameters that can be omitted. * @see Schema */ -class FunctionDeclaration( - val name: String, - val description: String, - val parameters: Map, - val optionalParameters: List = emptyList(), +public class FunctionDeclaration( + internal val name: String, + internal val description: String, + internal val parameters: Map, + internal val optionalParameters: List = emptyList(), ) { internal val schema: Schema = Schema.obj(properties = parameters, optionalProperties = optionalParameters, nullable = false) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/GenerateContentResponse.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/GenerateContentResponse.kt index 83cbcf50229..61eb9218f33 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/GenerateContentResponse.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/GenerateContentResponse.kt @@ -25,25 +25,25 @@ import android.util.Log * @property promptFeedback optional feedback for the given prompt. When streaming, it's only * populated in the first response. */ -class GenerateContentResponse( - val candidates: List, - val promptFeedback: PromptFeedback?, - val usageMetadata: UsageMetadata?, +public class GenerateContentResponse( + public val candidates: List, + public val promptFeedback: PromptFeedback?, + public val usageMetadata: UsageMetadata?, ) { /** Convenience field representing all the text parts in the response, if they exists. */ - val text: String? by lazy { + public val text: String? by lazy { candidates.first().content.parts.filterIsInstance().joinToString(" ") { it.text } } /** Convenience field to get all the function call parts in the request, if they exist */ - val functionCalls: List by lazy { + public val functionCalls: List by lazy { candidates.first().content.parts.filterIsInstance() } /** * Convenience field representing the first function response part in the response, if it exists. */ - val functionResponse: FunctionResponsePart? by lazy { firstPartAs() } + public val functionResponse: FunctionResponsePart? by lazy { firstPartAs() } private inline fun firstPartAs(): T? { if (candidates.isEmpty()) { diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/GenerationConfig.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/GenerationConfig.kt index 16d7554ece5..8bf8d7a1ac7 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/GenerationConfig.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/GenerationConfig.kt @@ -73,18 +73,18 @@ package com.google.firebase.vertexai.type * [Control generated output](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/control-generated-output) * guide for more details. */ -class GenerationConfig +public class GenerationConfig private constructor( - val temperature: Float?, - val topK: Int?, - val topP: Float?, - val candidateCount: Int?, - val maxOutputTokens: Int?, - val presencePenalty: Float?, - val frequencyPenalty: Float?, - val stopSequences: List?, - val responseMimeType: String?, - val responseSchema: Schema?, + internal val temperature: Float?, + internal val topK: Int?, + internal val topP: Float?, + internal val candidateCount: Int?, + internal val maxOutputTokens: Int?, + internal val presencePenalty: Float?, + internal val frequencyPenalty: Float?, + internal val stopSequences: List?, + internal val responseMimeType: String?, + internal val responseSchema: Schema?, ) { /** @@ -114,20 +114,20 @@ private constructor( * @property responseSchema See [GenerationConfig.responseSchema]. * @see [generationConfig] */ - class Builder { - @JvmField var temperature: Float? = null - @JvmField var topK: Int? = null - @JvmField var topP: Float? = null - @JvmField var candidateCount: Int? = null - @JvmField var maxOutputTokens: Int? = null - @JvmField var presencePenalty: Float? = null - @JvmField var frequencyPenalty: Float? = null - @JvmField var stopSequences: List? = null - @JvmField var responseMimeType: String? = null - @JvmField var responseSchema: Schema? = null + public class Builder { + @JvmField public var temperature: Float? = null + @JvmField public var topK: Int? = null + @JvmField public var topP: Float? = null + @JvmField public var candidateCount: Int? = null + @JvmField public var maxOutputTokens: Int? = null + @JvmField public var presencePenalty: Float? = null + @JvmField public var frequencyPenalty: Float? = null + @JvmField public var stopSequences: List? = null + @JvmField public var responseMimeType: String? = null + @JvmField public var responseSchema: Schema? = null /** Create a new [GenerationConfig] with the attached arguments. */ - fun build() = + public fun build(): GenerationConfig = GenerationConfig( temperature = temperature, topK = topK, @@ -142,7 +142,7 @@ private constructor( ) } - companion object { + public companion object { /** * Alternative casing for [GenerationConfig.Builder]: @@ -150,7 +150,7 @@ private constructor( * val config = GenerationConfig.builder() * ``` */ - fun builder() = Builder() + public fun builder(): Builder = Builder() } } @@ -169,7 +169,7 @@ private constructor( * } * ``` */ -fun generationConfig(init: GenerationConfig.Builder.() -> Unit): GenerationConfig { +public fun generationConfig(init: GenerationConfig.Builder.() -> Unit): GenerationConfig { val builder = GenerationConfig.builder() builder.init() return builder.build() diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/HarmBlockMethod.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/HarmBlockMethod.kt index b4a1fcd17ff..032f5353c97 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/HarmBlockMethod.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/HarmBlockMethod.kt @@ -20,7 +20,7 @@ package com.google.firebase.vertexai.type * Specifies how the block method computes the score that will be compared against the * [HarmBlockThreshold] in [SafetySetting]. */ -enum class HarmBlockMethod { +public enum class HarmBlockMethod { /** * The harm block method uses both probability and severity scores. See [HarmSeverity] and * [HarmProbability]. diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/HarmBlockThreshold.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/HarmBlockThreshold.kt index ade2d1a9513..162ec2a7a1f 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/HarmBlockThreshold.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/HarmBlockThreshold.kt @@ -19,7 +19,7 @@ package com.google.firebase.vertexai.type /** * Represents the threshold for some [HarmCategory] that is allowed and blocked by [SafetySetting]. */ -enum class HarmBlockThreshold { +public enum class HarmBlockThreshold { /** Content with negligible harm is allowed. */ LOW_AND_ABOVE, diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/HarmCategory.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/HarmCategory.kt index 68473f98187..40d104b158b 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/HarmCategory.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/HarmCategory.kt @@ -17,7 +17,7 @@ package com.google.firebase.vertexai.type /** Category for a given harm rating. */ -enum class HarmCategory { +public enum class HarmCategory { /** A new and not yet supported value. */ UNKNOWN, diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/HarmProbability.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/HarmProbability.kt index 56ab86e4707..6f877dacc8d 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/HarmProbability.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/HarmProbability.kt @@ -17,7 +17,7 @@ package com.google.firebase.vertexai.type /** Represents the probability that some [HarmCategory] is applicable in a [SafetyRating]. */ -enum class HarmProbability { +public enum class HarmProbability { /** A new and not yet supported value. */ UNKNOWN, diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/HarmSeverity.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/HarmSeverity.kt index 8e3f0d37c9a..a5526a66db2 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/HarmSeverity.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/HarmSeverity.kt @@ -17,7 +17,7 @@ package com.google.firebase.vertexai.type /** Represents the severity of a [HarmCategory] being applicable in a [SafetyRating]. */ -enum class HarmSeverity { +public enum class HarmSeverity { /** A new and not yet supported value. */ UNKNOWN, diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Part.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Part.kt index ea9635a2ef4..556e518534a 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Part.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Part.kt @@ -21,10 +21,10 @@ import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonObject /** Interface representing data sent to and received from requests. */ -interface Part +public interface Part /** Represents text or string based data sent to and received from requests. */ -class TextPart(val text: String) : Part +public class TextPart(public val text: String) : Part /** * Represents image data sent to and received from requests. When this is sent to the server it is @@ -32,7 +32,7 @@ class TextPart(val text: String) : Part * * @param image [Bitmap] to convert into a [Part] */ -class ImagePart(val image: Bitmap) : Part +public class ImagePart(public val image: Bitmap) : Part /** * Represents binary data with an associated MIME type sent to and received from requests. @@ -42,14 +42,14 @@ class ImagePart(val image: Bitmap) : Part * . * @param inlineData the binary data as a [ByteArray] */ -class InlineDataPart(val mimeType: String, val inlineData: ByteArray) : Part +public class InlineDataPart(public val mimeType: String, public val inlineData: ByteArray) : Part /** * Represents a function call request from the model * * @param functionCall The information provided by the model to call a function. */ -class FunctionCallPart(val functionCall: FunctionCall) : Part +public class FunctionCallPart(public val functionCall: FunctionCall) : Part /** * The result of calling a function as requested by the model. @@ -57,7 +57,7 @@ class FunctionCallPart(val functionCall: FunctionCall) : Part * @param functionResponse The information to send back to the model as the result of a functions * call. */ -class FunctionResponsePart(val functionResponse: FunctionResponse) : Part +public class FunctionResponsePart(public val functionResponse: FunctionResponse) : Part /** * The data necessary to invoke function [name] using the arguments [args]. @@ -65,7 +65,7 @@ class FunctionResponsePart(val functionResponse: FunctionResponse) : Part * @param name the name of the function to call * @param args the function parameters and values as a [Map] */ -class FunctionCall(val name: String, val args: Map) +public class FunctionCall(public val name: String, public val args: Map) /** * The [response] generated after calling function [name]. @@ -73,7 +73,7 @@ class FunctionCall(val name: String, val args: Map) * @param name the name of the called function * @param response the response produced by the function as a [JsonObject] */ -class FunctionResponse(val name: String, val response: JsonObject) +public class FunctionResponse(public val name: String, public val response: JsonObject) /** * Represents file data stored in Cloud Storage for Firebase, referenced by URI. @@ -83,16 +83,16 @@ class FunctionResponse(val name: String, val response: JsonObject) * @param mimeType an IANA standard MIME type. For supported MIME type values see the * [Firebase documentation](https://firebase.google.com/docs/vertex-ai/input-file-requirements). */ -class FileDataPart(val uri: String, val mimeType: String) : Part +public class FileDataPart(public val uri: String, public val mimeType: String) : Part /** Returns the part as a [String] if it represents text, and null otherwise */ -fun Part.asTextOrNull(): String? = (this as? TextPart)?.text +public fun Part.asTextOrNull(): String? = (this as? TextPart)?.text /** Returns the part as a [Bitmap] if it represents an image, and null otherwise */ -fun Part.asImageOrNull(): Bitmap? = (this as? ImagePart)?.image +public fun Part.asImageOrNull(): Bitmap? = (this as? ImagePart)?.image /** Returns the part as a [InlineDataPart] if it represents inline data, and null otherwise */ -fun Part.asInlineDataPartOrNull(): InlineDataPart? = this as? InlineDataPart +public fun Part.asInlineDataPartOrNull(): InlineDataPart? = this as? InlineDataPart /** Returns the part as a [FileDataPart] if it represents a file, and null otherwise */ -fun Part.asFileDataOrNull(): FileDataPart? = this as? FileDataPart +public fun Part.asFileDataOrNull(): FileDataPart? = this as? FileDataPart diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/PromptFeedback.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/PromptFeedback.kt index 3043dd01632..8486ef76f75 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/PromptFeedback.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/PromptFeedback.kt @@ -23,14 +23,14 @@ package com.google.firebase.vertexai.type * @param safetyRatings A list of relevant [SafetyRating]. * @param blockReasonMessage A message describing the reason that content was blocked, if any. */ -class PromptFeedback( - val blockReason: BlockReason?, - val safetyRatings: List, - val blockReasonMessage: String? +public class PromptFeedback( + public val blockReason: BlockReason?, + public val safetyRatings: List, + public val blockReasonMessage: String? ) /** Describes why content was blocked. */ -enum class BlockReason { +public enum class BlockReason { /** A new and not yet supported value. */ UNKNOWN, diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/RequestOptions.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/RequestOptions.kt index dbfbc5b9367..9aa648b6d07 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/RequestOptions.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/RequestOptions.kt @@ -22,7 +22,7 @@ import kotlin.time.DurationUnit import kotlin.time.toDuration /** Configurable options unique to how requests to the backend are performed. */ -class RequestOptions +public class RequestOptions internal constructor( internal val timeout: Duration, internal val endpoint: String = "https://firebasevertexai.googleapis.com", @@ -36,7 +36,7 @@ internal constructor( * the first request to first response. */ @JvmOverloads - constructor( + public constructor( timeoutInMillis: Long = 180.seconds.inWholeMilliseconds ) : this(timeout = timeoutInMillis.toDuration(DurationUnit.MILLISECONDS)) } diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/SafetySetting.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/SafetySetting.kt index 1e0bc763097..752353f8e4f 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/SafetySetting.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/SafetySetting.kt @@ -24,8 +24,8 @@ package com.google.firebase.vertexai.type * @param threshold The threshold form harm allowable. * @param method Specify if the threshold is used for probability or severity score. */ -class SafetySetting( - val harmCategory: HarmCategory, - val threshold: HarmBlockThreshold, - val method: HarmBlockMethod = HarmBlockMethod.PROBABILITY +public class SafetySetting( + internal val harmCategory: HarmCategory, + internal val threshold: HarmBlockThreshold, + internal val method: HarmBlockMethod = HarmBlockMethod.PROBABILITY ) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Schema.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Schema.kt index 4d041c917d2..f599e7d3b81 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Schema.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Schema.kt @@ -16,27 +16,27 @@ package com.google.firebase.vertexai.type -sealed class StringFormat(val value: String) { - class Custom(format: String) : StringFormat(format) +public sealed class StringFormat(public val value: String) { + public class Custom(format: String) : StringFormat(format) } /** Represents a schema */ -class Schema +public class Schema internal constructor( - val type: String, - val description: String? = null, - val format: String? = null, - val nullable: Boolean? = null, - val enum: List? = null, - val properties: Map? = null, - val required: List? = null, - val items: Schema? = null, + public val type: String, + public val description: String? = null, + public val format: String? = null, + public val nullable: Boolean? = null, + public val enum: List? = null, + public val properties: Map? = null, + public val required: List? = null, + public val items: Schema? = null, ) { - companion object { + public companion object { /** Returns a schema for a boolean */ @JvmStatic - fun boolean(description: String? = null, nullable: Boolean = false) = + public fun boolean(description: String? = null, nullable: Boolean = false): Schema = Schema( description = description, nullable = nullable, @@ -51,7 +51,7 @@ internal constructor( */ @JvmStatic @JvmName("numInt") - fun integer(description: String? = null, nullable: Boolean = false) = + public fun integer(description: String? = null, nullable: Boolean = false): Schema = Schema( description = description, format = "int32", @@ -67,7 +67,7 @@ internal constructor( */ @JvmStatic @JvmName("numLong") - fun long(description: String? = null, nullable: Boolean = false) = + public fun long(description: String? = null, nullable: Boolean = false): Schema = Schema( description = description, nullable = nullable, @@ -82,7 +82,7 @@ internal constructor( */ @JvmStatic @JvmName("numDouble") - fun double(description: String? = null, nullable: Boolean = false) = + public fun double(description: String? = null, nullable: Boolean = false): Schema = Schema(description = description, nullable = nullable, type = "NUMBER", format = "double") /** @@ -93,7 +93,7 @@ internal constructor( */ @JvmStatic @JvmName("numFloat") - fun float(description: String? = null, nullable: Boolean = false) = + public fun float(description: String? = null, nullable: Boolean = false): Schema = Schema(description = description, nullable = nullable, type = "NUMBER", format = "float") /** @@ -105,11 +105,11 @@ internal constructor( */ @JvmStatic @JvmName("str") - fun string( + public fun string( description: String? = null, nullable: Boolean = false, format: StringFormat? = null - ) = + ): Schema = Schema( description = description, format = format?.value, @@ -125,7 +125,7 @@ internal constructor( * @param nullable: Whether null is a valid value for this schema */ @JvmStatic - fun obj( + public fun obj( properties: Map, optionalProperties: List = emptyList(), description: String? = null, @@ -153,7 +153,11 @@ internal constructor( * @param nullable: Whether null is a valid value for this schema */ @JvmStatic - fun array(items: Schema, description: String? = null, nullable: Boolean = false) = + public fun array( + items: Schema, + description: String? = null, + nullable: Boolean = false + ): Schema = Schema( description = description, nullable = nullable, @@ -169,7 +173,11 @@ internal constructor( * @param nullable: Whether null is a valid value for this schema */ @JvmStatic - fun enumeration(values: List, description: String? = null, nullable: Boolean = false) = + public fun enumeration( + values: List, + description: String? = null, + nullable: Boolean = false + ): Schema = Schema( description = description, format = "enum", diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Tool.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Tool.kt index 0400387c081..41cbf99f6c4 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Tool.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Tool.kt @@ -22,8 +22,9 @@ package com.google.firebase.vertexai.type * * @param functionDeclarations The set of functions that this tool allows the model access to */ -class Tool internal constructor(internal val functionDeclarations: List?) { - companion object { +public class Tool +internal constructor(internal val functionDeclarations: List?) { + public companion object { /** * Creates a [Tool] instance that provides the model with access to the [functionDeclarations]. @@ -31,7 +32,7 @@ class Tool internal constructor(internal val functionDeclarations: List): Tool { + public fun functionDeclarations(functionDeclarations: List): Tool { return Tool(functionDeclarations) } } diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ToolConfig.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ToolConfig.kt index 38ea3837801..7641120b2ee 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ToolConfig.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/ToolConfig.kt @@ -22,4 +22,4 @@ package com.google.firebase.vertexai.type * * @param functionCallingConfig The config for function calling */ -class ToolConfig(val functionCallingConfig: FunctionCallingConfig) +public class ToolConfig(internal val functionCallingConfig: FunctionCallingConfig) diff --git a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/UsageMetadata.kt b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/UsageMetadata.kt index 6b403e11530..21da0255cb9 100644 --- a/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/UsageMetadata.kt +++ b/firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/UsageMetadata.kt @@ -23,8 +23,8 @@ package com.google.firebase.vertexai.type * @param candidatesTokenCount Number of tokens in the response(s). * @param totalTokenCount Total number of tokens. */ -class UsageMetadata( - val promptTokenCount: Int, - val candidatesTokenCount: Int?, - val totalTokenCount: Int +public class UsageMetadata( + public val promptTokenCount: Int, + public val candidatesTokenCount: Int?, + public val totalTokenCount: Int )