File tree Expand file tree Collapse file tree
main/java/org/devlive/sdk/openai
test/java/org/devlive/sdk/openai Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818
1919</div >
2020
21+ # How to use?
22+
23+ ``` java
24+ < properties>
25+ < openai. version> LATEST</ openai. version>
26+ < / properties>
27+
28+ < dependencies>
29+ < dependency>
30+ < groupId> org. devlive. sdk< / groupId>
31+ < artifactId> openai- java- sdk< / artifactId>
32+ < version> ${openai. version}< / version>
33+ < exclusions>
34+ < exclusion>
35+ < groupId> org. slf4j< / groupId>
36+ < artifactId> slf4j- simple< / artifactId>
37+ < / exclusion>
38+ < / exclusions>
39+ < / dependency>
40+ < / dependencies>
41+ ```
42+
43+ ` LATEST ` By default the latest version will be used.
44+
2145# Feature
2246
2347---
Original file line number Diff line number Diff line change 1+ ---
2+ title : User
3+ ---
4+
5+ !!! Note
6+
7+ Please build the client before calling, the build code is as follows:
8+
9+ ```java
10+ OpenAiClient client = OpenAiClient.builder()
11+ .apiHost("https://api.openai.com")
12+ .apiKey(System.getProperty("openai.token"))
13+ .build();
14+ ```
15+
16+ `System.getProperty("openai.token")` is the key to access the API authorization.
17+
18+ ### List keys
19+
20+ ---
21+
22+ Lists the currently available api keys, and provides basic information about each one such as the owner and availability.
23+
24+ ``` java
25+ client. getKeys();
26+ ```
27+
28+ Returns:
29+
30+ ``` json
31+ {
32+ "object" : " list" ,
33+ "data" : [
34+ {
35+ "sensitive_id" : " sk-xxx" ,
36+ "object" : " api_key" ,
37+ "name" : " Open API Key" ,
38+ "created" : 1688363358 ,
39+ "last_use" : 1688522702 ,
40+ "publishable" : false
41+ }
42+ ]
43+ }
44+ ```
45+
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ markdown_extensions:
4444nav :
4545 - index.md
4646 - Reference :
47+ - reference/users.md
4748 - reference/models.md
4849 - reference/completions.md
4950 - reference/completions_chat.md
Original file line number Diff line number Diff line change 77import org .devlive .sdk .openai .response .CompleteChatResponse ;
88import org .devlive .sdk .openai .response .CompleteResponse ;
99import org .devlive .sdk .openai .response .ModelResponse ;
10+ import org .devlive .sdk .openai .response .UserKeyResponse ;
1011import retrofit2 .http .Body ;
1112import retrofit2 .http .GET ;
1213import retrofit2 .http .POST ;
@@ -39,4 +40,10 @@ public interface DefaultApi
3940 */
4041 @ POST (value = "v1/chat/completions" )
4142 Single <CompleteChatResponse > fetchChatCompletions (@ Body CompletionChatEntity configure );
43+
44+ /**
45+ * Get all keys
46+ */
47+ @ GET (value = "dashboard/user/api_keys" )
48+ Single <UserKeyResponse > fetchUserAPIKeys ();
4249}
Original file line number Diff line number Diff line change 66import org .devlive .sdk .openai .response .CompleteChatResponse ;
77import org .devlive .sdk .openai .response .CompleteResponse ;
88import org .devlive .sdk .openai .response .ModelResponse ;
9+ import org .devlive .sdk .openai .response .UserKeyResponse ;
910
1011public abstract class DefaultClient
1112{
@@ -34,4 +35,10 @@ public CompleteChatResponse createChatCompletion(CompletionChatEntity configure)
3435 return this .api .fetchChatCompletions (configure )
3536 .blockingGet ();
3637 }
38+
39+ public UserKeyResponse getKeys ()
40+ {
41+ return this .api .fetchUserAPIKeys ()
42+ .blockingGet ();
43+ }
3744}
Original file line number Diff line number Diff line change 1+ package org .devlive .sdk .openai .entity ;
2+
3+ import com .fasterxml .jackson .annotation .JsonFormat ;
4+ import com .fasterxml .jackson .annotation .JsonIgnoreProperties ;
5+ import com .fasterxml .jackson .annotation .JsonProperty ;
6+ import lombok .AllArgsConstructor ;
7+ import lombok .Builder ;
8+ import lombok .Data ;
9+ import lombok .NoArgsConstructor ;
10+ import lombok .ToString ;
11+
12+ @ Data
13+ @ Builder
14+ @ ToString
15+ @ NoArgsConstructor
16+ @ AllArgsConstructor
17+ @ JsonIgnoreProperties (ignoreUnknown = true )
18+ public class UserKeyEntity
19+ {
20+ @ JsonProperty (value = "sensitive_id" )
21+ private String sensitiveId ;
22+
23+ @ JsonProperty (value = "object" )
24+ private String object ;
25+
26+ @ JsonProperty (value = "name" )
27+ private String name ;
28+
29+ @ JsonProperty (value = "created" )
30+ @ JsonFormat (pattern = "yyyy-MM-dd HH:mm:ss" )
31+ private String createTime ;
32+
33+ @ JsonProperty (value = "last_use" )
34+ @ JsonFormat (pattern = "yyyy-MM-dd HH:mm:ss" )
35+ private String lastUseTime ;
36+
37+ @ JsonProperty (value = "publishable" )
38+ private boolean publishable ;
39+ }
Original file line number Diff line number Diff line change 1+ package org .devlive .sdk .openai .response ;
2+
3+ import com .fasterxml .jackson .annotation .JsonIgnoreProperties ;
4+ import com .fasterxml .jackson .annotation .JsonProperty ;
5+ import lombok .AllArgsConstructor ;
6+ import lombok .Data ;
7+ import lombok .NoArgsConstructor ;
8+ import lombok .ToString ;
9+ import org .devlive .sdk .openai .entity .UserKeyEntity ;
10+
11+ import java .util .List ;
12+
13+ @ Data
14+ @ ToString
15+ @ NoArgsConstructor
16+ @ AllArgsConstructor
17+ @ JsonIgnoreProperties (ignoreUnknown = true )
18+ public class UserKeyResponse
19+ {
20+ @ JsonProperty (value = "object" )
21+ private String object ;
22+
23+ @ JsonProperty (value = "data" )
24+ private List <UserKeyEntity > keys ;
25+ }
Original file line number Diff line number Diff line change @@ -112,4 +112,10 @@ public void testCreateChatCompletion()
112112 .toString ()
113113 .contains ("openai-java-sdk" ));
114114 }
115+
116+ @ Test
117+ public void testGetKeys ()
118+ {
119+ Assert .assertNotNull (client .getKeys ());
120+ }
115121}
You can’t perform that action at this time.
0 commit comments