|
|
@ -1,5 +1,7 @@
|
|
|
|
package xyz.wbsite.achat.chat;
|
|
|
|
package xyz.wbsite.achat.chat;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import xyz.wbsite.achat.chat.tool.ToolCall;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
@ -18,11 +20,9 @@ public class ChatCompletionResponse {
|
|
|
|
private List<Choice> choices;
|
|
|
|
private List<Choice> choices;
|
|
|
|
private Usage usage;
|
|
|
|
private Usage usage;
|
|
|
|
|
|
|
|
|
|
|
|
// 无参构造函数
|
|
|
|
|
|
|
|
public ChatCompletionResponse() {
|
|
|
|
public ChatCompletionResponse() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 私有构造函数,用于Builder模式
|
|
|
|
|
|
|
|
private ChatCompletionResponse(Builder builder) {
|
|
|
|
private ChatCompletionResponse(Builder builder) {
|
|
|
|
this.id = builder.id;
|
|
|
|
this.id = builder.id;
|
|
|
|
this.object = builder.object;
|
|
|
|
this.object = builder.object;
|
|
|
@ -32,12 +32,10 @@ public class ChatCompletionResponse {
|
|
|
|
this.usage = builder.usage;
|
|
|
|
this.usage = builder.usage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 静态builder方法,返回Builder实例
|
|
|
|
|
|
|
|
public static Builder builder() {
|
|
|
|
public static Builder builder() {
|
|
|
|
return new Builder();
|
|
|
|
return new Builder();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Getters and Setters
|
|
|
|
|
|
|
|
public String getId() {
|
|
|
|
public String getId() {
|
|
|
|
return id;
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -86,7 +84,6 @@ public class ChatCompletionResponse {
|
|
|
|
this.usage = usage;
|
|
|
|
this.usage = usage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Builder内部类
|
|
|
|
|
|
|
|
public static class Builder {
|
|
|
|
public static class Builder {
|
|
|
|
private String id;
|
|
|
|
private String id;
|
|
|
|
private String object;
|
|
|
|
private String object;
|
|
|
@ -115,13 +112,11 @@ public class ChatCompletionResponse {
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 设置整个choices列表
|
|
|
|
|
|
|
|
public Builder choices(List<Choice> choices) {
|
|
|
|
public Builder choices(List<Choice> choices) {
|
|
|
|
this.choices = choices;
|
|
|
|
this.choices = choices;
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 使用lambda表达式构建choices列表,优化代码可读性
|
|
|
|
|
|
|
|
public Builder withChoices(java.util.function.Consumer<List<Choice>> choicesConsumer) {
|
|
|
|
public Builder withChoices(java.util.function.Consumer<List<Choice>> choicesConsumer) {
|
|
|
|
choicesConsumer.accept(this.choices);
|
|
|
|
choicesConsumer.accept(this.choices);
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
@ -177,6 +172,7 @@ public class ChatCompletionResponse {
|
|
|
|
private String content;
|
|
|
|
private String content;
|
|
|
|
private String name;
|
|
|
|
private String name;
|
|
|
|
private String finish_reason;
|
|
|
|
private String finish_reason;
|
|
|
|
|
|
|
|
private List<ToolCall> toolCalls = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
public ChoiceBuilder index(Integer index) {
|
|
|
|
public ChoiceBuilder index(Integer index) {
|
|
|
|
this.index = index;
|
|
|
|
this.index = index;
|
|
|
@ -203,10 +199,25 @@ public class ChatCompletionResponse {
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ChoiceBuilder withToolCalls(java.util.function.Consumer<List<ToolCall>> choicesConsumer) {
|
|
|
|
|
|
|
|
choicesConsumer.accept(this.toolCalls);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ChoiceBuilder addToolCall(ToolCall toolCalls) {
|
|
|
|
|
|
|
|
this.toolCalls.add(toolCalls);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Choice build() {
|
|
|
|
public Choice build() {
|
|
|
|
Choice choice = new Choice();
|
|
|
|
Choice choice = new Choice();
|
|
|
|
choice.setIndex(index);
|
|
|
|
choice.setIndex(index);
|
|
|
|
choice.setMessage(Message.builder().role(role).content(content).name(name).build());
|
|
|
|
choice.setMessage(Message.builder()
|
|
|
|
|
|
|
|
.role(role)
|
|
|
|
|
|
|
|
.content(content)
|
|
|
|
|
|
|
|
.name(name)
|
|
|
|
|
|
|
|
.tool_calls(toolCalls)
|
|
|
|
|
|
|
|
.build());
|
|
|
|
choice.setFinish_reason(finish_reason);
|
|
|
|
choice.setFinish_reason(finish_reason);
|
|
|
|
return choice;
|
|
|
|
return choice;
|
|
|
|
}
|
|
|
|
}
|
|
|
|