Class EventStream

  • All Implemented Interfaces:
    com.composum.ai.backend.base.service.chat.GPTCompletionCallback

    public class EventStream
    extends Object
    implements com.composum.ai.backend.base.service.chat.GPTCompletionCallback
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface com.composum.ai.backend.base.service.chat.GPTCompletionCallback

        com.composum.ai.backend.base.service.chat.GPTCompletionCallback.GPTCompletionCollector
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String QUEUEEND
      Special message in the queue that signals that we are done.
    • Constructor Summary

      Constructors 
      Constructor Description
      EventStream()  
    • Field Detail

      • QUEUEEND

        public static final String QUEUEEND
        Special message in the queue that signals that we are done. Impossible in the normal stream.
        See Also:
        Constant Field Values
    • Constructor Detail

      • EventStream

        public EventStream()
    • Method Detail

      • setId

        public void setId​(String id)
      • onFinish

        public void onFinish​(com.composum.ai.backend.base.service.chat.GPTFinishReason finishReason)
        Successfull conclusion; puts event 'finished' into the stream with data JSON like this: {"success":true,"data":{"result":{"finishreason":"STOP"}}}
        Specified by:
        onFinish in interface com.composum.ai.backend.base.service.chat.GPTCompletionCallback
      • setLoggingId

        public void setLoggingId​(String loggingId)
        Specified by:
        setLoggingId in interface com.composum.ai.backend.base.service.chat.GPTCompletionCallback
      • addWholeResponseListener

        public void addWholeResponseListener​(Consumer<String> listener)
      • getWholeResponse

        @Nullable
        public String getWholeResponse()
        Returns the whole response, but only if it was received completely, otherwise null.
      • onNext

        public void onNext​(String data)
        Specified by:
        onNext in interface com.composum.ai.backend.base.service.chat.GPTCompletionCallback
      • writeData

        protected void writeData​(String data)
      • onError

        public void onError​(Throwable throwable)
        Puts an 'exception' event into the stream with data JSON like this: {"success":false,"title":"Internal error","messages":[{"level":"error","text":"something happened"}]}
        Specified by:
        onError in interface com.composum.ai.backend.base.service.chat.GPTCompletionCallback