Grt1228 / chatgpt-java

ChatGPT Java SDK支持流式输出、Gpt插件、联网。支持OpenAI官方所有接口。ChatGPT的Java客户端。OpenAI GPT-3.5-Turb GPT-4 Api Client for Java
https://chatgpt-java.unfbx.com
Apache License 2.0
3.34k stars 816 forks source link

/v1/dashboard/billing/subscription 账户查询无法正常使用 #173

Closed NingNing0111 closed 1 year ago

NingNing0111 commented 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);
    }
}

报错日志

image

提示请求体中需要传key

其它

余额查询正常

Grt1228 commented 1 year ago

更新1.0.14 已经发了release

Grt1228 commented 1 year ago

https://github.com/Grt1228/chatgpt-java/releases/tag/v1.0.14 @NingNing0111

NingNing0111 commented 1 year ago

成功解决,感谢