Closed NingNing0111 closed 1 year ago
public class KeyInfoTest { OpenAiClient openAiClient; @Before public void before(){ //可以为null Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 10809)); HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(new OpenAILogger()); //!!!!千万别再生产或者测试环境打开BODY级别日志!!!! //!!!生产或者测试环境建议设置为这三种级别:NONE,BASIC,HEADERS,!!! httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS); OkHttpClient okHttpClient = new OkHttpClient .Builder() // .proxy(proxy) .addInterceptor(httpLoggingInterceptor) .addInterceptor(new OpenAiResponseInterceptor()) .connectTimeout(10, TimeUnit.SECONDS) .writeTimeout(30, TimeUnit.SECONDS) .readTimeout(30, TimeUnit.SECONDS) .build(); openAiClient = OpenAiClient.builder() //支持多key传入,请求时候随机选择 .apiKey(Arrays.asList("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")) //自定义key的获取策略:默认KeyRandomStrategy .keyStrategy(new KeyRandomStrategy()) .authInterceptor(new DynamicKeyOpenAiAuthInterceptor()) .okHttpClient(okHttpClient) .apiHost("https://api.openai.com/") .build(); } @Test public void subTest(){ Subscription subscription = openAiClient.subscription(); System.out.println(subscription); // BillingUsage billingUsage = openAiClient.billingUsage(LocalDate.of(2023, 5, 26), LocalDate.now()); // System.out.println(billingUsage); } }
提示请求体中需要传key
余额查询正常
更新1.0.14 已经发了release
https://github.com/Grt1228/chatgpt-java/releases/tag/v1.0.14 @NingNing0111
成功解决,感谢
问题代码
报错日志
提示请求体中需要传key
其它
余额查询正常