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.3k stars 810 forks source link

Readme 中例子的CountDownLatch 从未countdown #234

Closed nextyale-10 closed 9 months ago

nextyale-10 commented 9 months ago
public class Test {
    public static void main(String[] args) {
        OpenAiStreamClient client = OpenAiStreamClient.builder()
                .apiKey(Arrays.asList("sk-********","sk-********"))
                //自定义key的获取策略:默认KeyRandomStrategy
                //.keyStrategy(new KeyRandomStrategy())
                .keyStrategy(new FirstKeyStrategy())
                //自己做了代理就传代理地址,没有可不不传
//                .apiHost("https://自己代理的服务器地址/")
                .build();
        //聊天模型:gpt-3.5
        ConsoleEventSourceListener eventSourceListener = new ConsoleEventSourceListener();
        Message message = Message.builder().role(Message.Role.USER).content("你好啊我的伙伴!").build();
        ChatCompletion chatCompletion = ChatCompletion.builder().messages(Arrays.asList(message)).build();
        client.streamChatCompletion(chatCompletion, eventSourceListener);
        CountDownLatch countDownLatch = new CountDownLatch(1);
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

此代码片段的 countdownlatch 没有被释放过,或许能在你的框架里加上 latch 而不是用户自己加? 个人浅见

Grt1228 commented 9 months ago

这个是main测试,仅供参考 @nextyale-10