CompletionStream

org.llm4s.javaapi.CompletionStream
final class CompletionStream extends AutoCloseable

A completion being streamed from JLlmClient.stream to its CompletionStreamListener: cancel it, or await its reply. It is AutoCloseable, and close() cancels, so a try-with-resources block stops a call its body leaves.

try (CompletionStream stream = client.stream(conversation, piece -> ui.append(piece)).get()) {
   LlmResult<JCompletion> reply = stream.await();
}

Attributes

Graph
Supertypes
trait AutoCloseable
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def await(): LlmResult[JCompletion]

Blocks until the listener has returned from its last call - CompletionStreamListener.onComplete or CompletionStreamListener.onError - then returns the same outcome. A call whose thread is interrupted first returns a failed result (CancelledError) with the interrupt flag still set, and the stream carries on. A call from the listener itself, which would wait on itself, returns a failed result at once.

Blocks until the listener has returned from its last call - CompletionStreamListener.onComplete or CompletionStreamListener.onError - then returns the same outcome. A call whose thread is interrupted first returns a failed result (CancelledError) with the interrupt flag still set, and the stream carries on. A call from the listener itself, which would wait on itself, returns a failed result at once.

Attributes

def cancel(): Unit

Cancels the call: the provider's thread is interrupted, which is how llm4s providers are cancelled, and no further piece is delivered. The listener then receives CompletionStreamListener.onError with the cancellation - or onComplete, for a call that had already ended. Returns once the listener has heard, or after 5 seconds when a provider ignores the interrupt (logged at WARN). Safe to call more than once, from any thread, the listener's included.

Cancels the call: the provider's thread is interrupted, which is how llm4s providers are cancelled, and no further piece is delivered. The listener then receives CompletionStreamListener.onError with the cancellation - or onComplete, for a call that had already ended. Returns once the listener has heard, or after 5 seconds when a provider ignores the interrupt (logged at WARN). Safe to call more than once, from any thread, the listener's included.

Attributes

override def close(): Unit

Cancels the call; see cancel.

Cancels the call; see cancel.

Attributes

Definition Classes
AutoCloseable