Class EventStream
- java.lang.Object
-
- com.composum.ai.backend.slingbase.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
-
-
Constructor Summary
Constructors Constructor Description EventStream()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addWholeResponseListener(Consumer<String> listener)
String
getWholeResponse()
Returns the whole response, but only if it was received completely, otherwise null.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"}]}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"}}}void
onNext(String data)
void
setId(String id)
void
setLoggingId(String loggingId)
protected void
writeData(String data)
void
writeTo(PrintWriter writer)
-
-
-
Field Detail
-
QUEUEEND
public static final String QUEUEEND
Special message in thequeue
that signals that we are done. Impossible in the normal stream.- See Also:
- Constant Field Values
-
-
Method Detail
-
setId
public void setId(String id)
-
writeTo
public void writeTo(PrintWriter writer) throws InterruptedException
- Throws:
InterruptedException
-
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 interfacecom.composum.ai.backend.base.service.chat.GPTCompletionCallback
-
setLoggingId
public void setLoggingId(String loggingId)
- Specified by:
setLoggingId
in interfacecom.composum.ai.backend.base.service.chat.GPTCompletionCallback
-
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 interfacecom.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 interfacecom.composum.ai.backend.base.service.chat.GPTCompletionCallback
-
-