Class EventStream
- java.lang.Object
-
- com.composum.ai.backend.slingbase.EventStream
-
- All Implemented Interfaces:
GPTCompletionCallback
public class EventStream extends Object implements GPTCompletionCallback
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.composum.ai.backend.base.service.chat.GPTCompletionCallback
GPTCompletionCallback.GPTCompletionCollector
-
-
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(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)
Called when a couple of characters come in.void
setId(String id)
void
setLoggingId(String loggingId)
For debugging: this sets the internal ID that is used for logging purposes.protected void
writeData(String data)
void
writeTo(PrintWriter writer)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.composum.ai.backend.base.service.chat.GPTCompletionCallback
setRequest
-
-
-
-
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(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 interfaceGPTCompletionCallback
-
setLoggingId
public void setLoggingId(String loggingId)
Description copied from interface:GPTCompletionCallback
For debugging: this sets the internal ID that is used for logging purposes. Not a good ID give to the world, though.- Specified by:
setLoggingId
in interfaceGPTCompletionCallback
-
getWholeResponse
@Nullable public String getWholeResponse()
Returns the whole response, but only if it was received completely, otherwise null.
-
onNext
public void onNext(String data)
Description copied from interface:GPTCompletionCallback
Called when a couple of characters come in.- Specified by:
onNext
in interfaceGPTCompletionCallback
-
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 interfaceGPTCompletionCallback
-
-