Skip to content

Commit

Permalink
### 1.5.2
Browse files Browse the repository at this point in the history
- 升级gmp到1.9.7
- 支持batch相关api
- 优化 function模块下的 GmpFunction ,方法 handleToolMessage 中不再默认指定模型,而是使用 HandleResult 中指定的模型
- 调整 function模块下的 HandleResult ,使用builder的方式来创建对象,新增了gptModel来指定 使用的模型
  • Loading branch information
WhiteMagic2014 committed May 15, 2024
1 parent e385c2a commit 4271612
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 19 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ gpt-magic-plus-memory, 携带上下文且能够归纳对话作为记忆的chat

## Version

### 1.5.2

- 升级gmp到1.9.7
- 支持batch相关api
- 优化 function模块下的 GmpFunction ,方法 handleToolMessage 中不再默认指定模型,而是使用 HandleResult 中指定的模型
- 调整 function模块下的 HandleResult ,使用builder的方式来创建对象,新增了gptModel来指定 使用的模型

### 1.5.1

- 升级gmp到1.9.6,支持gpt-4o
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<url>https://github.com/WhiteMagic2014/gpt-magic-plus.git</url>
<groupId>io.github.whitemagic2014</groupId>
<artifactId>gpt-magic-plus</artifactId>
<version>1.5.1</version>
<version>1.5.2</version>

<developers>
<developer>
Expand Down Expand Up @@ -53,7 +53,7 @@
<dependency>
<groupId>io.github.whitemagic2014</groupId>
<artifactId>gpt-magic</artifactId>
<version>1.9.6</version>
<version>1.9.7</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public HandleResult handle(JSONObject arguments) {
} catch (Exception e) {
result = "很抱歉,作图的时候出了一点问题,可以稍后再次尝试";
}
return new HandleResult(true, result);
// 如果不需要额外处理
// HandleResult.builder().result(result).gptProcess(false).build();
return HandleResult.builder().result(result).gptProcess(true).gptModel(GptModel.gpt_4o).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.alibaba.fastjson.JSONObject;
import com.github.WhiteMagic2014.gptApi.Chat.CreateChatCompletionRequest;
import com.github.WhiteMagic2014.gptApi.Chat.pojo.ChatMessage;
import com.github.WhiteMagic2014.gptApi.GptModel;
import com.github.WhiteMagic2014.tool.FunctionTool;
import com.github.WhiteMagic2014.util.RequestUtil;

Expand Down Expand Up @@ -52,7 +51,7 @@ public String handleToolMessage(ChatMessage userMessage, ChatMessage assistantTe
if (handleResult.getGptProcess()) {
CreateChatCompletionRequest request = new CreateChatCompletionRequest()
.addTool(getFunctionTool())
.model(GptModel.gpt_4_function)
.model(handleResult.getGptModel())
.addMessage(userMessage)
.addMessage(assistantTempMessage)// gpt result
.addMessage(ChatMessage.toolMessage(callId, handleResult.getResult())); // send a function message with function_name and custom result
Expand Down
64 changes: 53 additions & 11 deletions src/main/java/com/github/WhiteMagic2014/function/HandleResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,79 @@ public class HandleResult {
*/
private Boolean gptProcess;

/**
* 如果需要gpt再次处理,指定所使用的gpt模型
*/
private String gptModel;

/**
* 内部处理结果
*/
private String result;

public HandleResult(Boolean gptProcess, String result) {
this.gptProcess = gptProcess;
this.result = result;

protected HandleResult(Builder builder) {
this.gptProcess = builder.gptProcess;
this.gptModel = builder.gptModel;
this.result = builder.result;
}

public Boolean getGptProcess() {
return gptProcess;
public static Builder builder() {
return new Builder();
}

public void setGptProcess(Boolean gptProcess) {
this.gptProcess = gptProcess;
public String getGptModel() {
return gptModel;
}

public String getResult() {
return result;
public Boolean getGptProcess() {
return gptProcess;
}

public void setResult(String result) {
this.result = result;
public String getResult() {
return result;
}

@Override
public String toString() {
return "HandleResult{" +
"gptProcess=" + gptProcess +
", gptModel='" + gptModel + '\'' +
", result='" + result + '\'' +
'}';
}


public static class Builder {
private Boolean gptProcess;
private String gptModel;
private String result;

public Builder() {
}

public Builder gptProcess(Boolean gptProcess) {
this.gptProcess = gptProcess;
return this;
}

public Builder gptModel(String gptModel) {
this.gptModel = gptModel;
return this;
}

public Builder result(String result) {
this.result = result;
return this;
}

public HandleResult build() {
if (gptProcess && (gptModel == null || gptModel.isEmpty())) {
throw new RuntimeException("gpt再次处理,请指定模型");
}
return new HandleResult(this);
}

}

}
6 changes: 3 additions & 3 deletions src/main/java/com/github/WhiteMagic2014/gmpm/GmpMemory.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
public class GmpMemory {

private String model = GptModel.gpt_3p5_turbo;
private String model = GptModel.gpt_4o;
private int maxTokens = 500;// 回答问题限制的 token数量
private boolean stream = false;// 是否使用流式请求
private float temperature = 1.0f; // 拘束 0~2 自由
Expand Down Expand Up @@ -128,7 +128,7 @@ private boolean check(String session, String prompt) {
}
sb.append("\nuser:").append(prompt);
String checkResult = originChat(Collections.singletonList(ChatMessage.userMessage(sb.toString())));
System.out.println("记忆联想:" + !checkResult.contains("不需要"));
// System.out.println("记忆联想:" + !checkResult.contains("不需要"));
return !checkResult.contains("不需要");
}

Expand All @@ -142,7 +142,7 @@ private boolean check(String session, String prompt) {
*/
public void addChatMemory(String session, String user, String assistant) {
String topic = originChat(Collections.singletonList(ChatMessage.userMessage("请概括以下user和assistant的对话:\n" + "user:\n" + user + "\nassistant:\n" + assistant)));
System.out.println("对话归纳:" + topic);
// System.out.println("对话归纳:" + topic);

ChatMemory memory = new ChatMemory();
memory.setUser(user);
Expand Down

0 comments on commit 4271612

Please sign in to comment.