Session

org.llm4s.repl.Session
See theSession companion object
@Experimental
final class Session

What the helpers of org.llm4s.repl talk to: a client, its completion options, the conversation so far and the statistics of the last call. Set it once as a context parameter and every helper finds it:

import org.llm4s.repl.*

given Session = Session.fromConfig()       // the `llm4s.providers.provider` section of application.conf
ask("Explain variance in Scala 3 in two sentences")

A session whose client cannot be built (no application.conf, a missing API key, an unregistered provider) is still a session: every helper prints the configuration error with its troubleshooting hint and returns a failure, so a worksheet never stops on a stack trace. failure says whether that is the case.

A session is for a REPL, a worksheet or a script, not for production code: it keeps the conversation in memory, prints to the console, and its helpers are not meant to be called concurrently. Each with* method returns a new session with the same client and an empty history.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def close(): Unit

Closes the client.

Closes the client.

Attributes

def failure: Option[LLMError]

The error that kept this session's client from being built, if there was one.

The error that kept this session's client from being built, if there was one.

Attributes

def reset(): Unit

Forgets the conversation so far and the last call's statistics.

Forgets the conversation so far and the last call's statistics.

Attributes

override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any
def withInput(in: BufferedReader): Session

A new session whose chat() reads lines from in instead of the console.

A new session whose chat() reads lines from in instead of the console.

Attributes

def withMaxToolSteps(steps: Int): Session

A new session that runs at most this many model calls (at least 1) for one ask that calls tools.

A new session that runs at most this many model calls (at least 1) for one ask that calls tools.

Attributes

A new session that sends these completion options with every call.

A new session that sends these completion options with every call.

Attributes

def withOutput(out: PrintStream): Session

A new session that prints to out instead of the console.

A new session that prints to out instead of the console.

Attributes

def withSystemPrompt(prompt: String): Session

A new session that starts every conversation with this system message.

A new session that starts every conversation with this system message.

Attributes

Concrete fields

val description: String
val maxToolSteps: Int
val systemPrompt: Option[String]