上传备份

master
王兵 4 days ago
parent fab1f9e26c
commit 9bfbd3674d

@ -8,7 +8,7 @@
//import org.springframework.web.bind.annotation.ResponseBody;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
//import xyz.wbsite.achat.core.message.Message;
//import xyz.wbsite.achat.core.chat.Message;
//import xyz.wbsite.achat.core.Result;
//import xyz.wbsite.achat.core.Session;
//import xyz.wbsite.achat.core.prompt.MessagePrompt;

@ -1,6 +1,5 @@
package xyz.wbsite.achat;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@ -10,6 +9,8 @@ import org.springframework.web.bind.annotation.RestController;
import xyz.wbsite.achat.core.chat.ChatCompletionRequest;
import xyz.wbsite.achat.core.chat.CompletionRequest;
import xyz.wbsite.achat.core.chat.CompletionResponse;
import xyz.wbsite.achat.core.chat.EmbeddingsRequest;
import xyz.wbsite.achat.core.chat.EmbeddingsResponse;
import xyz.wbsite.achat.core.model.ModelListResponse;
import xyz.wbsite.achat.core.service.ChatService;
@ -31,8 +32,6 @@ public class OpenAiController {
@Resource
private ChatService chatService;
private static final ObjectMapper objectMapper = new ObjectMapper();
@RequestMapping()
public String info() {
return "OpenAI API is support";
@ -82,4 +81,10 @@ public class OpenAiController {
return chatService.chat(request);
}
}
@RequestMapping("/embeddings")
public EmbeddingsResponse embeddings(@RequestBody EmbeddingsRequest request) {
return chatService.embeddings(request);
}
}

@ -30,6 +30,46 @@ public class ChatCompletionChunk {
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 static class Builder {
private String id;
private String object;
@ -74,49 +114,9 @@ public class ChatCompletionChunk {
}
}
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 static class Choice {
private int index = 0;
private Delta delta;
private Message delta;
private String finish_reason;
public Integer getIndex() {
@ -127,11 +127,11 @@ public class ChatCompletionChunk {
this.index = index;
}
public Delta getDelta() {
public Message getDelta() {
return delta;
}
public void setDelta(Delta delta) {
public void setDelta(Message delta) {
this.delta = delta;
}
@ -144,27 +144,44 @@ public class ChatCompletionChunk {
}
}
/**
*
*/
public static class Delta {
private String role;
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 String getRole() {
return role;
public ChoiceBuilder index(Integer index) {
this.index = index;
return this;
}
public void setRole(String role) {
public ChoiceBuilder role(Role role) {
this.role = role;
return this;
}
public String getContent() {
return content;
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 void setContent(String content) {
this.content = content;
public Choice build() {
Choice choice = new Choice();
choice.setIndex(index);
choice.setDelta(Message.builder().role(role).content(content).name(name).build());
choice.setFinish_reason(finish_reason);
return choice;
}
}
}

@ -1,7 +1,5 @@
package xyz.wbsite.achat.core.chat;
import xyz.wbsite.achat.core.message.Message;
import java.util.List;
/**

@ -1,7 +1,5 @@
package xyz.wbsite.achat.core.chat;
import xyz.wbsite.achat.core.message.Message;
import java.util.ArrayList;
import java.util.List;
@ -39,57 +37,6 @@ public class ChatCompletionResponse {
return new Builder();
}
// Builder内部类
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;
}
// 设置整个choices列表
public Builder choices(List<Choice> choices) {
this.choices = choices;
return this;
}
// 使用lambda表达式构建choices列表优化代码可读性
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 ChatCompletionResponse build() {
return new ChatCompletionResponse(this);
}
}
// Getters and Setters
public String getId() {
return id;
@ -139,6 +86,57 @@ public class ChatCompletionResponse {
this.usage = usage;
}
// Builder内部类
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;
}
// 设置整个choices列表
public Builder choices(List<Choice> choices) {
this.choices = choices;
return this;
}
// 使用lambda表达式构建choices列表优化代码可读性
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 ChatCompletionResponse build() {
return new ChatCompletionResponse(this);
}
}
public static class Choice {
private int index = 0;
private Message message;
@ -169,33 +167,48 @@ public class ChatCompletionResponse {
}
}
public static class Usage {
private int prompt_tokens;
private int completion_tokens;
private int total_tokens;
public static ChoiceBuilder choiceBuilder() {
return new ChoiceBuilder();
}
public int getPrompt_tokens() {
return prompt_tokens;
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 void setPrompt_tokens(int prompt_tokens) {
this.prompt_tokens = prompt_tokens;
public ChoiceBuilder role(Role role) {
this.role = role;
return this;
}
public int getCompletion_tokens() {
return completion_tokens;
public ChoiceBuilder content(String content) {
this.content = content;
return this;
}
public void setCompletion_tokens(int completion_tokens) {
this.completion_tokens = completion_tokens;
public ChoiceBuilder name(String name) {
this.name = name;
return this;
}
public int getTotal_tokens() {
return total_tokens;
public ChoiceBuilder finish_reason(String finish_reason) {
this.finish_reason = finish_reason;
return this;
}
public void setTotal_tokens(int total_tokens) {
this.total_tokens = total_tokens;
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,7 +1,5 @@
package xyz.wbsite.achat.core.chat;
import xyz.wbsite.achat.core.message.Message;
import java.util.ArrayList;
import java.util.List;
@ -29,63 +27,10 @@ public class CompletionResponse {
this.usage = builder.usage;
}
// 静态builder方法返回Builder实例
public static Builder builder() {
return new Builder();
}
// Builder内部类
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;
}
// 设置整个choices列表
public Builder choices(List<Choice> choices) {
this.choices = choices;
return this;
}
// 使用lambda表达式构建choices列表优化代码可读性
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;
}
// 构建CompletionResponse对象
public CompletionResponse build() {
return new CompletionResponse(this);
}
}
public String getId() {
return id;
}
@ -134,6 +79,53 @@ public class CompletionResponse {
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 CompletionResponse build() {
return new CompletionResponse(this);
}
}
public static class Choice {
private int index = 0;
@ -165,33 +157,48 @@ public class CompletionResponse {
}
}
public static class Usage {
private int prompt_tokens;
private int completion_tokens;
private int total_tokens;
public static ChoiceBuilder choiceBuilder() {
return new ChoiceBuilder();
}
public int getPrompt_tokens() {
return prompt_tokens;
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 void setPrompt_tokens(int prompt_tokens) {
this.prompt_tokens = prompt_tokens;
public ChoiceBuilder role(Role role) {
this.role = role;
return this;
}
public int getCompletion_tokens() {
return completion_tokens;
public ChoiceBuilder content(String content) {
this.content = content;
return this;
}
public void setCompletion_tokens(int completion_tokens) {
this.completion_tokens = completion_tokens;
public ChoiceBuilder name(String name) {
this.name = name;
return this;
}
public int getTotal_tokens() {
return total_tokens;
public ChoiceBuilder finish_reason(String finish_reason) {
this.finish_reason = finish_reason;
return this;
}
public void setTotal_tokens(int total_tokens) {
this.total_tokens = total_tokens;
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;
}
}
}

@ -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 - OpenAIAPI
*
* @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;

@ -1,4 +1,4 @@
package xyz.wbsite.achat.core.message;
package xyz.wbsite.achat.core.chat;
/**
*

@ -1,7 +1,6 @@
package xyz.wbsite.achat.core.message;
package xyz.wbsite.achat.core.chat;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import xyz.wbsite.achat.core.chat.ChatCompletionRequest;
import xyz.wbsite.achat.core.service.ChatCompletionGenerator;
import java.util.concurrent.ExecutorService;
@ -69,7 +68,6 @@ public class StreamEmitter extends SseEmitter {
}
}
// 静态builder方法返回Builder实例
public static Builder builder() {
return new Builder();
}
@ -95,7 +93,6 @@ public class StreamEmitter extends SseEmitter {
}
}
// 保留原有的构造函数以保持向后兼容
public StreamEmitter(ChatCompletionRequest chatCompletionRequest, ChatCompletionGenerator chatCompletionGenerator) {
super(Long.MAX_VALUE);
this.chatCompletionRequest = chatCompletionRequest;

@ -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;
// }
//}

@ -1,6 +1,6 @@
//package xyz.wbsite.achat.core.prompt;
//
//import xyz.wbsite.achat.core.message.Message;
//import xyz.wbsite.achat.core.chat.Message;
//import xyz.wbsite.achat.core.Prompt;
//import xyz.wbsite.achat.core.message.UserMessage;
//

@ -1,7 +1,7 @@
package xyz.wbsite.achat.core.service;
import xyz.wbsite.achat.core.chat.ChatCompletionRequest;
import xyz.wbsite.achat.core.message.StreamEmitter;
import xyz.wbsite.achat.core.chat.StreamEmitter;
/**
*

@ -4,7 +4,9 @@ import xyz.wbsite.achat.core.chat.ChatCompletionRequest;
import xyz.wbsite.achat.core.chat.ChatCompletionResponse;
import xyz.wbsite.achat.core.chat.CompletionRequest;
import xyz.wbsite.achat.core.chat.CompletionResponse;
import xyz.wbsite.achat.core.message.StreamEmitter;
import xyz.wbsite.achat.core.chat.EmbeddingsRequest;
import xyz.wbsite.achat.core.chat.EmbeddingsResponse;
import xyz.wbsite.achat.core.chat.StreamEmitter;
public interface ChatService {
@ -13,4 +15,6 @@ public interface ChatService {
ChatCompletionResponse chat(ChatCompletionRequest request);
StreamEmitter streamChat(ChatCompletionRequest request);
EmbeddingsResponse embeddings(EmbeddingsRequest request);
}

@ -1,7 +1,7 @@
//package xyz.wbsite.achat.core.service;
//
//import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
//import xyz.wbsite.achat.core.message.Message;
//import xyz.wbsite.achat.core.chat.Message;
//import xyz.wbsite.achat.core.Result;
//import xyz.wbsite.achat.core.Session;
//import xyz.wbsite.achat.core.prompt.MessagePrompt;

@ -4,22 +4,20 @@ import xyz.wbsite.achat.core.chat.ChatCompletionRequest;
import xyz.wbsite.achat.core.chat.ChatCompletionResponse;
import xyz.wbsite.achat.core.chat.CompletionRequest;
import xyz.wbsite.achat.core.chat.CompletionResponse;
import xyz.wbsite.achat.core.message.Message;
import xyz.wbsite.achat.core.message.Role;
import xyz.wbsite.achat.core.message.StreamEmitter;
import xyz.wbsite.achat.core.chat.EmbeddingsRequest;
import xyz.wbsite.achat.core.chat.EmbeddingsResponse;
import xyz.wbsite.achat.core.chat.Role;
import xyz.wbsite.achat.core.chat.StreamEmitter;
import xyz.wbsite.achat.core.chat.Usage;
import xyz.wbsite.achat.core.service.ChatService;
import java.util.ArrayList;
import java.util.List;
public class ChatServiceSampleImpl implements ChatService {
@Override
public CompletionResponse prompt(CompletionRequest request) {
CompletionResponse response = new CompletionResponse();
response.setObject("chat.completion");
response.setCreated(System.currentTimeMillis() / 1000);
response.setModel(request.getModel());
// CompletionResponse response = new CompletionResponse();
// response.setObject("chat.completion");
// response.setCreated(System.currentTimeMillis() / 1000);
// response.setModel(request.getModel());
// List<Choice> choices = new ArrayList<>();
// choices.add(Choice.builder().index(0).message(Message.builder().role(Role.ASSISTANT).content("您好,我还没有接入AI,请接入后再试!").build()).finish_reason("stop").build());
// response.setChoices(choices);
@ -31,37 +29,41 @@ public class ChatServiceSampleImpl implements ChatService {
.created(System.currentTimeMillis() / 1000)
.model(request.getModel())
.withChoices(choices -> {
// Choice choice1 = new Choice();
CompletionResponse.Choice
choice1.setIndex(0);
choice1.setMessage(new Message());
choice1.setFinish_reason("stop");
choices.add(choice1);
Choice choice2 = new Choice();
choice2.setIndex(1);
choice2.setMessage(new Message());
choice2.setFinish_reason("stop");
choices.add(choice2);
choices.add(CompletionResponse.choiceBuilder()
.index(0)
.role(Role.ASSISTANT)
.content("您好,我还没有接入AI,请接入后再试!")
.finish_reason("stop").build());
})
.usage(CompletionResponse.UsageBuilder().prompt_tokens(10).completion_tokens(10).total_tokens(10).build())
.usage(Usage.builder()
.prompt_tokens(10)
.completion_tokens(10)
.total_tokens(10)
.build())
.build();
}
@Override
public ChatCompletionResponse chat(ChatCompletionRequest request) {
ChatCompletionResponse response = new ChatCompletionResponse();
response.setId("chatcmpl-" + System.currentTimeMillis());
response.setObject("chat.completion");
response.setCreated(System.currentTimeMillis() / 1000);
response.setModel(request.getModel());
List<Choice> choices = new ArrayList<>();
choices.add(Choice.builder().index(0).message(Message.builder().role(Role.ASSISTANT).content("您好,我还没有接入AI,请接入后再试!").build()).finish_reason("stop").build());
response.setChoices(choices);
response.setUsage(Usage.builder().prompt_tokens(10).completion_tokens(20).total_tokens(30).build());
return response;
return ChatCompletionResponse.builder()
.id("chatcmpl-" + System.currentTimeMillis())
.object("chat.completion")
.created(System.currentTimeMillis() / 1000)
.model(request.getModel())
.withChoices(choices -> {
choices.add(ChatCompletionResponse.choiceBuilder()
.index(0)
.role(Role.ASSISTANT)
.content("您好,我还没有接入AI,请接入后再试!")
.finish_reason("stop")
.build());
})
.usage(Usage.builder()
.prompt_tokens(10)
.completion_tokens(10)
.total_tokens(10)
.build())
.build();
}
@Override
@ -73,10 +75,12 @@ public class ChatServiceSampleImpl implements ChatService {
if (request.getMessages() == null || request.getMessages().isEmpty()) {
throw new IllegalArgumentException("消息不能为空");
}
return StreamEmitter.builder()
StreamEmitter streamEmitter = StreamEmitter.builder()
.chatCompletionRequest(request)
.build();
return streamEmitter;
// SseEmitter emitter = new SseEmitter(Long.MAX_VALUE);
// 在单独的线程中处理流式响应
// new Thread(() -> {
@ -107,4 +111,9 @@ public class ChatServiceSampleImpl implements ChatService {
//
// return emitter;
}
@Override
public EmbeddingsResponse embeddings(EmbeddingsRequest request) {
return null;
}
}

@ -3,7 +3,7 @@
//import org.springframework.stereotype.Service;
//import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
//import xyz.wbsite.achat.core.message.MessageSseEmitter;
//import xyz.wbsite.achat.core.message.Message;
//import xyz.wbsite.achat.core.chat.Message;
//import xyz.wbsite.achat.core.Result;
//import xyz.wbsite.achat.core.Session;
//import xyz.wbsite.achat.core.prompt.MessagePrompt;

Loading…
Cancel
Save

Powered by TurnKey Linux.