Reply

org.llm4s.testkit.Reply
See theReply companion object
final case class Reply

What one scripted call to a ScriptedLLMClient returns: a text answer, one or more tool calls, or a failure.

Build one with Reply.text, Reply.toolCall, Reply.toolCalls or Reply.failure, and adjust it with the with* methods:

Reply.text("Paris").withUsage(TokenUsage(promptTokens = 12, completionTokens = 1, totalTokens = 13))
Reply.toolCall("get_weather", """{"city": "Paris"}""")
Reply.failure(RateLimitError("openai"))

A reply that carries a failure is returned as a Left; every other reply becomes a Completion.

Tool-call arguments are written as a JSON string, so the kit's own factories need no JSON library in the test. Reply.toolCalls and withToolCalls take core's ToolCall as it is, for a test that already builds them.

Value parameters

content

the text of the answer; empty for a reply that only calls tools

failure

the error to return instead of a completion

model

the model name reported in the completion

toolCalls

the tool calls the model makes; a call whose id is empty is given the id call-<call number>-<position> when the client returns it

usage

the token usage reported in the completion

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def isFailure: Boolean

True when this reply makes the call fail.

True when this reply makes the call fail.

Attributes

def withContent(content: String): Reply

This reply with another text.

This reply with another text.

Attributes

def withModel(model: String): Reply

This reply with another model name in the completion.

This reply with another model name in the completion.

Attributes

def withToolCall(name: String, argumentsJson: String, id: Option[String]): Reply

This reply with one more tool call after the ones it already makes, so that one answer can call several tools.

This reply with one more tool call after the ones it already makes, so that one answer can call several tools.

Reply.toolCall("get_weather", """{"city": "Oslo"}""").withToolCall("get_time", """{"zone": "CET"}""")

Value parameters

argumentsJson

the arguments the model passes, as a JSON object

id

the id of the call; when None the client numbers it

name

the name of the tool, as registered with the agent

Attributes

Throws
IllegalArgumentException

if argumentsJson is not a JSON object

def withToolCalls(toolCalls: List[ToolCall]): Reply

This reply with other tool calls.

This reply with other tool calls.

Attributes

def withUsage(usage: TokenUsage): Reply

This reply reporting the given token usage.

This reply reporting the given token usage.

Attributes

def withUsage(usage: Option[TokenUsage]): Reply

This reply reporting the given token usage, or none.

This reply reporting the given token usage, or none.

Attributes

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product