Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用流式输出如何获取返回的内容啊???有大佬指指路吗 #262

Open
kiliyxiaohao opened this issue Jan 31, 2024 · 0 comments

Comments

@kiliyxiaohao
Copy link

@OverRide
public void onOpen(EventSource eventSource, Response response) {
log.info("OpenAI建立sse连接...");
}

@OverRide
public void onEvent(EventSource eventSource, String id, String type, String data) {
log.info("OpenAI返回数据:{}", data);
if (data.equals("[DONE]")) {
log.info("OpenAI返回数据结束了");
return;
}
}

@OverRide
public void onClosed(EventSource eventSource) {
log.info("OpenAI关闭sse连接...");
}

@SneakyThrows
@OverRide
public void onFailure(EventSource eventSource, Throwable t, Response response) {
if(Objects.isNull(response)){
log.error("OpenAI sse连接异常:{}", t);
eventSource.cancel();
return;
}
ResponseBody body = response.body();
if (Objects.nonNull(body)) {
log.error("OpenAI sse连接异常data:{},异常:{}", body.string(), t);
} else {
log.error("OpenAI sse连接异常data:{},异常:{}", response, t);
}
eventSource.cancel();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant