Streams

org.llm4s.javaapi.reactor.Streams
object Streams

A model's reply as a Reactor Flux<String> of its text (#1492), for Spring WebFlux and other Reactor pipelines.

Each method adapts the JDK Flow.Publisher of org.llm4s.javaapi.JLlmClient#streamAsPublisher with Reactor's JdkFlowAdapter, so the Flux behaves as that publisher does:

  • it is cold: each subscription makes its own provider call, on a thread of its own;
  • it emits the pieces of the reply's text in order, then completes;
  • a failed call ends it with onError, carrying an LlmException whose getKind() says what failed;
  • it honours backpressure: a subscriber that requests less than the model produces holds the provider's thread rather than losing text;
  • cancelling the subscription (dispose(), take(n), a client that disconnects) interrupts the provider call.

A null argument is never thrown: the Flux fails on subscription with an LlmException of kind VALIDATION.

Flux<String> reply = Streams.toFlux(client, "Explain monads in one sentence");
reply.subscribe(System.out::print);

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Streams.type

Members list

Value members

Concrete methods

def toFlux(client: JLlmClient, query: String): Flux[String]

The reply to a single user query, as a Flux of its text.

The reply to a single user query, as a Flux of its text.

Attributes

def toFlux(client: JLlmClient, conversation: Conversation): Flux[String]

A conversation's reply, as a Flux of its text.

A conversation's reply, as a Flux of its text.

Attributes

def toFlux(client: JLlmClient, conversation: Conversation, options: JCompletionOptions): Flux[String]

A conversation's reply with the options of a org.llm4s.javaapi.JCompletionOptions, as a Flux of its text.

A conversation's reply with the options of a org.llm4s.javaapi.JCompletionOptions, as a Flux of its text.

Attributes