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

Add unit tests to common #85

Merged
merged 7 commits into from
Mar 18, 2024
Merged

Add unit tests to common #85

merged 7 commits into from
Mar 18, 2024

Conversation

rlazo
Copy link
Collaborator

@rlazo rlazo commented Mar 17, 2024

No description provided.

rlazo added 3 commits March 15, 2024 01:33
A few changes were required to get unit tests to work. Mostly:

- Move GenerateContentRequest validation from the model to the
APIController. It's better to centralize this logic
- Throw exceptions at the APIController level rather than model

Other changes were kept at a minimum to simplify review
Copy link
Collaborator

@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.

Left some comments, but otherwise looks good! Great job!

val responseList = responses.toList()
responseList.any {
it.candidates?.any { it.citationMetadata?.citationSources?.isNotEmpty() ?: false }
?: false
Copy link
Collaborator

Choose a reason for hiding this comment

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

You've used this structure of any at least 7 times in your tests. Tbh, I'm surprised it's not already apart of the stdlib, but might I suggest:

internal fun <T> Iterable<T>?.any(predicate: (T) -> Boolean): Boolean =
  this?.let { it.any { predicate(it) } } ?: false

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It does sound like a great idea... but it triggers a stackoverflow due to recursion

Caused by: java.lang.StackOverflowError
	at com.google.ai.client.generativeai.common.util.KotlinKt.any(kotlin.kt:38)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ahh I see, this should fix it:

internal fun <T> Iterable<T>?.any(predicate: (T) -> Boolean): Boolean =
  this?.firstNotNullOfOrNull(predicate) != null

@rlazo rlazo merged commit 7507710 into common_dev Mar 18, 2024
5 checks passed
@rlazo rlazo deleted the rl.common.tests branch March 18, 2024 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants