Skip to main content

LLM - LLMBuilder

LLM.LLMBuilder

Construct a multi-modal LLM agent from a purpose, prompt, functions and streams.

Example

 const price = new SourceBuilder("price")
.value({ value: 5 });

const message = new SourceBuilder("message",)
.writeable(AssistantInputStateType);

const sales = new SourceBuilder("sales")
.writeable(DictType(
StringType,
StructType({
date: DateTimeType,
item: StringType,
qty: IntegerType,
inventory: IntegerType,
price: FloatType,
amount: FloatType,
}))
)

const model = new SourceBuilder("model",)
.value({ value: variant('gpt-3.5-turbo-1106', null), type: LLMModelType });

const assistant = new LLMBuilder("assistant")
.input({ name: "sales", stream: sales.outputStream() })
.input({ name: "message", stream: message.outputStream() })
.input({ name: "model", stream: model.outputStream() })
.input({ name: "price", stream: price.outputStream() })
.assistant({
api_key: "...",
purpose: "You are a business analyst assistant",
prompt: (inputs) => inputs.message,
model: (inputs) => inputs.model,
})
.write(
"change_price",
"Change the value of the price.",
price.outputStream(),
)

Type parameters

NameType
Inputsextends Record =

LLM

assistant

assistant(args):

LLMAssistantBuilder<Inputs, , , VariantType<{ message: LLMMessage } & >>

Construct an Agent that produces any EastType

Stream, based on a purpose, requests and other streams.

Parameters

NameTypeDescription
argsObject-
args.api_keystring | (inputs: Inputs) => EastFunctionthe OpenAI api key
args.model?OpenAiModel | (inputs: Inputs) => EastFunctionthe open ai model to use
args.prompt?string | (inputs: Inputs) => EastFunction<Nullable>the assistant state, a message or thread
args.purpose?string | (inputs: Inputs) => EastFunctionthe purpose of the assistant

Returns

LLMAssistantBuilder<Inputs, , , VariantType<{ message: LLMMessage } & >>

a new

LLMAssistantBuilder

Example

 const price = new SourceBuilder("price")
.value({ value: 5 });

const message = new SourceBuilder("message",)
.writeable(AssistantInputStateType);

const sales = new SourceBuilder("sales")
.writeable(DictType(
StringType,
StructType({
date: DateTimeType,
item: StringType,
qty: IntegerType,
inventory: IntegerType,
price: FloatType,
amount: FloatType,
}))
)

const model = new SourceBuilder("model",)
.value({ value: variant('gpt-3.5-turbo-1106', null), type: LLMModelType });

const assistant = new LLMBuilder("assistant")
.input({ name: "sales", stream: sales.outputStream() })
.input({ name: "message", stream: message.outputStream() })
.input({ name: "model", stream: model.outputStream() })
.input({ name: "price", stream: price.outputStream() })
.assistant({
api_key: "...",
purpose: "You are a business analyst assistant",
prompt: (inputs) => inputs.message,
model: (inputs) => inputs.model,
})
.write(
"change_price",
"Change the value of the price.",
price.outputStream(),
)

input

input(config):

LLMBuilder<Inputs & { [K in string]: Variable }>

Add an additional named input

Stream to the LLMBuilder.

Type parameters

NameType
Nameextends string
Iextends EastType

Parameters

NameTypeDescription
configObjectthe input stream and the resulting variable name
config.nameName extends "input" | keyof Inputs ? never : NameThe name of the input. *
config.streamStreamThe Stream to input. *

Returns

LLMBuilder<Inputs & { [K in string]: Variable }>

a new

LLMBuilder

Example

 // use a stream that is a collection of pdf documents per customer
const price = new SourceBuilder("price")
.value({ value: 5 });

const message = new SourceBuilder("message",)
.writeable(AssistantInputStateType);

const model = new SourceBuilder("model",)
.value({ value: variant('gpt-3.5-turbo-1106', null), type: LLMModelType });

const assistant = new LLMBuilder("assistant")
.input({ name: "message", stream: message.outputStream() })
.input({ name: "model", stream: model.outputStream() })
.input({ name: "price", stream: price.outputStream() })
.assistant({
api_key: "...",
purpose: "You are a business analyst assistant",
prompt: (inputs) => inputs.message,
model: (inputs) => inputs.model,
})
.input({ name: "price", stream: price.outputStream() })
.write(
"change_price",
"Change the value of the price.",
price.outputStream(),
)

Other

constructor

new LLMBuilder(name, module?, inputs?, input_streams?):

LLMBuilder

Construct a multi-modal LLM agent from a purpose, prompt, functions and streams.

Type parameters

NameType
Inputsextends Record =

Parameters

NameType
namestring
module?ModulePath | ModuleBuilder
inputsInputs
input_streamsRecord

Returns

LLMBuilder

Example

 const price = new SourceBuilder("price")
.value({ value: 5 });

const message = new SourceBuilder("message",)
.writeable(AssistantInputStateType);

const sales = new SourceBuilder("sales")
.writeable(DictType(
StringType,
StructType({
date: DateTimeType,
item: StringType,
qty: IntegerType,
inventory: IntegerType,
price: FloatType,
amount: FloatType,
}))
)

const model = new SourceBuilder("model",)
.value({ value: variant('gpt-3.5-turbo-1106', null), type: LLMModelType });

const assistant = new LLMBuilder("assistant")
.input({ name: "sales", stream: sales.outputStream() })
.input({ name: "message", stream: message.outputStream() })
.input({ name: "model", stream: model.outputStream() })
.input({ name: "price", stream: price.outputStream() })
.assistant({
api_key: "...",
purpose: "You are a business analyst assistant",
prompt: (inputs) => inputs.message,
model: (inputs) => inputs.model,
})
.write(
"change_price",
"Change the value of the price.",
price.outputStream(),
)