parent
fab1f9e26c
commit
9bfbd3674d
@ -0,0 +1,12 @@
|
|||||||
|
package xyz.wbsite.achat.core.chat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 嵌入请求
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public class EmbeddingsRequest {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,204 @@
|
|||||||
|
package xyz.wbsite.achat.core.chat;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OpenAI聊天完成响应 - 符合OpenAI官方API规范
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public class EmbeddingsResponse {
|
||||||
|
private String id;
|
||||||
|
private String object;
|
||||||
|
private long created;
|
||||||
|
private String model;
|
||||||
|
private List<Choice> choices;
|
||||||
|
private Usage usage;
|
||||||
|
|
||||||
|
private EmbeddingsResponse(Builder builder) {
|
||||||
|
this.id = builder.id;
|
||||||
|
this.object = builder.object;
|
||||||
|
this.created = builder.created;
|
||||||
|
this.model = builder.model;
|
||||||
|
this.choices = builder.choices;
|
||||||
|
this.usage = builder.usage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getObject() {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setObject(String object) {
|
||||||
|
this.object = object;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getCreated() {
|
||||||
|
return created;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreated(long created) {
|
||||||
|
this.created = created;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getModel() {
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModel(String model) {
|
||||||
|
this.model = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Choice> getChoices() {
|
||||||
|
return choices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setChoices(List<Choice> choices) {
|
||||||
|
this.choices = choices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Usage getUsage() {
|
||||||
|
return usage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsage(Usage usage) {
|
||||||
|
this.usage = usage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
private String id;
|
||||||
|
private String object;
|
||||||
|
private long created;
|
||||||
|
private String model;
|
||||||
|
private List<Choice> choices = new ArrayList<>();
|
||||||
|
private Usage usage;
|
||||||
|
|
||||||
|
public Builder id(String id) {
|
||||||
|
this.id = id;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder object(String object) {
|
||||||
|
this.object = object;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder created(long created) {
|
||||||
|
this.created = created;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder model(String model) {
|
||||||
|
this.model = model;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder choices(List<Choice> choices) {
|
||||||
|
this.choices = choices;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder withChoices(java.util.function.Consumer<List<Choice>> choicesConsumer) {
|
||||||
|
choicesConsumer.accept(this.choices);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder usage(Usage usage) {
|
||||||
|
this.usage = usage;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EmbeddingsResponse build() {
|
||||||
|
return new EmbeddingsResponse(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Choice {
|
||||||
|
private int index = 0;
|
||||||
|
private Message message;
|
||||||
|
private String finish_reason;
|
||||||
|
|
||||||
|
public Integer getIndex() {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIndex(Integer index) {
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Message getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(Message message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFinish_reason() {
|
||||||
|
return finish_reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFinish_reason(String finish_reason) {
|
||||||
|
this.finish_reason = finish_reason;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ChoiceBuilder choiceBuilder() {
|
||||||
|
return new ChoiceBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ChoiceBuilder {
|
||||||
|
private Integer index;
|
||||||
|
private Role role;
|
||||||
|
private String content;
|
||||||
|
private String name;
|
||||||
|
private String finish_reason;
|
||||||
|
|
||||||
|
public ChoiceBuilder index(Integer index) {
|
||||||
|
this.index = index;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChoiceBuilder role(Role role) {
|
||||||
|
this.role = role;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChoiceBuilder content(String content) {
|
||||||
|
this.content = content;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChoiceBuilder name(String name) {
|
||||||
|
this.name = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChoiceBuilder finish_reason(String finish_reason) {
|
||||||
|
this.finish_reason = finish_reason;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Choice build() {
|
||||||
|
Choice choice = new Choice();
|
||||||
|
choice.setIndex(index);
|
||||||
|
choice.setMessage(Message.builder().role(role).content(content).name(name).build());
|
||||||
|
choice.setFinish_reason(finish_reason);
|
||||||
|
return choice;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package xyz.wbsite.achat.core.message;
|
package xyz.wbsite.achat.core.chat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息
|
* 消息
|
@ -1,4 +1,4 @@
|
|||||||
package xyz.wbsite.achat.core.message;
|
package xyz.wbsite.achat.core.chat;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonValue;
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package xyz.wbsite.achat.core.message;
|
package xyz.wbsite.achat.core.chat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息状态枚举
|
* 消息状态枚举
|
@ -0,0 +1,88 @@
|
|||||||
|
package xyz.wbsite.achat.core.chat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 令牌使用统计
|
||||||
|
*
|
||||||
|
* @author wangbing
|
||||||
|
* @version 0.0.1
|
||||||
|
* @since 1.8
|
||||||
|
*/
|
||||||
|
public class Usage {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提示词 tokens 数量
|
||||||
|
*/
|
||||||
|
private int prompt_tokens;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 补全 tokens 数量
|
||||||
|
*/
|
||||||
|
private int completion_tokens;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总 tokens 数量
|
||||||
|
*/
|
||||||
|
private int total_tokens;
|
||||||
|
|
||||||
|
public Usage() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private Usage(Builder builder) {
|
||||||
|
this.prompt_tokens = builder.prompt_tokens;
|
||||||
|
this.completion_tokens = builder.completion_tokens;
|
||||||
|
this.total_tokens = builder.total_tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPrompt_tokens() {
|
||||||
|
return prompt_tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrompt_tokens(int prompt_tokens) {
|
||||||
|
this.prompt_tokens = prompt_tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCompletion_tokens() {
|
||||||
|
return completion_tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCompletion_tokens(int completion_tokens) {
|
||||||
|
this.completion_tokens = completion_tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTotal_tokens() {
|
||||||
|
return total_tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotal_tokens(int total_tokens) {
|
||||||
|
this.total_tokens = total_tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
private int prompt_tokens;
|
||||||
|
private int completion_tokens;
|
||||||
|
private int total_tokens;
|
||||||
|
|
||||||
|
public Builder prompt_tokens(int prompt_tokens) {
|
||||||
|
this.prompt_tokens = prompt_tokens;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder completion_tokens(int completion_tokens) {
|
||||||
|
this.completion_tokens = completion_tokens;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder total_tokens(int total_tokens) {
|
||||||
|
this.total_tokens = total_tokens;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Usage build() {
|
||||||
|
return new Usage(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +0,0 @@
|
|||||||
//package xyz.wbsite.achat.core.message;
|
|
||||||
//
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * 用户消息
|
|
||||||
// *
|
|
||||||
// * @author wangbing
|
|
||||||
// * @version 0.0.1
|
|
||||||
// * @since 1.8
|
|
||||||
// */
|
|
||||||
//public class AiMessage extends Message {
|
|
||||||
//
|
|
||||||
//}
|
|
@ -1,41 +0,0 @@
|
|||||||
//package xyz.wbsite.achat.core.message;
|
|
||||||
//
|
|
||||||
//import xyz.wbsite.achat.core.Attachment;
|
|
||||||
//
|
|
||||||
//import java.util.List;
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * 用户消息
|
|
||||||
// *
|
|
||||||
// * @author wangbing
|
|
||||||
// * @version 0.0.1
|
|
||||||
// * @since 1.8
|
|
||||||
// */
|
|
||||||
//public class UserMessage extends Message {
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 用户ID
|
|
||||||
// */
|
|
||||||
// private String uid;
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * 附件
|
|
||||||
// */
|
|
||||||
// private List<Attachment> attachments;
|
|
||||||
//
|
|
||||||
// public String getUid() {
|
|
||||||
// return uid;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void setUid(String uid) {
|
|
||||||
// this.uid = uid;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public List<Attachment> getAttachments() {
|
|
||||||
// return attachments;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void setAttachments(List<Attachment> attachments) {
|
|
||||||
// this.attachments = attachments;
|
|
||||||
// }
|
|
||||||
//}
|
|
Loading…
Reference in new issue