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.GPTCompletionCallbackWrapper, GPTCompletionCallback.GPTCompletionCollector, GPTCompletionCallback.GPTToolExecutionContext
-
-
Constructor Summary
Constructors Constructor Description EventStream()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddWholeResponseListener(Consumer<String> listener)SlingGPTExecutionContextgetToolExecutionContext()For tool calls: set the context to execute actions in.StringgetWholeResponse()Returns the whole response, but only if it was received completely, otherwise null.voidonError(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"}]}voidonFinish(GPTFinishReason finishReason)Successfull conclusion; puts event 'finished' into the stream with data JSON like this: {"success":true,"data":{"result":{"finishreason":"STOP"}}}voidonNext(String data)Called when a couple of characters come in.voidsetContext(SlingGPTExecutionContext context)voidsetId(String id)voidsetLoggingId(String loggingId)For debugging: this sets the internal ID that is used for logging purposes.protected voidwriteData(String data)voidwriteTo(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
close, setRequest, toolDelta
-
-
-
-
Field Detail
-
QUEUEEND
public static final String QUEUEEND
Special message in thequeuethat 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:
onFinishin interfaceGPTCompletionCallback
-
setLoggingId
public void setLoggingId(String loggingId)
Description copied from interface:GPTCompletionCallbackFor debugging: this sets the internal ID that is used for logging purposes. Not a good ID give to the world, though.- Specified by:
setLoggingIdin 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:GPTCompletionCallbackCalled when a couple of characters come in.- Specified by:
onNextin 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:
onErrorin interfaceGPTCompletionCallback
-
setContext
public void setContext(SlingGPTExecutionContext context)
-
getToolExecutionContext
public SlingGPTExecutionContext getToolExecutionContext()
Description copied from interface:GPTCompletionCallbackFor tool calls: set the context to execute actions in.- Specified by:
getToolExecutionContextin interfaceGPTCompletionCallback
-
-