Skip to content

Commit

Permalink
- 1.9.5
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiteMagic2014 committed Apr 29, 2024
1 parent 1697e37 commit 9754c5c
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ new CreateChatCompletionRequest()

## Version

### 1.9.5

- Update: The CreateChatCompletionRequest now includes a new method, sendForResponse, which returns a
CreateChatCompletionResponse. This object not only contains the choice list returned by the sendForChoices method, but
also includes additional information such as the token usage for this request.

### 1.9.4

- Update models in GptModel. (0125 -> gpt-4-turbo-2024-04-09)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<url>https://github.com/WhiteMagic2014/gpt-magic.git</url>
<groupId>io.github.whitemagic2014</groupId>
<artifactId>gpt-magic</artifactId>
<version>1.9.4</version>
<version>1.9.5</version>

<developers>
<developer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.alibaba.fastjson.JSONObject;
import com.github.WhiteMagic2014.gptApi.Chat.pojo.ChatCompletionChoice;
import com.github.WhiteMagic2014.gptApi.Chat.pojo.ChatMessage;
import com.github.WhiteMagic2014.gptApi.Chat.pojo.CreateChatCompletionResponse;
import com.github.WhiteMagic2014.gptApi.GptModel;
import com.github.WhiteMagic2014.gptApi.GptRequest;
import com.github.WhiteMagic2014.tool.FunctionTool;
Expand Down Expand Up @@ -350,4 +351,10 @@ public List<ChatCompletionChoice> sendForChoices() {
return JSON.parseArray(data.toJSONString(), ChatCompletionChoice.class);
}

public CreateChatCompletionResponse sendForResponse() {
if (stream) {
throw new RuntimeException("If the 'stream' field is true, you need to set an OutputStream to receive the returned stream.Please use the send method");
}
return JSON.parseObject(send().toJSONString(), CreateChatCompletionResponse.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.github.WhiteMagic2014.gptApi.Chat.pojo;

import java.util.Date;
import java.util.List;

/**
* @Description: CreateChatCompletionResponse
* @author: magic chen
* @date: 2024/4/29 16:44
**/
public class CreateChatCompletionResponse {

private Date created;

private Usage usage;

private String model;

private String id;

private List<ChatCompletionChoice> choices;

private String systemFingerprint;

private String object;

public Date getCreated() {
return created;
}

public void setCreated(Date created) {
this.created = created;
}

public Usage getUsage() {
return usage;
}

public void setUsage(Usage usage) {
this.usage = usage;
}

public String getModel() {
return model;
}

public void setModel(String model) {
this.model = model;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public List<ChatCompletionChoice> getChoices() {
return choices;
}

public void setChoices(List<ChatCompletionChoice> choices) {
this.choices = choices;
}

public String getSystemFingerprint() {
return systemFingerprint;
}

public void setSystemFingerprint(String systemFingerprint) {
this.systemFingerprint = systemFingerprint;
}

public String getObject() {
return object;
}

public void setObject(String object) {
this.object = object;
}

@Override
public String toString() {
return "CreateChatCompletionResponse{" +
"created=" + created +
", usage=" + usage +
", model='" + model + '\'' +
", id='" + id + '\'' +
", choices=" + choices +
", systemFingerprint='" + systemFingerprint + '\'' +
", object='" + object + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.github.WhiteMagic2014.gptApi.Chat.pojo;

/**
* @Description: token usage
* @author: magic chen
* @date: 2024/4/29 16:49
**/
public class Usage {

private Long promptTokens;

private Long completionTokens;

private Long totalTokens;

public Long getPromptTokens() {
return promptTokens;
}

public void setPromptTokens(Long promptTokens) {
this.promptTokens = promptTokens;
}

public Long getCompletionTokens() {
return completionTokens;
}

public void setCompletionTokens(Long completionTokens) {
this.completionTokens = completionTokens;
}

public Long getTotalTokens() {
return totalTokens;
}

public void setTotalTokens(Long totalTokens) {
this.totalTokens = totalTokens;
}

@Override
public String toString() {
return "Usage{" +
"promptTokens=" + promptTokens +
", completionTokens=" + completionTokens +
", totalTokens=" + totalTokens +
'}';
}
}

0 comments on commit 9754c5c

Please sign in to comment.