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
-
-
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.GPTCompletionCallbackWrapper, com.composum.ai.backend.base.service.chat.GPTCompletionCallback.GPTCompletionCollector, com.composum.ai.backend.base.service.chat.GPTCompletionCallback.GPTToolExecutionContext
-
-
Constructor Summary
Constructors Constructor Description EventStream()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addWholeResponseListener(Consumer<String> listener)
SlingGPTExecutionContext
getToolExecutionContext()
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
setContext(SlingGPTExecutionContext context)
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
-
setContext
public void setContext(SlingGPTExecutionContext context)
-
getToolExecutionContext
public SlingGPTExecutionContext getToolExecutionContext()
- Specified by:
getToolExecutionContext
in interfacecom.composum.ai.backend.base.service.chat.GPTCompletionCallback
-
-