ScriptedLLMClient

org.llm4s.testkit.ScriptedLLMClient
See theScriptedLLMClient companion class

Attributes

Companion
class
Source
ScriptedLLMClient.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

A client that gives the same reply to every call.

A client that gives the same reply to every call.

Attributes

Source
ScriptedLLMClient.scala

A client that chooses each reply from the conversation. A conversation no case matches returns a Left(UnscriptedCallError) that names the call.

A client that chooses each reply from the conversation. A conversation no case matches returns a Left(UnscriptedCallError) that names the call.

The rules run under the client's lock, so they must not block on another call to the same client, and an exception a rule throws is not caught: it propagates from complete or streamComplete.

EndsWithUser, LastUser, AfterToolResult, AfterToolResults and AfterCorrection are extractors for the rules: each matches a conversation by where in a turn its call is.

ScriptedLLMClient.respondingTo {
 case EndsWithUser(s"take $item")              => Reply.toolCall("add_inventory_item", s"""{"item":"$item"}""")
 case AfterToolResult("add_inventory_item", _) => Reply.text("Taken.")
 case c if c.messages.size > 20                => Reply.text("That is enough.")
}

Attributes

Source
ScriptedLLMClient.scala
def sequence(replies: Reply*): ScriptedLLMClient

A client that answers call 1 with the first reply, call 2 with the second, and so on. A call past the end of the script returns a Left(UnscriptedCallError) that names the call.

A client that answers call 1 with the first reply, call 2 with the second, and so on. A call past the end of the script returns a Left(UnscriptedCallError) that names the call.

Attributes

Source
ScriptedLLMClient.scala