Skip to content

Commit

Permalink
Added priority to Role enum.
Browse files Browse the repository at this point in the history
  • Loading branch information
nandita727 committed Jan 18, 2024
1 parent ea905cb commit 2e1adfc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/main/java/com/meta/cp4m/message/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
}
2 changes: 1 addition & 1 deletion src/main/java/com/meta/cp4m/message/ThreadState.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private ThreadState(ThreadState<T> 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(
Expand Down

0 comments on commit 2e1adfc

Please sign in to comment.