Skip to content

Commit

Permalink
- Optimize: Add GptModel.class list some available models for request…
Browse files Browse the repository at this point in the history
…; You can choose models instead of type the model name。
  • Loading branch information
WhiteMagic2014 committed Mar 15, 2023
1 parent 41e2f91 commit aa8f781
Show file tree
Hide file tree
Showing 11 changed files with 189 additions and 15 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,15 @@ String key = "sk-your key";
### 1.3
- New: chat apis
- New: audio apis
### 1.3.1
- Optimize: Add GptModel.class list some available models for request; You can choose models instead of type the model name。
```
version before 1.3.1
new CreateCompletionRequest().model("text-davinci-003");
version after 1.3.1
new CreateCompletionRequest().model(GptModel.text_davinci_003);
```

## License
This project is an open-sourced software licensed under the [MIT license](LICENSE).
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.3</version>
<version>1.3.1</version>

<developers>
<developer>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.WhiteMagic2014.gptApi.Audio;

import com.github.WhiteMagic2014.gptApi.GptModel;
import com.github.WhiteMagic2014.gptApi.GptRequest;
import com.github.WhiteMagic2014.util.GptHttpUtil;

Expand Down Expand Up @@ -46,9 +47,9 @@ public CreateTranscriptionRequest file(File file) {

/**
* Required
* ID of the model to use. Only whisper-1 is currently available.
* ID of the model to use.
*/
private String model = "whisper-1";
private String model = GptModel.whisper_1;

public CreateTranscriptionRequest model(String model) {
this.model = model;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.WhiteMagic2014.gptApi.Audio;

import com.github.WhiteMagic2014.gptApi.GptModel;
import com.github.WhiteMagic2014.gptApi.GptRequest;
import com.github.WhiteMagic2014.util.GptHttpUtil;

Expand Down Expand Up @@ -46,9 +47,9 @@ public CreateTranslationRequest file(File file) {

/**
* Required
* ID of the model to use. Only whisper-1 is currently available.
* ID of the model to use.
*/
private String model = "whisper-1";
private String model = GptModel.whisper_1;

public CreateTranslationRequest model(String model) {
this.model = model;
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.GptModel;
import com.github.WhiteMagic2014.gptApi.GptRequest;
import com.github.WhiteMagic2014.util.GptHttpUtil;

Expand Down Expand Up @@ -43,9 +44,8 @@ public CreateChatCompletionRequest organization(String organization) {
/**
* Required
* ID of the model to use.
* Currently, only gpt-3.5-turbo and gpt-3.5-turbo-0301 are supported.
*/
private String model = "gpt-3.5-turbo";
private String model = GptModel.gpt_3p5_turbo;

public CreateChatCompletionRequest model(String model) {
this.model = model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.WhiteMagic2014.gptApi.Completions.pojo.CompletionChoice;
import com.github.WhiteMagic2014.gptApi.GptModel;
import com.github.WhiteMagic2014.gptApi.GptRequest;
import com.github.WhiteMagic2014.util.GptHttpUtil;

import java.util.List;

/**
* Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.
*
* @Description: Creates a completion for the provided prompt and parameters
* @author: magic chen
* @date: 2023/2/22 17:52
Expand Down Expand Up @@ -42,7 +44,7 @@ public CreateCompletionRequest organization(String organization) {
* ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them.
* https://platform.openai.com/docs/models/overview
*/
private String model = "text-davinci-003";
private String model = GptModel.text_davinci_003;

public CreateCompletionRequest model(String model) {
this.model = model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.WhiteMagic2014.gptApi.Edits.pojo.EditChoice;
import com.github.WhiteMagic2014.gptApi.GptModel;
import com.github.WhiteMagic2014.gptApi.GptRequest;
import com.github.WhiteMagic2014.util.GptHttpUtil;

Expand Down Expand Up @@ -39,9 +40,9 @@ public CreateEditRequest organization(String organization) {
// params
/**
* Required
* ID of the model to use. You can use the text-davinci-edit-001 or code-davinci-edit-001 model with this endpoint.
* ID of the model to use.
*/
private String model = "text-davinci-edit-001";// or code-davinci-edit-001
private String model = GptModel.text_davinci_edit_001;

public CreateEditRequest model(String model) {
this.model = model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.WhiteMagic2014.gptApi.GptModel;
import com.github.WhiteMagic2014.gptApi.GptRequest;
import com.github.WhiteMagic2014.util.GptHttpUtil;

Expand Down Expand Up @@ -43,7 +44,7 @@ public CreateEmbeddingsRequest organization(String organization) {
* ID of the model to use. You can use the List models API to see all of your available models, or see our Model overview for descriptions of them.
* https://platform.openai.com/docs/models/overview
*/
private String model = "text-embedding-ada-002";
private String model = GptModel.text_embedding_ada_002;

public CreateEmbeddingsRequest model(String model) {
this.model = model;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.WhiteMagic2014.gptApi.FineTunes;

import com.alibaba.fastjson.JSONObject;
import com.github.WhiteMagic2014.gptApi.GptModel;
import com.github.WhiteMagic2014.gptApi.GptRequest;
import com.github.WhiteMagic2014.util.GptHttpUtil;

Expand Down Expand Up @@ -68,7 +69,7 @@ public CreateFineTuneRequest validationFile(String validationFile) {
* To learn more about these models, see the Models documentation.
* https://platform.openai.com/docs/models
*/
private String model = "curie";
private String model = GptModel.ada;

public CreateFineTuneRequest model(String model) {
this.model = model;
Expand Down
152 changes: 152 additions & 0 deletions src/main/java/com/github/WhiteMagic2014/gptApi/GptModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package com.github.WhiteMagic2014.gptApi;

/**
* @Description: some models
* @author: magic chen
* @date: 2023/3/15 11:09
* https://platform.openai.com/docs/models/model-endpoint-compatibility
**/
public class GptModel {


/**
* Models for CreateChatCompletionRequest
*/
/**
* More capable than any GPT-3.5 model, able to do more complex tasks, and optimized for chat. Will be updated with our latest model iteration.
* 8192 max tokens
*/
public final static String gpt4 = "gpt-4";

/**
* Snapshot of gpt-4 from March 14th 2023. Unlike gpt-4, this model will not receive updates, and will only be supported for a three month period ending on June 14th 2023.
* 8192 max tokens
*/
public final static String gpt_4_0314 = "gpt-4-0314";

/**
* Same capabilities as the base gpt-4 mode but with 4x the context length. Will be updated with our latest model iteration.
* 32768 max tokens
*/
public final static String gpt_4_32k = "gpt-4-32k";

/**
* Snapshot of gpt-4-32 from March 14th 2023. Unlike gpt-4-32k, this model will not receive updates, and will only be supported for a three month period ending on June 14th 2023.
* 32768 max tokens
*/
public final static String gpt_4_32k_0314 = "gpt-4-32k-0314";

/**
* Most capable GPT-3.5 model and optimized for chat at 1/10th the cost of text-davinci-003. Will be updated with our latest model iteration.
* 4096 max tokens
*/
public final static String gpt_3p5_turbo = "gpt-3.5-turbo";

/**
* Snapshot of gpt-3.5-turbo from March 1st 2023. Unlike gpt-3.5-turbo, this model will not receive updates, and will only be supported for a three month period ending on June 1st 2023.
* 4096 max tokens
*/
public final static String gpt_3p5_turbo_0301 = "gpt-3.5-turbo-0301";





/*
* Models for CreateCompletionRequest
*/
/**
* Can do any language task with better quality, longer output, and consistent instruction-following than the curie, babbage, or ada models. Also supports inserting completions within text.
* 4097 max tokens
*/
public final static String text_davinci_003 = "text-davinci-003";

/**
* Similar capabilities to text-davinci-003 but trained with supervised fine-tuning instead of reinforcement learning
* 4097 max tokens
*/
public final static String text_davinci_002 = "text-davinci-002";

/**
* Very capable, faster and lower cost than Davinci.
* 2049 max tokens
*/
public final static String text_curie_001 = "text-curie-001";

/**
* Capable of straightforward tasks, very fast, and lower cost.
* 2049 max tokens
*/
public final static String text_babbage_001 = "text-babbage-001";

/**
* Capable of very simple tasks, usually the fastest model in the GPT-3 series, and lowest cost.
* 2049 max tokens
*/
public final static String text_ada_001 = "text-ada-001";

/**
* Most capable GPT-3 model. Can do any task the other models can do, often with higher quality.
* 2049 max tokens
*/
public final static String davinci = "davinci";

/**
* Very capable, but faster and lower cost than Davinci.
* 2049 max tokens
*/
public final static String curie = "curie";

/**
* Capable of straightforward tasks, very fast, and lower cost.
* 2049 max tokens
*/
public final static String babbage = "babbage";

/**
* Capable of very simple tasks, usually the fastest model in the GPT-3 series, and lowest cost.
* 2049 max tokens
*/
public final static String ada = "ada";


/**
* Models for CreateEditRequest
*/
public final static String text_davinci_edit_001 = "text-davinci-edit-001";
public final static String code_davinci_edit_001 = "code-davinci-edit-001";


/**
* Models for CreateTranslationRequest and CreateTranscriptionRequest
* https://platform.openai.com/docs/models/whisper
*/
public final static String whisper_1 = "whisper-1";


/**
* Models for FileTunes
* davinci, curie, babbage, ada
*/

/**
* Models for CreateEmbeddingsRequest
* https://platform.openai.com/docs/models/embeddings
*/
public final static String text_embedding_ada_002 = "text-embedding-ada-002";
public final static String text_search_ada_doc_001 = "text-search-ada-doc-001";


/**
* Models for CreateModerationRequest
* https://platform.openai.com/docs/models/moderation
*/
/**
* Most capable moderation model. Accuracy will be slighlty higher than the stable model
*/
public final static String text_moderation_latest = "text-moderation-latest";
/**
* Almost as capable as the latest model, but slightly older.
*/
public final static String text_moderation_stable = "text-moderation-stable";
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.WhiteMagic2014.gptApi.GptModel;
import com.github.WhiteMagic2014.gptApi.GptRequest;
import com.github.WhiteMagic2014.gptApi.Moderations.pojo.ModerationCategory;
import com.github.WhiteMagic2014.util.GptHttpUtil;
Expand Down Expand Up @@ -65,18 +66,22 @@ public CreateModerationRequest inputs(String... inputs) {
* If you use text-moderation-stable, we will provide advanced notice before updating the model.
* Accuracy of text-moderation-stable may be slightly lower than for text-moderation-latest.
*/
private String model = "text-moderation-latest";
private String model = GptModel.text_moderation_latest;

public CreateModerationRequest modelLatest() {
this.model = "text-moderation-latest";
this.model = GptModel.text_moderation_latest;
return this;
}

public CreateModerationRequest modelStable() {
this.model = "text-moderation-stable";
this.model = GptModel.text_moderation_stable;
return this;
}

public CreateModerationRequest model(String model) {
this.model = model;
return this;
}

@Override
protected String sendHook() {
Expand Down

0 comments on commit aa8f781

Please sign in to comment.