Skip to content

Add JsonIgnoreProperties to DeepSeek Model Response objects #3057

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

Closed
wants to merge 1 commit into from
Closed
Changes from all 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 @@ -16,11 +16,8 @@

package org.springframework.ai.deepseek.api;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.*;
Copy link
Member

Choose a reason for hiding this comment

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

wildcard imports aren't allowed - will fix when merging.

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.ai.model.ApiKey;
import org.springframework.ai.model.ChatModelDescription;
import org.springframework.ai.model.ModelOptionsUtils;
Expand Down Expand Up @@ -484,12 +481,13 @@ public void setJsonSchema(String jsonSchema) {
* @param toolChoice Controls which (if any) function is called by the model. none
* means the model will not call a function and instead generates a message. auto
* means the model can pick between generating a message or calling a function.
* Specifying a particular function via {"type: "function", "function": {"name":
* Specifying a particular function via {"type": "function", "function": {"name":
* "my_function"}} forces the model to call that function. none is the default when no
* functions are present. auto is the default if functions are present. Use the
* {@link ToolChoiceBuilder} to create the tool choice value.
*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
Copy link
Member

Choose a reason for hiding this comment

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

We want to add this annotation only for the response objects. Hence, we can remove this. Will fix it when merging.

public record ChatCompletionRequest(// @formatter:off
@JsonProperty("messages") List<ChatCompletionMessage> messages,
@JsonProperty("model") String model,
Expand Down Expand Up @@ -587,6 +585,7 @@ public static Object FUNCTION(String functionName) {
* Applicable only for {@link Role#ASSISTANT} role and null otherwise.
*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public record ChatCompletionMessage(// @formatter:off
@JsonProperty("content") Object rawContent,
@JsonProperty("role") Role role,
Expand Down Expand Up @@ -675,6 +674,7 @@ public enum Role {
* @param function The function definition.
*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public record ToolCall(// @formatter:off
@JsonProperty("index") Integer index,
@JsonProperty("id") String id,
Expand All @@ -695,6 +695,7 @@ public ToolCall(String id, String type, ChatCompletionFunction function) {
* function.
*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public record ChatCompletionFunction(// @formatter:off
@JsonProperty("name") String name,
@JsonProperty("arguments") String arguments) { // @formatter:on
Expand All @@ -718,6 +719,7 @@ public record ChatCompletionFunction(// @formatter:off
* @param usage Usage statistics for the completion request.
*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public record ChatCompletion(// @formatter:off
@JsonProperty("id") String id,
@JsonProperty("choices") List<Choice> choices,
Expand All @@ -737,6 +739,7 @@ public record ChatCompletion(// @formatter:off
* @param logprobs Log probability information for the choice.
*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public record Choice(// @formatter:off
@JsonProperty("finish_reason") ChatCompletionFinishReason finishReason,
@JsonProperty("index") Integer index,
Expand All @@ -753,6 +756,7 @@ public record Choice(// @formatter:off
* @param refusal A list of message refusal tokens with log probability information.
*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public record LogProbs(@JsonProperty("content") List<Content> content,
@JsonProperty("refusal") List<Content> refusal) {

Expand All @@ -771,6 +775,7 @@ public record LogProbs(@JsonProperty("content") List<Content> content,
* requested top_logprobs returned.
*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public record Content(// @formatter:off
@JsonProperty("token") String token,
@JsonProperty("logprob") Float logprob,
Expand All @@ -789,6 +794,7 @@ public record Content(// @formatter:off
* is no bytes representation for the token.
*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public record TopLogProbs(// @formatter:off
@JsonProperty("token") String token,
@JsonProperty("logprob") Float logprob,
Expand All @@ -812,6 +818,7 @@ public record TopLogProbs(// @formatter:off
* @param promptTokensDetails Breakdown of tokens used in the prompt.
*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public record Usage(// @formatter:off
@JsonProperty("completion_tokens") Integer completionTokens,
@JsonProperty("prompt_tokens") Integer promptTokens,
Expand All @@ -828,6 +835,7 @@ public Usage(Integer completionTokens, Integer promptTokens, Integer totalTokens
* @param cachedTokens Cached tokens present in the prompt.
*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public record PromptTokensDetails(// @formatter:off
@JsonProperty("cached_tokens") Integer cachedTokens) { // @formatter:on
}
Expand All @@ -853,6 +861,7 @@ public record PromptTokensDetails(// @formatter:off
* only if the StreamOptions.includeUsage is set to true.
*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public record ChatCompletionChunk(// @formatter:off
@JsonProperty("id") String id,
@JsonProperty("choices") List<ChunkChoice> choices,
Expand All @@ -872,6 +881,7 @@ public record ChatCompletionChunk(// @formatter:off
* @param logprobs Log probability information for the choice.
*/
@JsonInclude(Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public record ChunkChoice(// @formatter:off
@JsonProperty("finish_reason") ChatCompletionFinishReason finishReason,
@JsonProperty("index") Integer index,
Expand Down