Skip to content

Commit 2bcf5d3

Browse files
committed
Adjust naming and fix test compilation
1 parent bbfaa1e commit 2bcf5d3

28 files changed

+197
-199
lines changed

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/common/APIController.kt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ package com.google.firebase.vertexai.common
1919
import android.util.Log
2020
import com.google.firebase.Firebase
2121
import com.google.firebase.options
22-
import com.google.firebase.vertexai.common.server.GRpcError
23-
import com.google.firebase.vertexai.common.server.GRpcErrorDetails
2422
import com.google.firebase.vertexai.common.util.decodeToFlow
2523
import com.google.firebase.vertexai.common.util.fullModelName
24+
import com.google.firebase.vertexai.type.CountTokensResponse
25+
import com.google.firebase.vertexai.type.FinishReason
2626
import com.google.firebase.vertexai.type.GRpcErrorResponse
27-
import com.google.firebase.vertexai.type.InternalCountTokensResponse
28-
import com.google.firebase.vertexai.type.InternalGenerateContentResponse
27+
import com.google.firebase.vertexai.type.GenerateContentResponse
2928
import com.google.firebase.vertexai.type.RequestOptions
3029
import com.google.firebase.vertexai.type.Response
3130
import io.ktor.client.HttpClient
@@ -109,31 +108,31 @@ internal constructor(
109108
install(ContentNegotiation) { json(JSON) }
110109
}
111110

112-
suspend fun generateContent(request: GenerateContentRequest): InternalGenerateContentResponse =
111+
suspend fun generateContent(request: GenerateContentRequest): GenerateContentResponse.Internal =
113112
try {
114113
client
115114
.post("${requestOptions.endpoint}/${requestOptions.apiVersion}/$model:generateContent") {
116115
applyCommonConfiguration(request)
117116
applyHeaderProvider()
118117
}
119118
.also { validateResponse(it) }
120-
.body<InternalGenerateContentResponse>()
119+
.body<GenerateContentResponse.Internal>()
121120
.validate()
122121
} catch (e: Throwable) {
123122
throw FirebaseCommonAIException.from(e)
124123
}
125124

126-
fun generateContentStream(request: GenerateContentRequest): Flow<InternalGenerateContentResponse> =
125+
fun generateContentStream(request: GenerateContentRequest): Flow<GenerateContentResponse.Internal> =
127126
client
128-
.postStream<InternalGenerateContentResponse>(
127+
.postStream<GenerateContentResponse.Internal>(
129128
"${requestOptions.endpoint}/${requestOptions.apiVersion}/$model:streamGenerateContent?alt=sse"
130129
) {
131130
applyCommonConfiguration(request)
132131
}
133132
.map { it.validate() }
134133
.catch { throw FirebaseCommonAIException.from(it) }
135134

136-
suspend fun countTokens(request: CountTokensRequest): InternalCountTokensResponse =
135+
suspend fun countTokens(request: CountTokensRequest): CountTokensResponse.Internal =
137136
try {
138137
client
139138
.post("${requestOptions.endpoint}/${requestOptions.apiVersion}/$model:countTokens") {
@@ -278,19 +277,19 @@ private suspend fun validateResponse(response: HttpResponse) {
278277
throw ServerException(message)
279278
}
280279

281-
private fun getServiceDisabledErrorDetailsOrNull(error: GRpcError): GRpcErrorDetails? {
280+
private fun getServiceDisabledErrorDetailsOrNull(error: GRpcErrorResponse.GRpcError): GRpcErrorResponse.GRpcError.GRpcErrorDetails? {
282281
return error.details?.firstOrNull {
283282
it.reason == "SERVICE_DISABLED" && it.domain == "googleapis.com"
284283
}
285284
}
286285

287-
private fun InternalGenerateContentResponse.validate() = apply {
286+
private fun GenerateContentResponse.Internal.validate() = apply {
288287
if ((candidates?.isEmpty() != false) && promptFeedback == null) {
289288
throw SerializationException("Error deserializing response, found no valid fields")
290289
}
291290
promptFeedback?.blockReason?.let { throw PromptBlockedException(this) }
292291
candidates
293292
?.mapNotNull { it.finishReason }
294-
?.firstOrNull { it != FinishReason.STOP }
293+
?.firstOrNull { it != FinishReason.Internal.STOP }
295294
?.let { throw ResponseStoppedException(this) }
296295
}

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/common/Exceptions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ internal class InvalidAPIKeyException(message: String, cause: Throwable? = null)
6767
* @property response the full server response for the request.
6868
*/
6969
internal class PromptBlockedException(
70-
val response: GenerateContentResponse.InternalGenerateContentResponse,
70+
val response: GenerateContentResponse.Internal,
7171
cause: Throwable? = null
7272
) :
7373
FirebaseCommonAIException(
@@ -99,7 +99,7 @@ internal class InvalidStateException(message: String, cause: Throwable? = null)
9999
* @property response the full server response for the request
100100
*/
101101
internal class ResponseStoppedException(
102-
val response: GenerateContentResponse.InternalGenerateContentResponse,
102+
val response: GenerateContentResponse.Internal,
103103
cause: Throwable? = null
104104
) :
105105
FirebaseCommonAIException(

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/common/Request.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ internal sealed interface Request
3030
@Serializable
3131
internal data class GenerateContentRequest(
3232
val model: String? = null,
33-
val contents: List<Content.InternalContent>,
34-
@SerialName("safety_settings") val safetySettings: List<SafetySetting.InternalSafetySetting>? = null,
35-
@SerialName("generation_config") val generationConfig: GenerationConfig.InternalGenerationConfig? = null,
36-
val tools: List<Tool.InternalTool>? = null,
37-
@SerialName("tool_config") var toolConfig: ToolConfig.InternalToolConfig? = null,
38-
@SerialName("system_instruction") val systemInstruction: Content.InternalContent? = null,
33+
val contents: List<Content.Internal>,
34+
@SerialName("safety_settings") val safetySettings: List<SafetySetting.Internal>? = null,
35+
@SerialName("generation_config") val generationConfig: GenerationConfig.Internal? = null,
36+
val tools: List<Tool.Internal>? = null,
37+
@SerialName("tool_config") var toolConfig: ToolConfig.Internal? = null,
38+
@SerialName("system_instruction") val systemInstruction: Content.Internal? = null,
3939
) : Request
4040

4141
@Serializable
4242
internal data class CountTokensRequest(
4343
val generateContentRequest: GenerateContentRequest? = null,
4444
val model: String? = null,
45-
val contents: List<Content.InternalContent>? = null,
46-
val tools: List<Tool.InternalTool>? = null,
47-
@SerialName("system_instruction") val systemInstruction: Content.InternalContent? = null,
45+
val contents: List<Content.Internal>? = null,
46+
val tools: List<Tool.Internal>? = null,
47+
@SerialName("system_instruction") val systemInstruction: Content.Internal? = null,
4848
) : Request {
4949
companion object {
5050
fun forGenAI(generateContentRequest: GenerateContentRequest) =

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Candidate.kt

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ internal constructor(
4141
) {
4242

4343
@Serializable
44-
internal data class InternalCandidate(
45-
val content: Content.InternalContent? = null,
46-
val finishReason: FinishReason.InternalFinishReason? = null,
47-
val safetyRatings: List<SafetyRating.InternalSafetyRating>? = null,
48-
val citationMetadata: CitationMetadata.InternalCitationMetadata? = null,
49-
val groundingMetadata: InternalGroundingMetadata? = null,
44+
internal data class Internal(
45+
val content: Content.Internal? = null,
46+
val finishReason: FinishReason.Internal? = null,
47+
val safetyRatings: List<SafetyRating.Internal>? = null,
48+
val citationMetadata: CitationMetadata.Internal? = null,
49+
val groundingMetadata: GroundingMetadata? = null,
5050
) {
5151
internal fun toPublic(): Candidate {
5252
val safetyRatings = safetyRatings?.map { it.toPublic() }.orEmpty()
@@ -62,27 +62,27 @@ internal constructor(
6262
}
6363

6464
@Serializable
65-
internal data class InternalGroundingMetadata(
65+
internal data class GroundingMetadata(
6666
@SerialName("web_search_queries") val webSearchQueries: List<String>?,
67-
@SerialName("search_entry_point") val searchEntryPoint: InternalSearchEntryPoint?,
67+
@SerialName("search_entry_point") val searchEntryPoint: SearchEntryPoint?,
6868
@SerialName("retrieval_queries") val retrievalQueries: List<String>?,
69-
@SerialName("grounding_attribution") val groundingAttribution: List<InternalGroundingAttribution>?,
69+
@SerialName("grounding_attribution") val groundingAttribution: List<GroundingAttribution>?,
7070
) {
7171

7272
@Serializable
73-
internal data class InternalSearchEntryPoint(
73+
internal data class SearchEntryPoint(
7474
@SerialName("rendered_content") val renderedContent: String?,
7575
@SerialName("sdk_blob") val sdkBlob: String?,
7676
)
7777

7878
@Serializable
79-
internal data class InternalGroundingAttribution(
80-
val segment: InternalSegment,
79+
internal data class GroundingAttribution(
80+
val segment: Segment,
8181
@SerialName("confidence_score") val confidenceScore: Float?,
8282
) {
8383

8484
@Serializable
85-
internal data class InternalSegment(
85+
internal data class Segment(
8686
@SerialName("start_index") val startIndex: Int,
8787
@SerialName("end_index") val endIndex: Int,
8888
)
@@ -115,12 +115,12 @@ internal constructor(
115115
) {
116116

117117
@Serializable
118-
internal data class InternalSafetyRating @JvmOverloads constructor(
119-
val category: HarmCategory.InternalHarmCategory,
120-
val probability: HarmProbability.InternalHarmProbability,
118+
internal data class Internal @JvmOverloads constructor(
119+
val category: HarmCategory.Internal,
120+
val probability: HarmProbability.Internal,
121121
val blocked: Boolean? = null, // TODO(): any reason not to default to false?
122122
val probabilityScore: Float? = null,
123-
val severity: HarmSeverity.InternalHarmSeverity? = null,
123+
val severity: HarmSeverity.Internal? = null,
124124
val severityScore: Float? = null,
125125
) {
126126

@@ -146,9 +146,9 @@ internal constructor(
146146
public class CitationMetadata internal constructor(public val citations: List<Citation>) {
147147

148148
@Serializable
149-
internal data class InternalCitationMetadata
149+
internal data class Internal
150150
@OptIn(ExperimentalSerializationApi::class)
151-
internal constructor(@JsonNames("citations") val citationSources: List<Citation.InternalCitationSources>) {
151+
internal constructor(@JsonNames("citations") val citationSources: List<Citation.Internal>) {
152152

153153
internal fun toPublic() =
154154
CitationMetadata(citationSources.map { it.toPublic() })
@@ -182,13 +182,13 @@ internal constructor(
182182
) {
183183

184184
@Serializable
185-
internal data class InternalCitationSources(
185+
internal data class Internal(
186186
val title: String? = null,
187187
val startIndex: Int = 0,
188188
val endIndex: Int,
189189
val uri: String? = null,
190190
val license: String? = null,
191-
val publicationDate: InternalDate? = null,
191+
val publicationDate: Date? = null,
192192
) {
193193

194194
internal fun toPublic(): Citation {
@@ -216,7 +216,7 @@ internal constructor(
216216
}
217217

218218
@Serializable
219-
internal data class InternalDate(
219+
internal data class Date(
220220
/** Year of the date. Must be between 1 and 9999, or 0 for no year. */
221221
val year: Int? = null,
222222
/** 1-based index for month. Must be from 1 to 12, or 0 to specify a year without a month. */
@@ -238,8 +238,8 @@ internal constructor(
238238
*/
239239
public class FinishReason private constructor(public val name: String, public val ordinal: Int) {
240240

241-
@Serializable(InternalFinishReason.InternalFinishReasonSerializer::class)
242-
internal enum class InternalFinishReason {
241+
@Serializable(Internal.Serializer::class)
242+
internal enum class Internal {
243243
UNKNOWN,
244244
@SerialName("FINISH_REASON_UNSPECIFIED") UNSPECIFIED,
245245
STOP,
@@ -248,8 +248,8 @@ public class FinishReason private constructor(public val name: String, public va
248248
RECITATION,
249249
OTHER;
250250

251-
internal object InternalFinishReasonSerializer :
252-
KSerializer<InternalFinishReason> by FirstOrdinalSerializer(InternalFinishReason::class)
251+
internal object Serializer :
252+
KSerializer<Internal> by FirstOrdinalSerializer(Internal::class)
253253

254254
internal fun toPublic() =
255255
when (this) {

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/Content.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ constructor(public val role: String? = "user", public val parts: List<Part>) {
8181
}
8282

8383
internal fun toInternal() =
84-
InternalContent(
84+
Internal(
8585
this.role ?: "user",
8686
this.parts.map { it.toInternal() }
8787
)
8888

8989
@ExperimentalSerializationApi
9090
@Serializable
91-
internal data class InternalContent(@EncodeDefault val role: String? = "user", val parts: List<InternalPart>) {
91+
internal data class Internal(@EncodeDefault val role: String? = "user", val parts: List<InternalPart>) {
9292

9393
internal fun toPublic(): Content =
9494
Content(role, parts.map { it.toPublic() })

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/CountTokensResponse.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class CountTokensResponse(
4040
public operator fun component2(): Int? = totalBillableCharacters
4141

4242
@Serializable
43-
internal data class InternalCountTokensResponse(
43+
internal data class Internal(
4444
val totalTokens: Int,
4545
val totalBillableCharacters: Int? = null
4646
) : Response {

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/FunctionCallingConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ internal constructor(
5050

5151

5252
@Serializable
53-
internal data class InternalFunctionCallingConfig(
53+
internal data class Internal(
5454
val mode: Mode,
5555
@SerialName("allowed_function_names") val allowedFunctionNames: List<String>? = null
5656
) {

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/FunctionDeclaration.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ public class FunctionDeclaration(
6262
Schema.obj(properties = parameters, optionalProperties = optionalParameters, nullable = false)
6363

6464
internal fun toInternal() =
65-
InternalFunctionDeclaration(name, "", schema.toInternal())
65+
Internal(name, "", schema.toInternal())
6666

6767
@Serializable
68-
internal data class InternalFunctionDeclaration(
68+
internal data class Internal(
6969
val name: String,
7070
val description: String,
71-
val parameters: Schema.InternalSchema
71+
val parameters: Schema.Internal
7272
)
7373
}

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/GenerateContentResponse.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ public class GenerateContentResponse(
4545
}
4646

4747
@Serializable
48-
internal data class InternalGenerateContentResponse(
49-
val candidates: List<Candidate.InternalCandidate>? = null,
50-
val promptFeedback: PromptFeedback.InternalPromptFeedback? = null,
51-
val usageMetadata: UsageMetadata.InternalUsageMetadata? = null,
48+
internal data class Internal(
49+
val candidates: List<Candidate.Internal>? = null,
50+
val promptFeedback: PromptFeedback.Internal? = null,
51+
val usageMetadata: UsageMetadata.Internal? = null,
5252
) : Response {
5353
internal fun toPublic(): GenerateContentResponse {
5454
return GenerateContentResponse(

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/type/GenerationConfig.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private constructor(
146146
}
147147

148148
internal fun toInternal() =
149-
InternalGenerationConfig(
149+
Internal(
150150
temperature = temperature,
151151
topP = topP,
152152
topK = topK,
@@ -160,7 +160,7 @@ private constructor(
160160
)
161161

162162
@Serializable
163-
internal data class InternalGenerationConfig(
163+
internal data class Internal(
164164
val temperature: Float?,
165165
@SerialName("top_p") val topP: Float?,
166166
@SerialName("top_k") val topK: Int?,
@@ -170,7 +170,7 @@ private constructor(
170170
@SerialName("response_mime_type") val responseMimeType: String? = null,
171171
@SerialName("presence_penalty") val presencePenalty: Float? = null,
172172
@SerialName("frequency_penalty") val frequencyPenalty: Float? = null,
173-
@SerialName("response_schema") val responseSchema: Schema.InternalSchema? = null,
173+
@SerialName("response_schema") val responseSchema: Schema.Internal? = null,
174174
)
175175

176176
public companion object {

0 commit comments

Comments
 (0)