Skip to content

Commit

Permalink
- Optimize:Now, with the use of System.setProperty, you can easily se…
Browse files Browse the repository at this point in the history
…t properties without the need to manually set them each time a request is created.
  • Loading branch information
WhiteMagic2014 committed Jun 16, 2023
1 parent c2afd7d commit f16074b
Show file tree
Hide file tree
Showing 27 changed files with 31 additions and 50 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ String key = "sk-your key";

## Version

### 1.6.1

- Optimize:Now, with the use of System.setProperty, you can easily set properties without the need to manually set them each time a request is created.
```
Explicitly setting in the request > Setting with System.setProperty > System default value.
System.setProperty("OPENAI_API_KEY",""); // no system default value
System.setProperty("OPENAI_API_ORG","");// no system default value
System.setProperty("OPENAI_API_SERVER",""); // default = https://api.openai.com
```

### 1.6.0

- new: The CreateChatCompletionRequest function can now call other functions. For more information on how to call
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.6.0</version>
<version>1.6.1</version>

<developers>
<developer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
public class CreateTranscriptionRequest extends GptRequest {


private String server = "https://api.openai.com";

public CreateTranscriptionRequest server(String server) {
this.server = server;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
import java.util.Map;

/**
* @Description: Translates audio into into English.
* @Description: Translates audio into English.
* @author: magic chen
* @date: 2023/3/2 11:57
* https://platform.openai.com/docs/api-reference/audio/create
**/
public class CreateTranslationRequest extends GptRequest {


private String server = "https://api.openai.com";

public CreateTranslationRequest server(String server) {
this.server = server;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
**/
public class CreateChatCompletionRequest extends GptRequest {

private String server = "https://api.openai.com";

public CreateChatCompletionRequest server(String server) {
this.server = server;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
public class CreateCompletionRequest extends GptRequest {


private String server = "https://api.openai.com";

public CreateCompletionRequest server(String server) {
this.server = server;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
public class CreateEditRequest extends GptRequest {


private String server = "https://api.openai.com";

public CreateEditRequest server(String server) {
this.server = server;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
**/
public class CreateEmbeddingsRequest extends GptRequest {

private String server = "https://api.openai.com";

public CreateEmbeddingsRequest server(String server) {
this.server = server;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
public class DeleteFileRequest extends GptRequest {


private String server = "https://api.openai.com";

public DeleteFileRequest server(String server) {
this.server = server;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
public class ListFilesRequest extends GptRequest {


private String server = "https://api.openai.com";

public ListFilesRequest server(String server) {
this.server = server;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
**/
public class RetrieveFileContentRequest extends GptRequest {

private String server = "https://api.openai.com";

public RetrieveFileContentRequest server(String server) {
this.server = server;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
**/
public class RetrieveFileRequest extends GptRequest {

private String server = "https://api.openai.com";

public RetrieveFileRequest server(String server) {
this.server = server;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
**/
public class UploadFileRequest extends GptRequest {

private String server = "https://api.openai.com";

public UploadFileRequest server(String server) {
this.server = server;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
**/
public class CancelFineTuneRequest extends GptRequest {


private String server = "https://api.openai.com";

public CancelFineTuneRequest server(String server) {
this.server = server;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
**/
public class CreateFineTuneRequest extends GptRequest {

private String server = "https://api.openai.com";

public CreateFineTuneRequest server(String server) {
this.server = server;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
**/
public class DeleteFineTuneModelRequest extends GptRequest {

private String server = "https://api.openai.com";

public DeleteFineTuneModelRequest server(String server) {
this.server = server;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
**/
public class ListFineTuneEventsRequest extends GptRequest {

private String server = "https://api.openai.com";

public ListFineTuneEventsRequest server(String server) {
this.server = server;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
**/
public class ListFineTunesRequest extends GptRequest {

private String server = "https://api.openai.com";

public ListFineTunesRequest server(String server) {
this.server = server;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
**/
public class RetrieveFineTuneRequest extends GptRequest {

private String server = "https://api.openai.com";

public RetrieveFineTuneRequest server(String server) {
this.server = server;
return this;
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/github/WhiteMagic2014/gptApi/GptModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ public class GptModel {
*/
public final static String gpt_3p5_turbo_16k = "gpt-3.5-turbo-16k";


/**
* 16k tokens and function calling
*/
public final static String gpt_3p5_turbo_16k_0613 = "gpt-3.5-turbo-16k-0613";

/*
* Models for CreateCompletionRequest
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/com/github/WhiteMagic2014/gptApi/GptRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
**/
public abstract class GptRequest {

/**
* default server
*/
protected String server = System.getProperty("OPENAI_API_SERVER", "https://api.openai.com");

/**
* Required
* OpenAI key, Use api need your key
Expand All @@ -32,8 +37,15 @@ public JSONObject send() {
if (gptHttpUtil == null) {
throw new RuntimeException("missing GptHttpUtil");
}
if (key == null) {
throw new RuntimeException("missing GptKey");
if (key == null || "".equals(key.trim())) {
String keySetting = System.getProperty("OPENAI_API_KEY");
if (keySetting == null || "".equals(keySetting.trim())) {
throw new RuntimeException("missing GptKey");
}
key = keySetting;
}
if (org == null) {
org = System.getProperty("OPENAI_API_ORG");
}
String resp = sendHook();
if (resp == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
**/
public class CreateImageEditRequest extends GptRequest {

private String server = "https://api.openai.com";

public CreateImageEditRequest server(String server) {
this.server = server;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
**/
public class CreateImageRequest extends GptRequest {

private String server = "https://api.openai.com";

public CreateImageRequest server(String server) {
this.server = server;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
**/
public class CreateImageVariationRequest extends GptRequest {

private String server = "https://api.openai.com";

public CreateImageVariationRequest server(String server) {
this.server = server;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
**/
public class ListModelsRequest extends GptRequest {

private String server = "https://api.openai.com";

public ListModelsRequest server(String server) {
this.server = server;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
**/
public class RetrieveModelRequest extends GptRequest {

private String server = "https://api.openai.com";

public RetrieveModelRequest server(String server) {
this.server = server;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
**/
public class CreateModerationRequest extends GptRequest {

private String server = "https://api.openai.com";

public CreateModerationRequest server(String server) {
this.server = server;
return this;
Expand Down

0 comments on commit f16074b

Please sign in to comment.