|
5 | 5 | import com.fasterxml.jackson.databind.DeserializationFeature; |
6 | 6 | import com.fasterxml.jackson.databind.ObjectMapper; |
7 | 7 | import com.fasterxml.jackson.databind.SerializationFeature; |
| 8 | +import com.unfbx.chatgpt.entity.billing.BillingUsage; |
8 | 9 | import com.unfbx.chatgpt.entity.billing.CreditGrantsResponse; |
| 10 | +import com.unfbx.chatgpt.entity.billing.Subscription; |
9 | 11 | import com.unfbx.chatgpt.entity.chat.ChatCompletion; |
10 | 12 | import com.unfbx.chatgpt.entity.chat.ChatCompletionResponse; |
11 | 13 | import com.unfbx.chatgpt.entity.chat.Message; |
|
40 | 42 |
|
41 | 43 | import java.net.InetSocketAddress; |
42 | 44 | import java.net.Proxy; |
| 45 | +import java.time.LocalDate; |
43 | 46 | import java.util.*; |
44 | 47 | import java.util.concurrent.TimeUnit; |
45 | 48 |
|
@@ -78,10 +81,26 @@ public void before() { |
78 | 81 | //.keyStrategy(new KeyRandomStrategy()) |
79 | 82 | .keyStrategy(new FirstKeyStrategy()) |
80 | 83 | .okHttpClient(okHttpClient) |
81 | | - //自己做了代理就传代理地址,没有可不不传 |
| 84 | + //自己做了代理就传代理地址,没有可不不传,(关注公众号回复:openai ,获取免费的测试代理地址) |
82 | 85 | // .apiHost("https://自己代理的服务器地址/") |
83 | 86 | .build(); |
84 | 87 | } |
| 88 | + @Test |
| 89 | + public void subscription() { |
| 90 | + Subscription subscription = v2.subscription(); |
| 91 | + log.info("用户名:{}", subscription.getAccountName()); |
| 92 | + log.info("用户总余额(美元):{}", subscription.getHardLimitUsd()); |
| 93 | + log.info("更多信息看Subscription类"); |
| 94 | + } |
| 95 | + |
| 96 | + @Test |
| 97 | + public void billingUsage() { |
| 98 | + LocalDate start = LocalDate.of(2023, 3, 7); |
| 99 | + BillingUsage billingUsage = v2.billingUsage(start, LocalDate.now()); |
| 100 | + log.info("总使用金额(美分):{}", billingUsage.getTotalUsage()); |
| 101 | + log.info("更多信息看BillingUsage类"); |
| 102 | + } |
| 103 | + |
85 | 104 |
|
86 | 105 | @Test |
87 | 106 | public void chatTokensTest() { |
@@ -229,7 +248,7 @@ public void editText() { |
229 | 248 |
|
230 | 249 | @Test |
231 | 250 | public void genImages() { |
232 | | - Image image = Image.builder().prompt("电脑画面").build(); |
| 251 | + Image image = Image.builder().prompt("电脑画面").responseFormat(ResponseFormat.B64_JSON.getName()).build(); |
233 | 252 | ImageResponse imageResponse = v2.genImages(image); |
234 | 253 | System.out.println(imageResponse); |
235 | 254 | } |
@@ -283,15 +302,20 @@ public void variationsImages() { |
283 | 302 |
|
284 | 303 | @Test |
285 | 304 | public void embeddingsV2() { |
286 | | - Embedding embedding = Embedding.builder().input("我爱你亲爱的姑娘").build(); |
| 305 | + Embedding embedding = Embedding.builder().input(Arrays.asList("我爱你亲爱的姑娘", "i love you")).build(); |
287 | 306 | EmbeddingResponse embeddings = v2.embeddings(embedding); |
288 | 307 | System.out.println(embeddings); |
289 | 308 | } |
290 | 309 |
|
| 310 | + @Test |
| 311 | + public void embeddingsV3() { |
| 312 | + EmbeddingResponse embeddings = v2.embeddings(Arrays.asList("我爱你亲爱的姑娘", "i love you")); |
| 313 | + System.out.println(embeddings); |
| 314 | + } |
291 | 315 |
|
292 | 316 | @Test |
293 | 317 | public void embeddings() { |
294 | | - EmbeddingResponse embeddings = v2.embeddings("The food was delicious and the waiter..."); |
| 318 | + EmbeddingResponse embeddings = v2.embeddings("我爱你"); |
295 | 319 | System.out.println(embeddings); |
296 | 320 | } |
297 | 321 |
|
|
0 commit comments