Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Objects;
Expand All @@ -44,7 +42,7 @@ public class EmbeddingsCreate200ResponseDataInner
private String _object;

@JsonProperty("embedding")
private List<BigDecimal> embedding = new ArrayList<>(); //
private float[] embedding;

@JsonAnySetter @JsonAnyGetter
private final Map<String, Object> cloudSdkCustomFields = new LinkedHashMap<>();
Expand Down Expand Up @@ -121,34 +119,18 @@ public void setObject(@Nonnull final String _object) {
* @return The same instance of this {@link EmbeddingsCreate200ResponseDataInner} class
*/
@Nonnull
public EmbeddingsCreate200ResponseDataInner embedding(@Nonnull final List<BigDecimal> embedding) {
public EmbeddingsCreate200ResponseDataInner embedding(@Nonnull final float[] embedding) {
this.embedding = embedding;
return this;
}

/**
* Add one embedding instance to this {@link EmbeddingsCreate200ResponseDataInner}.
*
* @param embeddingItem The embedding that should be added
* @return The same instance of type {@link EmbeddingsCreate200ResponseDataInner}
*/
@Nonnull
public EmbeddingsCreate200ResponseDataInner addEmbeddingItem(
@Nonnull final BigDecimal embeddingItem) {
if (this.embedding == null) {
this.embedding = new ArrayList<>();
}
this.embedding.add(embeddingItem);
return this;
}

/**
* Get embedding
*
* @return embedding The embedding of this {@link EmbeddingsCreate200ResponseDataInner} instance.
*/
@Nonnull
public List<BigDecimal> getEmbedding() {
public float[] getEmbedding() {
return embedding;
}

Expand All @@ -157,7 +139,7 @@ public List<BigDecimal> getEmbedding() {
*
* @param embedding The embedding of this {@link EmbeddingsCreate200ResponseDataInner}
*/
public void setEmbedding(@Nonnull final List<BigDecimal> embedding) {
public void setEmbedding(@Nonnull final float[] embedding) {
this.embedding = embedding;
}

Expand Down Expand Up @@ -217,12 +199,12 @@ public boolean equals(@Nullable final Object o) {
this.cloudSdkCustomFields, embeddingsCreate200ResponseDataInner.cloudSdkCustomFields)
&& Objects.equals(this.index, embeddingsCreate200ResponseDataInner.index)
&& Objects.equals(this._object, embeddingsCreate200ResponseDataInner._object)
&& Objects.equals(this.embedding, embeddingsCreate200ResponseDataInner.embedding);
&& Arrays.equals(this.embedding, embeddingsCreate200ResponseDataInner.embedding);
Copy link
Member Author

@rpanackal rpanackal Feb 26, 2025

Choose a reason for hiding this comment

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

This equality check may continue with Objects.equals, especially if thats what the generator will do

Copy link
Member Author

Choose a reason for hiding this comment

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

Using Object.equals will be flagged a bug.

}

@Override
public int hashCode() {
return Objects.hash(index, _object, embedding, cloudSdkCustomFields);
return Objects.hash(index, _object, Arrays.hashCode(embedding), cloudSdkCustomFields);
Copy link
Member Author

Choose a reason for hiding this comment

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

Similar to above, may continue without Arrays.hashCode()

Copy link
Contributor

@newtork newtork Feb 26, 2025

Choose a reason for hiding this comment

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

(How) do you plan to realize that in the generator mustache files?
Related SAP/cloud-sdk-java#734

Copy link
Member Author

Choose a reason for hiding this comment

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

I am going to take that as the case where there is no flag/indicator to distinguish between an array of primitive and object. So I will revert and stay consistent with all object type handling.

Copy link
Contributor

@newtork newtork Feb 27, 2025

Choose a reason for hiding this comment

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

How exactly are you planning to do that? Are you currently working on a (the above) PR or is it a follow-up BLI?

Establishing manual code changes without a clear path to solve it in the generator is creating problems in the future. Same applies e.g. for prompt-registry PoC PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

We discussed and found a solution in Cloud SDK

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import com.sap.ai.sdk.foundationmodels.openai.generated.model.PromptFilterResult;
import io.vavr.control.Try;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
Expand Down Expand Up @@ -265,12 +264,7 @@ void embedding() {
assertThat(embeddingData.getEmbedding())
.isNotNull()
.isNotEmpty()
.containsExactly(
new BigDecimal("0.0"),
new BigDecimal("3.4028235E+38"),
new BigDecimal("1.4E-45"),
new BigDecimal("1.23"),
new BigDecimal("-4.56"));
.isEqualTo(new float[] {0.0f, 3.4028235E+38f, 1.4E-45f, 1.23f, -4.56f});

verify(
postRequestedFor(urlPathEqualTo("/embeddings"))
Expand Down
Loading