This repository was archived by the owner on Jun 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathChatMessage.java
More file actions
51 lines (46 loc) · 2.12 KB
/
ChatMessage.java
File metadata and controls
51 lines (46 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.theokanning.openai.completion.chat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* <p>Each object has a role (either "system", "user", or "assistant") and content (the content of the message). Conversations can be as short as 1 message or fill many pages.</p>
* <p>Typically, a conversation is formatted with a system message first, followed by alternating user and assistant messages.</p>
* <p>The system message helps set the behavior of the assistant. In the example above, the assistant was instructed with "You are a helpful assistant."<br>
* The user messages help instruct the assistant. They can be generated by the end users of an application, or set by a developer as an instruction.<br>
* The assistant messages help store prior responses. They can also be written by a developer to help give examples of desired behavior.
* </p>
*
* see <a href="https://platform.openai.com/docs/guides/chat/introduction">OpenAi documentation</a>
*/
@Data
@NoArgsConstructor(force = true)
@AllArgsConstructor
public class ChatMessage<T> {
/**
* Must be either 'system', 'user', 'assistant' or 'function'.<br>
* You may use {@link ChatMessageRole} enum.
*/
String role;
/**
* An array of content parts with a defined type, each can be of type text or image_url when passing in images. You
* can pass multiple images by adding multiple image_url content parts. Image input is only supported when using the
* gpt-4-visual-preview model.
*/
@JsonInclude() // content should always exist in the call, even if it is null
T content;
//name is optional, The name of the author of this message. May contain a-z, A-Z, 0-9, and underscores, with a maximum length of 64 characters.
String name;
@JsonProperty("function_call")
ChatFunctionCall functionCall;
public ChatMessage(String role, T content) {
this.role = role;
this.content = content;
}
public ChatMessage(String role, T content, String name) {
this.role = role;
this.content = content;
this.name = name;
}
}