1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| OpenAiStreamingChatModel streamChatModel = OpenAiStreamingChatModel.builder() .apiKey(System.getenv("AI_KEY")) .modelName("qwen-plus") .baseUrl("https://dashscope.aliyuncs.com/compatible-mode/v1") .build();
CountDownLatch latch = new CountDownLatch(1);
streamChatModel.chat("你好呀", new StreamingChatResponseHandler() {
@Override public void onPartialResponse(String partialResponse) { System.out.printf("part_response:"+partialResponse); StreamingChatResponseHandler.super.onPartialResponse(partialResponse); }
@Override public void onCompleteResponse(ChatResponse chatResponse) { System.out.println("响应完成"); }
@Override public void onError(Throwable throwable) {
} });
latch.await();
|