File tree Expand file tree Collapse file tree 4 files changed +29
-11
lines changed
Filter options
example/src/main/java/example Expand file tree Collapse file tree 4 files changed +29
-11
lines changed
Original file line number Diff line number Diff line change 2
2
Java libraries for using OpenAI's GPT-3 api.
3
3
4
4
Includes the following artifacts:
5
- - api : request/response POJOs for the GPT-3 engine, completion, and search APIs.
6
- - client : a basic retrofit client for the GPT-3 endpoints
5
+ - ` api ` : request/response POJOs for the GPT-3 engine, completion, and search APIs.
6
+ - ` client ` : a basic retrofit client for the GPT-3 endpoints
7
7
8
8
as well as an example project using the client.
9
9
@@ -12,9 +12,10 @@ as well as an example project using the client.
12
12
If you're looking for the fastest solution, import the ` client ` and use [ OpenAiService] ( client/src/main/java/openai/OpenAiService.java ) .
13
13
```
14
14
OpenAiService service = new OpenAiService(your_token)
15
- CompletionRequest completionRequest = new CompletionRequest();
16
- completionRequest.setPrompt("Somebody once told me the world is gonna roll me");
17
- completionRequest.setEcho(true);
15
+ CompletionRequest completionRequest = CompletionRequest.builder()
16
+ .prompt("Somebody once told me the world is gonna roll me")
17
+ .echo(true)
18
+ .build();
18
19
service.createCompletion("ada", completionRequest).getChoices().forEach(System.out::println);
19
20
```
20
21
Original file line number Diff line number Diff line change 1
1
package openai .completion ;
2
2
3
+ import lombok .AllArgsConstructor ;
4
+ import lombok .Builder ;
3
5
import lombok .Data ;
6
+ import lombok .NoArgsConstructor ;
4
7
5
8
import java .util .List ;
6
9
11
14
* Documentation taken from
12
15
* https://beta.openai.com/docs/api-reference/create-completion
13
16
*/
17
+ @ Builder
18
+ @ NoArgsConstructor
19
+ @ AllArgsConstructor
14
20
@ Data
15
21
public class CompletionRequest {
22
+
16
23
/**
17
24
* An optional prompt to complete from
18
25
*/
Original file line number Diff line number Diff line change 1
1
package openai .search ;
2
2
3
+ import lombok .AllArgsConstructor ;
4
+ import lombok .Builder ;
3
5
import lombok .Data ;
6
+ import lombok .NoArgsConstructor ;
4
7
5
8
import java .util .List ;
6
9
11
14
*
12
15
* https://beta.openai.com/docs/api-reference/search
13
16
*/
17
+ @ Builder
18
+ @ NoArgsConstructor
19
+ @ AllArgsConstructor
14
20
@ Data
15
21
public class SearchRequest {
22
+
16
23
/**
17
24
* Documents to search over
18
25
*/
Original file line number Diff line number Diff line change @@ -20,15 +20,18 @@ public static void main(String... args) {
20
20
System .out .println (ada );
21
21
22
22
System .out .println ("\n Creating completion..." );
23
- CompletionRequest completionRequest = new CompletionRequest ();
24
- completionRequest .setPrompt ("Somebody once told me the world is gonna roll me" );
25
- completionRequest .setEcho (true );
23
+
24
+ CompletionRequest completionRequest = CompletionRequest .builder ()
25
+ .prompt ("Somebody once told me the world is gonna roll me" )
26
+ .echo (true )
27
+ .build ();
26
28
service .createCompletion ("ada" , completionRequest ).getChoices ().forEach (System .out ::println );
27
29
28
30
System .out .println ("\n Searching documents..." );
29
- SearchRequest searchRequest = new SearchRequest ();
30
- searchRequest .setDocuments (Arrays .asList ("Water" , "Earth" , "Electricity" , "Fire" ));
31
- searchRequest .setQuery ("Pikachu" );
31
+ SearchRequest searchRequest = SearchRequest .builder ()
32
+ .documents (Arrays .asList ("Water" , "Earth" , "Electricity" , "Fire" ))
33
+ .query ("Pikachu" )
34
+ .build ();
32
35
service .search ("ada" , searchRequest ).forEach (System .out ::println );
33
36
}
34
37
}
You can’t perform that action at this time.
0 commit comments