Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0ae8868

Browse filesBrowse files
committed
Add comments explaining the api object fields
1 parent 7c4739b commit 0ae8868
Copy full SHA for 0ae8868

File tree

Expand file treeCollapse file tree

7 files changed

+180
-0
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+180
-0
lines changed

‎openai-api/src/main/java/openai/OpenAiResponse.java

Copy file name to clipboardExpand all lines: openai-api/src/main/java/openai/OpenAiResponse.java
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@
44

55
import java.util.List;
66

7+
/**
8+
* A wrapper class to fit the OpenAI engine and search endpoints
9+
*/
710
@Data
811
public class OpenAiResponse<T> {
12+
/**
13+
* A list containing the actual results
14+
*/
915
public List<T> data;
16+
17+
/**
18+
* The type of object returned, should be "list"
19+
*/
1020
public String object;
1121
}

‎openai-api/src/main/java/openai/completion/CompletionChoice.java

Copy file name to clipboardExpand all lines: openai-api/src/main/java/openai/completion/CompletionChoice.java
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,26 @@
22

33
import lombok.Data;
44

5+
/**
6+
* A completion generated by GPT-3
7+
*
8+
* https://beta.openai.com/docs/api-reference/create-completion
9+
*/
510
@Data
611
public class CompletionChoice {
12+
/**
13+
* The generated text. Will include the prompt if {@link CompletionRequest#echo } is true
14+
*/
715
String text;
16+
17+
/**
18+
* This index of this completion in the returned list.
19+
*/
820
Integer index;
921
// todo add logprobs
22+
23+
/**
24+
* The reason why GPT-3 stopped generating, for example "length".
25+
*/
1026
String finish_reason;
1127
}

‎openai-api/src/main/java/openai/completion/CompletionRequest.java

Copy file name to clipboardExpand all lines: openai-api/src/main/java/openai/completion/CompletionRequest.java
+79Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,97 @@
44

55
import java.util.List;
66

7+
/**
8+
* A request for OpenAi to generate a predicted completion for a prompt.
9+
* All fields are nullable.
10+
*
11+
* Documentation taken from
12+
* https://beta.openai.com/docs/api-reference/create-completion
13+
*/
714
@Data
815
public class CompletionRequest {
16+
/**
17+
* An optional prompt to complete from
18+
*/
919
String prompt;
20+
21+
/**
22+
* The maximum number of tokens to generate.
23+
* Requests can use up to 2048 tokens shared between prompt and completion.
24+
* (One token is roughly 4 characters for normal English text)
25+
*/
1026
Integer maxTokens;
27+
28+
/**
29+
* What sampling temperature to use. Higher values means the model will take more risks.
30+
* Try 0.9 for more creative applications, and 0 (argmax sampling) for ones with a well-defined answer.
31+
*
32+
* We generally recommend using this or {@link top_p} but not both.
33+
*/
1134
Double temperature;
35+
36+
/**
37+
* An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of
38+
* the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are
39+
* considered.
40+
*
41+
* We generally recommend using this or {@link temperature} but not both.
42+
*/
1243
Double topP;
44+
45+
/**
46+
* How many completions to generate for each prompt.
47+
*
48+
* Because this parameter generates many completions, it can quickly consume your token quota.
49+
* Use carefully and ensure that you have reasonable settings for {@link max_tokens} and {@link stop}.
50+
*/
1351
Integer n;
52+
53+
/**
54+
* Whether to stream back partial progress.
55+
* If set, tokens will be sent as data-only server-sent events as they become available,
56+
* with the stream terminated by a data: DONE message.
57+
*/
1458
Boolean stream;
59+
60+
/**
61+
* Include the log probabilities on the logprobs most likely tokens, as well the chosen tokens.
62+
* For example, if logprobs is 10, the API will return a list of the 10 most likely tokens.
63+
* The API will always return the logprob of the sampled token,
64+
* so there may be up to logprobs+1 elements in the response.
65+
*/
1566
Integer logprobs;
67+
68+
/**
69+
* Echo back the prompt in addition to the completion
70+
*/
1671
Boolean echo;
72+
73+
/**
74+
* Up to 4 sequences where the API will stop generating further tokens.
75+
* The returned text will not contain the stop sequence.
76+
*/
1777
List<String> stop; //todo test this
78+
79+
/**
80+
* Number between 0 and 1 (default 0) that penalizes new tokens based on whether they appear in the text so far.
81+
* Increases the model's likelihood to talk about new topics.
82+
*/
1883
Double presencePenalty;
84+
85+
/**
86+
* Number between 0 and 1 (default 0) that penalizes new tokens based on their existing frequency in the text so far.
87+
* Decreases the model's likelihood to repeat the same line verbatim.
88+
*/
1989
Double frequencyPenalty;
90+
91+
/**
92+
* Generates best_of completions server-side and returns the "best"
93+
* (the one with the lowest log probability per token).
94+
* Results cannot be streamed.
95+
*
96+
* When used with {@link n}, best_of controls the number of candidate completions and n specifies how many to return,
97+
* best_of must be greater than n.
98+
*/
2099
Integer bestOf;
21100
}

‎openai-api/src/main/java/openai/completion/CompletionResult.java

Copy file name to clipboardExpand all lines: openai-api/src/main/java/openai/completion/CompletionResult.java
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,35 @@
44

55
import java.util.List;
66

7+
/**
8+
* An object containing a response from the completion api
9+
*
10+
* https://beta.openai.com/docs/api-reference/create-completion
11+
*/
712
@Data
813
public class CompletionResult {
14+
/**
15+
* A unique id assigned to this completion
16+
*/
917
String id;
18+
19+
/**
20+
* The type of object returned, should be "text_completion"
21+
*/
1022
String object;
23+
24+
/**
25+
* The creation time in epoch milliseconds.
26+
*/
1127
long created;
28+
29+
/**
30+
* The GPT-3 model used
31+
*/
1232
String model;
33+
34+
/**
35+
* A list of generated completions
36+
*/
1337
List<CompletionChoice> choices;
1438
}

‎openai-api/src/main/java/openai/engine/Engine.java

Copy file name to clipboardExpand all lines: openai-api/src/main/java/openai/engine/Engine.java
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,30 @@
22

33
import lombok.Data;
44

5+
/**
6+
* GPT-3 engine details
7+
*
8+
* https://beta.openai.com/docs/api-reference/retrieve-engine
9+
*/
510
@Data
611
public class Engine {
12+
/**
13+
* An identifier for this engine, used to specify an engine for completions or searching.
14+
*/
715
public String id;
16+
17+
/**
18+
* The type of object returned, should be "engine"
19+
*/
820
public String object;
21+
22+
/**
23+
* The owner of the GPT-3 engine, typically "openai"
24+
*/
925
public String owner;
26+
27+
/**
28+
* Whether the engine is ready to process requests or not
29+
*/
1030
public boolean ready;
1131
}

‎openai-api/src/main/java/openai/search/SearchRequest.java

Copy file name to clipboardExpand all lines: openai-api/src/main/java/openai/search/SearchRequest.java
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,22 @@
44

55
import java.util.List;
66

7+
/**
8+
* A request to the document search api.
9+
* GPT-3 will perform a semantic search over the documents and score them based on how related they are to the query.
10+
* Higher scores indicate a stronger relation.
11+
*
12+
* https://beta.openai.com/docs/api-reference/search
13+
*/
714
@Data
815
public class SearchRequest {
16+
/**
17+
* Documents to search over
18+
*/
919
List<String> documents;
20+
21+
/**
22+
* Search query
23+
*/
1024
String query;
1125
}

‎openai-api/src/main/java/openai/search/SearchResult.java

Copy file name to clipboardExpand all lines: openai-api/src/main/java/openai/search/SearchResult.java
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,26 @@
22

33
import lombok.Data;
44

5+
/**
6+
* A search result for a single document.
7+
*
8+
* https://beta.openai.com/docs/api-reference/search
9+
*/
510
@Data
611
public class SearchResult {
12+
/**
13+
* The position of this document in the request list
14+
*/
715
Integer document;
16+
17+
/**
18+
* The type of object returned, should be "search_result"
19+
*/
820
String object;
21+
22+
/**
23+
* A number measuring the document's correlation with the query.
24+
* A higher score means a stronger relationship.
25+
*/
926
Double score;
1027
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.