Giter Club home page Giter Club logo

chatgpt-steam-output's Introduction

chatgpt-steam-output

Open AI ChatGPT流式输出。Open AI Stream output. ChatGPT Stream output.

主要就是做了EventSourceListener的继承实现自定义的com.unfbx.chatgptsteamoutput.listener.OpenAIEventSourceListener

SSE

主要是基于SSE 实现的(可以百度下这个技术)。也是最近在了解到SSE。OpenAI官网在接受Completions接口的时候,有提到过这个技术。 Completion对象本身有一个stream属性,当stream为true时候Api的Response返回就会变成Http长链接。 具体可以看下文档:https://platform.openai.com/docs/api-reference/completions/create

引入依赖

参考:https://github.com/Grt1228/chatgpt-java

<dependency>
    <groupId>com.unfbx</groupId>
    <artifactId>chatgpt-java</artifactId>
    <version>1.0.2</version>
</dependency>

实现自定义的EventSourceListener

com.unfbx.chatgptsteamoutput.listener.OpenAIEventSourceListener并持有一个SseEmitter,通过SseEmitter进行数据的通信

postman测试

发送请求:Get http://localhost:8080/test/sse?uid=123

看下response (需要新版本postman)我发现老版本不支持,就先不上图了,后续补上去 image

重点关注下header:Content-Type:text/event-stream

如果想结合前端显示自行百度sse前端相关实现

chatgpt-steam-output's People

Contributors

grt1228 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.