Skip to content

Commit 59bbeb3

Browse files
committed
Default to assistant role when received null
1 parent a050057 commit 59bbeb3

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

api/src/main/java/com/theokanning/openai/completion/chat/ChatMessage.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
1818
*/
1919
@Data
2020
@NoArgsConstructor(force = true)
21-
@RequiredArgsConstructor
2221
@AllArgsConstructor
2322
public class ChatMessage {
2423

2524
/**
2625
* Must be either 'system', 'user', 'assistant' or 'function'.<br>
26+
* If it's set to null, it will be set to 'assistant' by default.<br>
2727
* You may use {@link ChatMessageRole} enum.
2828
*/
29-
@NonNull
3029
String role;
3130
@JsonInclude() // content should always exist in the call, even if it is null
3231
String content;
@@ -40,12 +39,12 @@ public class ChatMessage {
4039
ChatFunctionCall functionCall;
4140

4241
public ChatMessage(String role, String content) {
43-
this.role = role;
42+
this.role = role == null ? "assistant" : role;
4443
this.content = content;
4544
}
4645

4746
public ChatMessage(String role, String content, String name) {
48-
this.role = role;
47+
this.role = role == null ? "assistant" : role;
4948
this.content = content;
5049
this.name = name;
5150
}

0 commit comments

Comments
 (0)