From 2e1adfcc14a597a4842e2f1fd72904401db5422e Mon Sep 17 00:00:00 2001 From: Nandita Rao Date: Thu, 18 Jan 2024 10:42:07 -0500 Subject: [PATCH] Added priority to Role enum. --- src/main/java/com/meta/cp4m/message/Message.java | 13 ++++++++++--- .../java/com/meta/cp4m/message/ThreadState.java | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/meta/cp4m/message/Message.java b/src/main/java/com/meta/cp4m/message/Message.java index 69c3cc8..26dd4c1 100644 --- a/src/main/java/com/meta/cp4m/message/Message.java +++ b/src/main/java/com/meta/cp4m/message/Message.java @@ -44,8 +44,15 @@ default Identifier threadId() { } enum Role { - ASSISTANT, - USER, - SYSTEM + ASSISTANT(0), + USER(1), + SYSTEM(2); + + public final Integer priority; + + private Role(Integer priority){ + this.priority = priority; + } + } } diff --git a/src/main/java/com/meta/cp4m/message/ThreadState.java b/src/main/java/com/meta/cp4m/message/ThreadState.java index f130fec..883cbb2 100644 --- a/src/main/java/com/meta/cp4m/message/ThreadState.java +++ b/src/main/java/com/meta/cp4m/message/ThreadState.java @@ -42,7 +42,7 @@ private ThreadState(ThreadState old, T newMessage) { T mWithParentMessage = newMessage.role() == Role.USER ? (T) newMessage.addParentMessage(old.tail()): newMessage; this.messages = Stream.concat(messages.stream(), Stream.of(mWithParentMessage)) - .sorted((m1,m2) -> m1.parentMessage() == m2.parentMessage() ? (m1.role().compareTo(m2.role())) : (m1.timestamp().compareTo(m2.timestamp()))) + .sorted((m1,m2) -> m1.parentMessage() == m2.parentMessage() ? (m1.role().priority.compareTo(m2.role().priority)) : (m1.timestamp().compareTo(m2.timestamp()))) .collect(Collectors.toUnmodifiableList()); Preconditions.checkArgument(