org.llm4s.javaapi

Members list

Type members

Classlikes

final class ConversationBuilder

Builder for constructing a Conversation without using Scala case-class syntax or sequence literals.

Builder for constructing a Conversation without using Scala case-class syntax or sequence literals.

Conversation conv = ConversationBuilder.create()
   .system("You are a helpful assistant.")
   .user("What is the capital of France?")
   .build();

Instances are immutable: every method returns a new builder, so a builder may be shared and forked across threads. A null content argument throws NullPointerException immediately.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
final class JAgent

Java-friendly wrapper around Agent.

Java-friendly wrapper around Agent.

Exposes a simplified run(query) entry point that returns LlmResult[AgentState] so Java callers do not need to deal with Scala's Either or Result types directly.

Obtain instances via Llm4s.createAgent.

JAgent agent = Llm4s.createAgent(client);
LlmResult<AgentState> result = agent.run("Summarise the news today");
result.ifSuccess(state -> System.out.println(state.conversation()))
     .ifFailure(e -> System.err.println(e.getMessage()));

Attributes

Supertypes
class Object
trait Matchable
class Any
final class JLlmClient extends AutoCloseable

Java-friendly wrapper around LLMClient.

Java-friendly wrapper around LLMClient.

The underlying Scala client returns Result[Completion]; this wrapper unwraps the content string and surfaces it as LlmResult so Java callers never import any Scala types.

Obtain instances via Llm4s.createDefaultClient or Llm4s.createClient.

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

Attributes

Supertypes
trait AutoCloseable
class Object
trait Matchable
class Any
object Llm4s

Entry-point factory for Java callers.

Entry-point factory for Java callers.

All methods return LlmResult so Java code never imports Scala Either or deals with implicit/given parameters directly. The Scala-level ModelRegistryService given is resolved internally and passed explicitly.

=== Quick-start (Java) ===

LlmResult<JLlmClient> r = Llm4s.createDefaultClient();
if (r.isSuccess()) {
   JLlmClient client = r.get();
   client.complete("Hello").ifSuccess(System.out::println);
}

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
Llm4s.type
final class LlmException(val error: LLMError) extends RuntimeException

A checked-free runtime exception wrapping an LLMError, thrown only when Java callers dereference a failed LlmResult via LlmResult#get.

A checked-free runtime exception wrapping an LLMError, thrown only when Java callers dereference a failed LlmResult via LlmResult#get.

If the wrapped error carries an underlying Throwable (for example a cause: Option[Throwable] field), it is exposed through getCause.

Attributes

Companion
object
Supertypes
class RuntimeException
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all
object LlmException

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
final class LlmResult[A]

Java-friendly wrapper for org.llm4s.types.Result, which is an Either[LLMError, 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
Supertypes
class Object
trait Matchable
class Any
object LlmResult

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
LlmResult.type