mirror of
https://github.com/YuWanTingbb/unofficial-gpt4.git
synced 2025-10-13 13:45:06 +00:00
Revert "Update machineIdList.json"
This commit is contained in:
@@ -10,7 +10,6 @@ import com.gpt4.copilot.copilotApplication;
|
||||
import com.gpt4.copilot.pojo.Conversation;
|
||||
import com.gpt4.copilot.pojo.Result;
|
||||
import com.gpt4.copilot.pojo.SystemSetting;
|
||||
import com.unfbx.chatgpt.entity.chat.ChatCompletion;
|
||||
import com.unfbx.chatgpt.entity.chat.Message;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
@@ -471,7 +470,7 @@ public class ChatController {
|
||||
@PostMapping(value = "/v1/chat/completions")
|
||||
public ResponseEntity<Object> coPilotConversation(HttpServletResponse response,
|
||||
HttpServletRequest request,
|
||||
@org.springframework.web.bind.annotation.RequestBody ChatCompletion conversation) {
|
||||
@org.springframework.web.bind.annotation.RequestBody Conversation conversation) {
|
||||
String header = request.getHeader("Authorization");
|
||||
String authorizationHeader = (header != null && !header.trim().isEmpty()) ? header.trim() : null;
|
||||
// 异步处理
|
||||
@@ -530,7 +529,7 @@ public class ChatController {
|
||||
return getObjectResponseEntity(response, future);
|
||||
}
|
||||
|
||||
private String getRequestApikey(String authorizationHeader, @org.springframework.web.bind.annotation.RequestBody ChatCompletion conversation) {
|
||||
private String getRequestApikey(String authorizationHeader, @org.springframework.web.bind.annotation.RequestBody Conversation conversation) {
|
||||
checkConversation(conversation);
|
||||
String apiKey;
|
||||
if (authorizationHeader != null && authorizationHeader.startsWith("Bearer ")) {
|
||||
@@ -554,17 +553,16 @@ public class ChatController {
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
private String modelAdjust(ChatCompletion conversation) {
|
||||
private String modelAdjust(Conversation conversation) {
|
||||
String model = conversation.getModel();
|
||||
if (model == null) {
|
||||
conversation.setModel("gpt-3.5-turbo");
|
||||
return "gpt-3.5-turbo";
|
||||
String temModel;
|
||||
if (model == null || !model.startsWith("gpt-4")) {
|
||||
temModel = "gpt-3.5-turbo";
|
||||
} else {
|
||||
if (model.startsWith("gpt-4")) {
|
||||
conversation.setModel("gpt-4");
|
||||
}
|
||||
return model;
|
||||
temModel = "gpt-4";
|
||||
}
|
||||
conversation.setModel(temModel);
|
||||
return model;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -583,7 +581,7 @@ public class ChatController {
|
||||
@PostMapping(value = "/cocopilot/v1/chat/completions")
|
||||
public ResponseEntity<Object> coCoPilotConversation(HttpServletResponse response,
|
||||
HttpServletRequest request,
|
||||
@org.springframework.web.bind.annotation.RequestBody ChatCompletion conversation) {
|
||||
@org.springframework.web.bind.annotation.RequestBody Conversation conversation) {
|
||||
String header = request.getHeader("Authorization");
|
||||
String authorizationHeader = (header != null && !header.trim().isEmpty()) ? header.trim() : null;
|
||||
// 异步处理
|
||||
@@ -672,12 +670,12 @@ public class ChatController {
|
||||
* @param conversation
|
||||
* @throws IOException
|
||||
*/
|
||||
private String[] extractApiKeyAndRequestUrl(String authorizationHeader, ChatCompletion conversation) throws IllegalArgumentException {
|
||||
private String[] extractApiKeyAndRequestUrl(String authorizationHeader, Conversation conversation) throws IllegalArgumentException {
|
||||
checkConversation(conversation);
|
||||
return getApiKeyAndRequestUrl(authorizationHeader);
|
||||
}
|
||||
|
||||
private void checkConversation(ChatCompletion conversation) {
|
||||
private void checkConversation(Conversation conversation) {
|
||||
if (conversation == null) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Request body is missing or not in JSON format");
|
||||
}
|
||||
@@ -744,7 +742,7 @@ public class ChatController {
|
||||
@PostMapping(value = "/self/v1/chat/completions")
|
||||
public ResponseEntity<Object> selfConversation(HttpServletResponse response,
|
||||
HttpServletRequest request,
|
||||
@org.springframework.web.bind.annotation.RequestBody ChatCompletion conversation) {
|
||||
@org.springframework.web.bind.annotation.RequestBody Conversation conversation) {
|
||||
String header = request.getHeader("Authorization");
|
||||
String authorizationHeader = (header != null && !header.trim().isEmpty()) ? header.trim() : null;
|
||||
// 异步处理
|
||||
@@ -816,7 +814,7 @@ public class ChatController {
|
||||
* @return
|
||||
*/
|
||||
public Object againConversation(HttpServletResponse response,
|
||||
@org.springframework.web.bind.annotation.RequestBody ChatCompletion conversation,
|
||||
@org.springframework.web.bind.annotation.RequestBody Conversation conversation,
|
||||
String token,
|
||||
String apiKey,
|
||||
String model) {
|
||||
@@ -839,22 +837,14 @@ public class ChatController {
|
||||
}
|
||||
}
|
||||
|
||||
private Request getPrompt(@org.springframework.web.bind.annotation.RequestBody ChatCompletion conversation, String model, Map<String, String> headersMap) {
|
||||
private Request getPrompt(@org.springframework.web.bind.annotation.RequestBody Conversation conversation, String model, Map<String, String> headersMap) {
|
||||
try {
|
||||
if (model.startsWith("gpt-4") && systemSetting.getGpt4_prompt()) {
|
||||
Message newMessage = getStringStringMap(model);
|
||||
conversation.getMessages().add(0, newMessage);
|
||||
|
||||
log.info("gpt-4模型,添加系统消息注入!");
|
||||
log.info(model + "模型,添加系统消息注入!");
|
||||
}
|
||||
|
||||
// 创建符合 github copilot 的请求体
|
||||
Conversation newConversation = new Conversation();
|
||||
newConversation.setStream(conversation.isStream());
|
||||
newConversation.setModel(conversation.getModel());
|
||||
newConversation.setMessages(conversation.getMessages());
|
||||
|
||||
String json = com.alibaba.fastjson2.JSON.toJSONString(newConversation);
|
||||
String json = com.alibaba.fastjson2.JSON.toJSONString(conversation);
|
||||
RequestBody requestBody = RequestBody.create(json, JSON);
|
||||
Request.Builder requestBuilder = new Request.Builder().url(github_chat_url).post(requestBody);
|
||||
headersMap.forEach(requestBuilder::addHeader);
|
||||
@@ -1273,7 +1263,7 @@ public class ChatController {
|
||||
* @param resp
|
||||
* @param conversation
|
||||
*/
|
||||
private void outPutChat(HttpServletResponse response, Response resp, ChatCompletion conversation, String model) {
|
||||
private void outPutChat(HttpServletResponse response, Response resp, Conversation conversation, String model) {
|
||||
try {
|
||||
boolean isStream = conversation.isStream();
|
||||
int sleep_time = calculateSleepTime(model, isStream);
|
||||
|
@@ -1,26 +1,56 @@
|
||||
package com.gpt4.copilot.pojo;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.unfbx.chatgpt.entity.chat.Message;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import com.unfbx.chatgpt.utils.TikTokensUtil;
|
||||
import lombok.*;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author YANGYANG
|
||||
* 描述: chat模型参数
|
||||
*
|
||||
* @author https:www.unfbx.com
|
||||
* 2023-03-02
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@SuperBuilder
|
||||
@Slf4j
|
||||
@NoArgsConstructor
|
||||
public class Conversation {
|
||||
@AllArgsConstructor
|
||||
public class Conversation implements Serializable {
|
||||
|
||||
private String model;
|
||||
/**
|
||||
* 是否流式输出.
|
||||
* default:false
|
||||
*
|
||||
* @see com.unfbx.chatgpt.OpenAiStreamClient
|
||||
*/
|
||||
@Builder.Default
|
||||
private boolean stream = false;
|
||||
|
||||
/**
|
||||
* 问题描述
|
||||
*/
|
||||
@NonNull
|
||||
private List<Message> messages;
|
||||
|
||||
private Boolean stream;
|
||||
/**
|
||||
* 获取当前参数的tokens数
|
||||
*/
|
||||
public long tokens() {
|
||||
if (CollectionUtil.isEmpty(this.messages) || StrUtil.isBlank(this.getModel())) {
|
||||
log.warn("参数异常model:{},prompt:{}", this.getModel(), this.messages);
|
||||
return 0;
|
||||
}
|
||||
String temModel = this.getModel() == null || !model.startsWith("gpt-4") ? "gpt-3.5-turbo" :"gpt-4-0613";
|
||||
return TikTokensUtil.tokens(temModel, this.messages);
|
||||
}
|
||||
|
||||
}
|
||||
@Builder.Default
|
||||
private String model = "gpt-3.5-turbo";
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,11 +1,12 @@
|
||||
com\gpt4\copilot\controller\ChatController.class
|
||||
com\gpt4\copilot\config\CorsConfig.class
|
||||
com\gpt4\copilot\pojo\Conversation$ConversationBuilderImpl.class
|
||||
com\gpt4\copilot\copilotApplication.class
|
||||
com\gpt4\copilot\controller\ChatController$1.class
|
||||
com\gpt4\copilot\pojo\Conversation$ConversationBuilder.class
|
||||
com\gpt4\copilot\config\WebConfig.class
|
||||
com\gpt4\copilot\controller\ChatController.class
|
||||
com\gpt4\copilot\controller\CustomErrorController.class
|
||||
com\gpt4\copilot\pojo\Conversation.class
|
||||
com\gpt4\copilot\pojo\SystemSetting.class
|
||||
com\gpt4\copilot\config\CorsConfig.class
|
||||
com\gpt4\copilot\pojo\Result.class
|
||||
com\gpt4\copilot\controller\ChatController$2.class
|
||||
com\gpt4\copilot\copilotApplication.class
|
||||
|
Reference in New Issue
Block a user