Promptable

org.llm4s.prompt.Promptable
See thePromptable companion object
@Experimental
trait Promptable[-A]

How a value of type A is written into a Prompt.

An interpolated value is rendered by its Promptable, never by toString, and a type without one does not compile: prompt"Summarise $client" (an LLMClient) is a compile error naming the type.

case class Invoice(customer: String, amount: BigDecimal, currency: String) derives Promptable

prompt"Check ${Invoice("ACME, Inc.", BigDecimal("12.5"), "EUR")}"
// Check Invoice(customer: "ACME, Inc.", amount: 12.5, currency: "EUR")

The rendering is deterministic: a case class is its name and labelled fields in declaration order, an enum case its name, a Seq its elements in order, a Set and a Map sorted by their rendered elements and keys, None is (none), and a Some its value. A string on its own is written as it is; inside a structure it is quoted, so a comma in a field cannot be read as the end of the field.

Type parameters

A

the type rendered.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

Abstract methods

def render(value: A): String

value as it is written where it stands on its own in a prompt.

value as it is written where it stands on its own in a prompt.

Attributes

Concrete methods

def renderNested(value: A): String

value as it is written inside a case class, collection or Option; the same as render unless overridden.

value as it is written inside a case class, collection or Option; the same as render unless overridden.

Attributes