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

fix: Deployments should be cached for non-model-information #102

Merged
merged 9 commits into from
Sep 4, 2024
Merged

Conversation

marikaner
Copy link
Contributor

Context

AI/gen-ai-hub-sdk-js-backlog#78.

Follow up from #96.

When retrieving a deployment for a model name without version and there are only deployments where each model has a version, the second time we use this deployment, the cache wasn't used.

Definition of Done

  • Code is tested (Unit, E2E)
  • Error handling created / updated & covered by the tests above
  • Documentation updated
  • (Optional) Aligned changes with the Java SDK
  • (Optional) Release notes updated

[...deployments].reverse().forEach(deployment => {
cache.set(getCacheKey({ ...opts, model: extractModel(deployment) }), {
entry: transformDeploymentForCache(deployment)
const cacheEntries = [...deployments].map(deployment =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MatKuhr how do you like that?

my 2 cents: I think it is semantically better, however more error prone.

Copy link
Contributor Author

@marikaner marikaner Sep 3, 2024

Choose a reason for hiding this comment

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

Ok, after multiple tries and still failing tests, I am reverting this. Feel free to check the commit, if you are interested: 37eaadd

Comment on lines 61 to 72
.flatMap(entry => {
const entries = [entry];
// if the entry has a model, also cache it without model and version
if (entry.model) {
entries.push({ id: entry.id });
}
// if the entry has a model version, also cache it for without model version
if (entry.model?.version) {
entries.push({ id: entry.id, model: { name: entry.model.name } });
}
return entries;
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This could still be shortened if we remove the checks:

Suggested change
.flatMap(entry => {
const entries = [entry];
// if the entry has a model, also cache it without model and version
if (entry.model) {
entries.push({ id: entry.id });
}
// if the entry has a model version, also cache it for without model version
if (entry.model?.version) {
entries.push({ id: entry.id, model: { name: entry.model.name } });
}
return entries;
});
.flatMap(entry => [entry, { id: entry.id }, { id: entry.id, model: { name: entry.model.name } }]);

Even though this is a little less performant, I think I even prefer that, but no strong opinion.

@marikaner marikaner enabled auto-merge (squash) September 4, 2024 08:11
@marikaner marikaner merged commit 9506707 into main Sep 4, 2024
9 checks passed
@marikaner marikaner deleted the cache branch September 4, 2024 08:47
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