Skip to content
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

Migrate VertexAI serialization to be localized #6631

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

emilypgoogle
Copy link
Collaborator

There are some considerations to how this should be finalized. Current implementation details that I've decided on which we can change:

  • Based on the example doc, all classes Foo have been renamed InternalFoo
  • All internal serialization classes, where relevant, are moved to inner classes of their API counterparts
  • All classes only used as child fields for serialization classes have been moved to inner classes of those classes
  • All toPublic and toInternal methods on API and serialization classes have been moved inside of those classes and conversions.kt has been mostly emptied.
  • A few serialization classes do not have API equivalents and are left in a Types.kt file

Possible changes:

  • Change all InternalFoo classes to have the same name, referenced as Foo.Internal rather than Foo.InternalFoo. This will probably make the codebase feel cleaner, but I'll wait for opinions on it
  • Move serialization only classes out of the internal serialization classes, either to inner classes of the API classes or top level classes themselves.
  • For classes that have serializers, rename serializers from InternalFooSerializer to Serializer for example Foo.InternalFoo.Serializer or Foo.Internal.Serializer instead of Foo.InternalFoo.InternalFooSerializer or Foo.Internal.InternalFooSerializer

@emilypgoogle emilypgoogle requested review from rlazo and daymxn January 17, 2025 22:29
Copy link
Contributor

github-actions bot commented Jan 17, 2025

📝 PRs merging into main branch

Our main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released.

Copy link
Contributor

Vertex AI Mock Responses Check ⚠️

A newer major version of the mock responses for Vertex AI unit tests is available. update_responses.sh should be updated to clone the latest version of the responses: v5.3

@google-oss-bot
Copy link
Contributor

1 Warning
⚠️ Did you forget to add a changelog entry? (Add the 'no-changelog' label to the PR to silence this warning.)

Generated by 🚫 Danger

@google-oss-bot
Copy link
Contributor

Coverage Report 1

Affected Products

No changes between base commit (8e61ec2) and merge commit (324baa9).

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/tbmNiWtvxk.html

Copy link
Contributor

Test Results

0 files   -    64  0 suites   - 64   0s ⏱️ - 1m 12s
0 tests  -   542  0 ✅  -   541  0 💤  - 1  0 ❌ ±0 
0 runs   - 1 084  0 ✅  - 1 082  0 💤  - 2  0 ❌ ±0 

Results for commit bbfaa1e. ± Comparison against base commit 8e61ec2.

Copy link
Member

@daymxn daymxn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't currently compile, as there's some imports and usages that need to be updated. Like:

- private fun InternalGenerateContentResponse.validate()
+ private fun GenerateContentResponse.InternalGenerateContentResponse.validate()

Also, (and this probably a convo for @rlazo too), any reason we want the fully qualified names over something like Internal?

Current:

public class FunctionDeclaration(
  internal val name: String,
  internal val description: String,
  internal val parameters: Map<String, Schema>,
  internal val optionalParameters: List<String> = emptyList(),
) {
  internal val schema: Schema =
    Schema.obj(properties = parameters, optionalProperties = optionalParameters, nullable = false)

  internal fun toInternal() =
    InternalFunctionDeclaration(name, "", schema.toInternal())

  @Serializable
  internal data class InternalFunctionDeclaration(
    val name: String,
    val description: String,
    val parameters: Schema.InternalSchema
  )
}

With internal naming:

public class FunctionDeclaration(
  internal val name: String,
  internal val description: String,
  internal val parameters: Map<String, Schema>,
  internal val optionalParameters: List<String> = emptyList(),
) {
  internal val schema: Schema =
    Schema.obj(properties = parameters, optionalProperties = optionalParameters, nullable = false)

  internal fun toInternal() =
   Internal(name, "", schema.toInternal())

  @Serializable
  internal data class Internal(
    val name: String,
    val description: String,
    val parameters: Schema.InternalSchema
  )
}

So its usage would be like this:

- FunctionDeclaration.InternalFunctionDeclaration(...)
+ FunctionDeclaration.Internal(...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants