LlmResult

org.llm4s.javaapi.LlmResult
See theLlmResult companion object
final class LlmResult[A]

Java-friendly wrapper for org.llm4s.types.Result, which is an Either[LLMError, A].

Rather than requiring Java callers to deal with Scala's Either, Option, or Left/Right, this class surfaces a familiar API modelled after java.util.Optional and CompletableFuture.

LlmResult<String> result = client.complete("What is 2+2?");
result.ifSuccess(System.out::println)
     .ifFailure(e -> System.err.println(e.getMessage()));

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def get(): A

Returns the value on success, or throws LlmException on failure.

Returns the value on success, or throws LlmException on failure.

Attributes

Returns the LlmException on failure, or null on success.

Returns the LlmException on failure, or null on success.

Attributes

def getOrNull(): A

Returns the value on success, or null on failure.

Returns the value on success, or null on failure.

Intended for reference types only (String, Completion, ...), which is what every Java-facing API here returns. If A were ever a primitive mapping (int, boolean), the failure case would yield 0/false instead of null, so prefer toOptional or isSuccess there.

Attributes

def ifFailure(action: Consumer[LlmException]): LlmResult[A]

Invokes action with the exception if this result is a failure. Returns this to allow chaining with ifSuccess.

Invokes action with the exception if this result is a failure. Returns this to allow chaining with ifSuccess.

Attributes

def ifSuccess(action: Consumer[A]): LlmResult[A]

Invokes action with the value if this result is a success. Returns this to allow chaining with ifFailure.

Invokes action with the value if this result is a success. Returns this to allow chaining with ifFailure.

Attributes

def isFailure: Boolean
def isSuccess: Boolean
def map[B](f: Function[A, B]): LlmResult[B]

Transforms the success value; failures pass through unchanged.

Transforms the success value; failures pass through unchanged.

Attributes

def toCompletableFuture: CompletableFuture[A]

Returns an already-completed CompletableFuture wrapping the result.

Returns an already-completed CompletableFuture wrapping the result.

Attributes

def toOptional: Optional[A]

Returns Optional.of(value) on success, Optional.empty() on failure, and also Optional.empty() when the success value is null (never throws).

Returns Optional.of(value) on success, Optional.empty() on failure, and also Optional.empty() when the success value is null (never throws).

Attributes