Skip to content

Commit

Permalink
Added @JsonIgnoreProperties to Records to minify risk of errors if ne…
Browse files Browse the repository at this point in the history
…w attributes are added to the API
  • Loading branch information
jschm42 committed Jan 26, 2024
1 parent 56dd987 commit e0c9353
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 111 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<Tool> tools,
@JsonProperty("file_ids")
List<String> fileIds,
Map<String, Object> 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<Tool> tools,
@JsonProperty("file_ids")
List<String> fileIds,
Map<String, Object> metadata
) {

}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<Assistant> data,
@JsonProperty("first_id")
Expand All @@ -28,4 +29,5 @@ public record AssistantList(String object,
String lastId,
@JsonProperty("has_more")
Boolean hasMore) {

}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<ContentItem> content,
@JsonProperty("file_ids")
List<String> fileIds,
@JsonProperty("assistant_id")
String assistantId,
@JsonProperty("run_id")
String runId,
Map<String, Object> metadata
String id,
String object,
@JsonProperty("created_at")
Date createdAt,
@JsonProperty("thread_id")
String threadId,
Role role,
List<ContentItem> content,
@JsonProperty("file_ids")
List<String> fileIds,
@JsonProperty("assistant_id")
String assistantId,
@JsonProperty("run_id")
String runId,
Map<String, Object> 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<Annotation> annotations
) {

public record Annotation(
// Define the annotation structure here
) {

}
}

public record ImageContent(
@JsonProperty("file_id")
String fileId
) {
public record TextContent(
String value,
List<Annotation> annotations
) {
public record Annotation(
// Define the annotation structure here
) {
}
}

public record ImageContent(
@JsonProperty("file_id")
String fileId
) {
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<Message> data,
@JsonProperty("first_id")
String firstId,
@JsonProperty("last_id")
String lastId,
@JsonProperty("has_more")
boolean hasMore) {
String object,
List<Message> data,
@JsonProperty("first_id")
String firstId,
@JsonProperty("last_id")
String lastId,
@JsonProperty("has_more")
boolean hasMore) {

}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<ToolRecord> tools,
@JsonProperty("file_ids")
List<String> fileIds,
Map<String, Object> 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<ToolRecord> tools,
@JsonProperty("file_ids")
List<String> fileIds,
Map<String, Object> 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
) {
}
}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<String, Object> metadata
String id,
String object,
@JsonProperty("created_at")
Date createdAt,
Map<String, Object> metadata
) {

}

0 comments on commit e0c9353

Please sign in to comment.