| | |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
| | | import com.fasterxml.jackson.annotation.JsonInclude; |
| | | import com.fasterxml.jackson.annotation.JsonProperty; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Data; |
| | | import lombok.Getter; |
| | | import org.ruoyi.common.chat.entity.chat.tool.ToolCalls; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 描述: |
| | |
| | | @Data |
| | | @JsonInclude(JsonInclude.Include.NON_NULL) |
| | | @JsonIgnoreProperties(ignoreUnknown = true) |
| | | public class Message implements Serializable { |
| | | |
| | | /** |
| | | * 目前支持四个中角色参考官网,进行情景输入: |
| | | * https://platform.openai.com/docs/guides/chat/introduction |
| | | */ |
| | | private String role; |
| | | public class Message extends BaseMessage implements Serializable { |
| | | |
| | | private Object content; |
| | | |
| | | private String name; |
| | | |
| | | @JsonProperty("function_call") |
| | | private FunctionCall functionCall; |
| | | |
| | | public static Builder builder() { |
| | | return new Builder(); |
| | |
| | | * 构造函数 |
| | | * |
| | | * @param role 角色 |
| | | * @param content 描述主题信息 |
| | | * @param name name |
| | | * @param content content |
| | | * @param functionCall functionCall |
| | | */ |
| | | public Message(String role, String content, String name, FunctionCall functionCall) { |
| | | this.role = role; |
| | | public Message(String role, String name, String content, List<ToolCalls> toolCalls, String toolCallId, FunctionCall functionCall) { |
| | | this.content = content; |
| | | this.name = name; |
| | | this.functionCall = functionCall; |
| | | super.setRole(role); |
| | | super.setName(name); |
| | | super.setToolCalls(toolCalls); |
| | | super.setToolCallId(toolCallId); |
| | | super.setFunctionCall(functionCall); |
| | | } |
| | | |
| | | public Message() { |
| | | } |
| | | |
| | | private Message(Builder builder) { |
| | | setRole(builder.role); |
| | | setContent(builder.content); |
| | | setName(builder.name); |
| | | setFunctionCall(builder.functionCall); |
| | | } |
| | | |
| | | |
| | | @Getter |
| | | @AllArgsConstructor |
| | | public enum Role { |
| | | |
| | | SYSTEM("system"), |
| | | USER("user"), |
| | | ASSISTANT("assistant"), |
| | | FUNCTION("function"), |
| | | ; |
| | | private String name; |
| | | super.setRole(builder.role); |
| | | super.setName(builder.name); |
| | | super.setFunctionCall(builder.functionCall); |
| | | super.setToolCalls(builder.toolCalls); |
| | | super.setToolCallId(builder.toolCallId); |
| | | } |
| | | |
| | | public static final class Builder { |
| | | private String role; |
| | | private String content; |
| | | private String name; |
| | | private String toolCallId; |
| | | private List<ToolCalls> toolCalls; |
| | | private FunctionCall functionCall; |
| | | |
| | | public Builder() { |
| | |
| | | return this; |
| | | } |
| | | |
| | | public Builder toolCalls(List<ToolCalls> toolCalls) { |
| | | this.toolCalls = toolCalls; |
| | | return this; |
| | | } |
| | | |
| | | public Builder toolCallId(String toolCallId) { |
| | | this.toolCallId = toolCallId; |
| | | return this; |
| | | } |
| | | |
| | | public Message build() { |
| | | return new Message(this); |
| | | } |