From e0c9353a656edcb8f20fbc25f4badf3f8ad45220 Mon Sep 17 00:00:00 2001 From: Jean Schmitz Date: Fri, 26 Jan 2024 17:12:54 +0100 Subject: [PATCH] Added @JsonIgnoreProperties to Records to minify risk of errors if new attributes are added to the API --- .../openai/assistant/dto/Assistant.java | 40 +++++----- .../openai/assistant/dto/AssistantList.java | 6 +- .../service/openai/assistant/dto/Message.java | 79 ++++++++++--------- .../openai/assistant/dto/MessageList.java | 21 ++--- .../service/openai/assistant/dto/Run.java | 73 +++++++++-------- .../service/openai/assistant/dto/Thread.java | 16 ++-- 6 files changed, 124 insertions(+), 111 deletions(-) diff --git a/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/Assistant.java b/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/Assistant.java index 7695e152..8385c289 100644 --- a/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/Assistant.java +++ b/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/Assistant.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Jean Schmitz. + * Copyright (c) 2023-2024 Jean Schmitz. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,31 +16,31 @@ package com.talkforgeai.service.openai.assistant.dto; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; - import java.util.List; import java.util.Map; - +@JsonIgnoreProperties(ignoreUnknown = true) public record Assistant( - @JsonInclude(JsonInclude.Include.NON_NULL) - String id, - - @JsonInclude(JsonInclude.Include.NON_NULL) - String object, - - @JsonInclude(JsonInclude.Include.NON_NULL) - @JsonProperty("created_at") - String createdAt, - String name, - String description, - String model, - String instructions, - List tools, - @JsonProperty("file_ids") - List fileIds, - Map metadata + @JsonInclude(JsonInclude.Include.NON_NULL) + String id, + + @JsonInclude(JsonInclude.Include.NON_NULL) + String object, + + @JsonInclude(JsonInclude.Include.NON_NULL) + @JsonProperty("created_at") + String createdAt, + String name, + String description, + String model, + String instructions, + List tools, + @JsonProperty("file_ids") + List fileIds, + Map metadata ) { } diff --git a/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/AssistantList.java b/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/AssistantList.java index 011806f2..ece71d0e 100644 --- a/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/AssistantList.java +++ b/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/AssistantList.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Jean Schmitz. + * Copyright (c) 2023-2024 Jean Schmitz. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,11 @@ package com.talkforgeai.service.openai.assistant.dto; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; - import java.util.List; +@JsonIgnoreProperties(ignoreUnknown = true) public record AssistantList(String object, List data, @JsonProperty("first_id") @@ -28,4 +29,5 @@ public record AssistantList(String object, String lastId, @JsonProperty("has_more") Boolean hasMore) { + } diff --git a/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/Message.java b/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/Message.java index df37035c..97e03e3d 100644 --- a/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/Message.java +++ b/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/Message.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Jean Schmitz. + * Copyright (c) 2023-2024 Jean Schmitz. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,52 +16,57 @@ package com.talkforgeai.service.openai.assistant.dto; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; - import java.util.Date; import java.util.List; import java.util.Map; +@JsonIgnoreProperties(ignoreUnknown = true) public record Message( - String id, - String object, - @JsonProperty("created_at") - Date createdAt, - @JsonProperty("thread_id") - String threadId, - Role role, - List content, - @JsonProperty("file_ids") - List fileIds, - @JsonProperty("assistant_id") - String assistantId, - @JsonProperty("run_id") - String runId, - Map metadata + String id, + String object, + @JsonProperty("created_at") + Date createdAt, + @JsonProperty("thread_id") + String threadId, + Role role, + List content, + @JsonProperty("file_ids") + List fileIds, + @JsonProperty("assistant_id") + String assistantId, + @JsonProperty("run_id") + String runId, + Map metadata ) { - @JsonInclude(JsonInclude.Include.NON_NULL) - public record ContentItem( - String type, - TextContent text, - @JsonProperty("image_file") - ImageContent imageFile + @JsonInclude(JsonInclude.Include.NON_NULL) + public record ContentItem( + String type, + TextContent text, + @JsonProperty("image_file") + ImageContent imageFile + ) { + + public record TextContent( + String value, + List annotations + ) { + + public record Annotation( + // Define the annotation structure here + ) { + + } + } + + public record ImageContent( + @JsonProperty("file_id") + String fileId ) { - public record TextContent( - String value, - List annotations - ) { - public record Annotation( - // Define the annotation structure here - ) { - } - } - public record ImageContent( - @JsonProperty("file_id") - String fileId - ) { - } } + } } \ No newline at end of file diff --git a/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/MessageList.java b/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/MessageList.java index 68624381..3a4bd504 100644 --- a/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/MessageList.java +++ b/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/MessageList.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Jean Schmitz. + * Copyright (c) 2023-2024 Jean Schmitz. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,18 +16,19 @@ package com.talkforgeai.service.openai.assistant.dto; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; - import java.util.List; +@JsonIgnoreProperties(ignoreUnknown = true) public record MessageList( - String object, - List data, - @JsonProperty("first_id") - String firstId, - @JsonProperty("last_id") - String lastId, - @JsonProperty("has_more") - boolean hasMore) { + String object, + List data, + @JsonProperty("first_id") + String firstId, + @JsonProperty("last_id") + String lastId, + @JsonProperty("has_more") + boolean hasMore) { } diff --git a/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/Run.java b/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/Run.java index 3226d725..81a2d792 100644 --- a/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/Run.java +++ b/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/Run.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Jean Schmitz. + * Copyright (c) 2023-2024 Jean Schmitz. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,49 +16,52 @@ package com.talkforgeai.service.openai.assistant.dto; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; - import java.util.Date; import java.util.List; import java.util.Map; +@JsonIgnoreProperties(ignoreUnknown = true) public record Run( - String id, - String object, - @JsonProperty("created_at") - long createdAt, - @JsonProperty("assistant_id") - String assistantId, - @JsonProperty("thread_id") - String threadId, - String status, - @JsonProperty("started_at") - Date startedAt, - @JsonProperty("expires_at") - Date expiresAt, - @JsonProperty("cancelled_at") - Date cancelledAt, - @JsonProperty("failed_at") - Date failedAt, - @JsonProperty("completed_at") - Date completedAt, - @JsonProperty("last_error") - LastError lastError, - String model, - String instructions, - List tools, - @JsonProperty("file_ids") - List fileIds, - Map metadata + String id, + String object, + @JsonProperty("created_at") + long createdAt, + @JsonProperty("assistant_id") + String assistantId, + @JsonProperty("thread_id") + String threadId, + String status, + @JsonProperty("started_at") + Date startedAt, + @JsonProperty("expires_at") + Date expiresAt, + @JsonProperty("cancelled_at") + Date cancelledAt, + @JsonProperty("failed_at") + Date failedAt, + @JsonProperty("completed_at") + Date completedAt, + @JsonProperty("last_error") + LastError lastError, + String model, + String instructions, + List tools, + @JsonProperty("file_ids") + List fileIds, + Map metadata ) { - public record LastError(String code, String message) { - } + public record LastError(String code, String message) { + + } + + public record ToolRecord( + String type + ) { - public record ToolRecord( - String type - ) { - } + } } diff --git a/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/Thread.java b/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/Thread.java index 8196406b..0bbd1aad 100644 --- a/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/Thread.java +++ b/service/src/main/java/com/talkforgeai/service/openai/assistant/dto/Thread.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Jean Schmitz. + * Copyright (c) 2023-2024 Jean Schmitz. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,16 +16,18 @@ package com.talkforgeai.service.openai.assistant.dto; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; - import java.util.Date; import java.util.Map; +@JsonIgnoreProperties(ignoreUnknown = true) public record Thread( - String id, - String object, - @JsonProperty("created_at") - Date createdAt, - Map metadata + String id, + String object, + @JsonProperty("created_at") + Date createdAt, + Map metadata ) { + }