Skip to main content

LLM - LLMAssistantBuilder

LLM.LLMAssistantBuilder

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

Type parameters

NameType
Inputsextends Record = Record
Functionsextends Record = Record
Outputsextends Record = Record
Samplesextends VariantType<{ message: LLMMessage } & { [K in keyof Functions]: LLMFunctionCall }> = VariantType<{ message: LLMMessage } & { [K in keyof Functions]: LLMFunctionCall }>

Hierarchy

  • Builder

    LLMAssistantBuilder

LLM

aggregate

aggregate(function_name, config):

LLMAssistantBuilder<Inputs, Functions & { [K in string]: LLMAggregateFunction }, Outputs, Samples>

Allow the agent provide definition of an aggregation to perform on a stream, if added to a layout the values will be shown in a chat message.

Type parameters

NameType
Nameextends string
Rextends DictType

Parameters

NameTypeDescription
function_nameName extends keyof Functions ? never : NameThe unique identifier for the function.
configObjectA configuration object providing options for the aggregation operation.
config.function_description?stringThe description of the function. *
config.silent?booleanFalse if the function should return the value to the agent. *
config.value(inputs: Inputs) => VariableThe Variable to be aggregated. *
config.value_description?AbstractTypeBuilder | (builder: TypeBuilder) => AbstractTypeBuilderThe optional description of the entries in the collection. *

Returns

LLMAssistantBuilder<Inputs, Functions & { [K in string]: LLMAggregateFunction }, Outputs, Samples>

a new

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,
})
.aggregate(
"aggregate_sales",
{
value: (inputs) => inputs.sales,
}
)

chart

chart(function_name, config):

LLMAssistantBuilder<Inputs, Functions & { [K in string]: LLMChartFunction }, Outputs, Samples>

Allow the agent to create a chart from a stream, if added to a layout the chart will be shown in a chat message.

Type parameters

NameType
Nameextends string
Textends DictType

Parameters

NameTypeDescription
function_nameName extends keyof Functions ? never : NameThe unique identifier for the function.
configObjectA configuration object providing options for the chart operation.
config.function_description?stringThe description of the function. *
config.valueStreamThe Stream to visualize. *
config.value_description?AbstractTypeBuilder | (builder: TypeBuilder) => AbstractTypeBuilderThe optional description of the Stream to visualize. *

Returns

LLMAssistantBuilder<Inputs, Functions & { [K in string]: LLMChartFunction }, Outputs, Samples>

a new

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,
})
.chart(
"chart_sales_data",
{
value: sales_data.outputStream(),
}
)

example

example(values):

LLMAssistantBuilder

Add a chain of example messages, and functions calls to inform the agent.

Parameters

NameTypeDescription
values(builder: LLMTrainingSampleBuilder<Functions, VariantType<{ message: LLMMessage } & { [K in string | number | symbol]: LLMFunctionCall }>>) => LLMTrainingSampleBuilder<Functions, VariantType<{ message: LLMMessage } & { [K in string | number | symbol]: LLMFunctionCall }>>The builder defining the examples.

Returns

LLMAssistantBuilder

a new

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,
})
.chart(
"chart_sales_data",
`Read, aggregate and chart the sales data`,
sales_data.outputStream(),
)
.example(builder => builder
.message('user', "Can you show me the revenue over time per item, based on a price of $5.5?")
.call('write_inputs', builder => builder.args("Set the price.", 5.5))
.call('read_and_aggregate_results_data', builder => builder
.args(
"A chart showing the total revenue per item over time.",
{
name: "Total revenue per item over time",
mark: { kind: "line" },
x: { field: 'date', title: "Date", type: 'temporal' },
y: { field: 'amount', title: "Revenue", type: 'quantitative', aggregate: 'sum' },
color: { field: 'item', title: "Item", type: 'nominal' }
})
)
.message('assistant', "The chart of total revenue for a price of $5.5 was generated successfully.")
)

expression

expression(function_name, config):

LLMAssistantBuilder<Inputs, Functions & { [K in string]: LLMExpressionFunction }, Outputs, Samples>

Allow the agent provide arguments to a function that evaluates a user defined expression, if added to a layout the values will be shown in a chat message.

Type parameters

NameType
Nameextends string
Iextends EastType
Rextends EastType

Parameters

NameTypeDescription
function_nameName extends keyof Functions ? never : NameThe unique identifier for the function.
configObjectA configuration object providing options for the expression operation.
config.function_argsAbstractTypeBuilder | (builder: TypeBuilder) => AbstractTypeBuilderThe StructType function arguments that must be passed in by the agent. *
config.function_description?stringThe description of the function. *
config.return_description?AbstractTypeBuilder | (builder: TypeBuilder) => AbstractTypeBuilderThe optional description of the return value. *
config.return_error?ObjectThe predicate to check for an error, and message returned to the agent based on the arguments, return value and inputs. *
config.return_error.is_error(args: Variable, ret: Variable, inputs: Inputs) => EastFunctionthe EastFunction with a predicate indicating if an has occurred
config.return_error.message(args: Variable, ret: Variable, inputs: Inputs) => EastFunctionthe EastFunction with an error message
config.return_value(args: Variable, inputs: Inputs) => EastFunctionThe EastFunction value returned to the agent. *
config.silent?booleanFalse if the function should return the value to the agent, defaults to true. *

Returns

LLMAssistantBuilder<Inputs, Functions & { [K in string]: LLMExpressionFunction }, Outputs, Samples>

a new

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,
})
.expression(
"filter_sales",
{
function_args: (builder) => builder
.describe("The filter parameters")
.struct(builder => builder
.field('start', builder => builder.describe('sales with dates earlier than this will be removed').datetime())
.field('end', builder => builder.describe('sales with dates later than this will be removed').datetime())
),
return_value: (args, inputs) => Filter(
inputs.sales,
(value) => And(
GreaterEqual(GetField(value, 'date'), GetField(args, 'start')),
LessEqual(GetField(value, 'date'), GetField(args, 'end'))
)
),
}
)

input

input(config):

LLMAssistantBuilder<Inputs & { [K in string]: Variable }, Functions, Outputs, Samples>

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

LLMAssistantBuilder<Inputs & { [K in string]: Variable }, Functions, Outputs, Samples>

a new

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,
})
.read(
"get_the_price",
"Get the current value of the price",
(inputs) => inputs.price,
)

output

output(function_name, config):

LLMAssistantBuilder<Inputs, Functions & { [K in string]: LLMOutputFunction }, Outputs & { [K in string]: Stream }, Samples>

Allow the agent to produce a stream output, if added to a layout the values will be shown in a chat message.

Type parameters

NameType
Nameextends string
Iextends EastType

Parameters

NameTypeDescription
function_nameName extends keyof Functions ? never : NameThe unique identifier for the function.
configObjectA configuration object providing options for the output operation.
config.function_description?stringThe description of the function. *
config.return_error?ObjectThe predicate to check for an error, and message returned to the agent based on the arguments, and inputs. *
config.return_error.is_error(args: Variable, inputs: Inputs) => EastFunctionthe EastFunction with a predicate indicating if an has occurred
config.return_error.message(args: Variable, inputs: Inputs) => EastFunctionthe EastFunction with an error message
config.valueAbstractTypeBuilder | (builder: TypeBuilder) => AbstractTypeBuilderThe TypeBuilder describing the output value. *

Returns

LLMAssistantBuilder<Inputs, Functions & { [K in string]: LLMOutputFunction }, Outputs & { [K in string]: Stream }, Samples>

a new

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,
})
.output(
"change_the_price",
{
value: (builder) => builder.describe("The new price").float(),
}
)

read

read(function_name, config):

LLMAssistantBuilder<Inputs & { [K in string]: Variable }, Functions & { [K in string]: LLMValueFunction }, Outputs, Samples>

Allow the agent to read a

Stream value, if added to a layout the values will be shown in a chat message.

Type parameters

NameType
Nameextends string
Textends EastType

Parameters

NameTypeDescription
function_nameName extends keyof Functions ? never : NameThe unique identifier for the function.
configObjectA configuration object providing options for the read operation.
config.function_description?stringThe description of the function. *
config.return_description?AbstractTypeBuilder | (builder: TypeBuilder) => AbstractTypeBuilderThe optional description of the stream value. *
config.return_value(inputs: Inputs) => VariableThe value returned to the assistant, Remarks this is not an Expression *
config.silent?booleanFalse if the function should return the value to the agent. *

Returns

LLMAssistantBuilder<Inputs & { [K in string]: Variable }, Functions & { [K in string]: LLMValueFunction }, Outputs, Samples>

a new

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,
})
.read(
"get_the_price",
{
return_value: (inputs) => inputs.price,
}
)

write

write(function_name, config):

LLMAssistantBuilder<Inputs, Functions & { [K in string]: LLMWriteFunction }, Outputs, Samples>

Allow the agent to write a value to an existing writable stream, if added to a layout the values will be shown in a chat message.

Type parameters

NameType
Nameextends string
Textends EastType

Parameters

NameTypeDescription
function_nameName extends keyof Functions ? never : NameThe unique identifier for the function.
configObjectA configuration object providing options for the write operation.
config.function_description?stringThe description of the function. *
config.return_error?ObjectThe predicate to check for an error, and message returned to the agent based on the arguments, and inputs. *
config.return_error.is_error(args: Variable, inputs: Inputs) => EastFunctionthe EastFunction with a predicate indicating if an has occurred
config.return_error.message(args: Variable, inputs: Inputs) => EastFunctionthe EastFunction with an error message
config.valueStreamThe stream containing the value *
config.value_description?AbstractTypeBuilder | (builder: TypeBuilder) => AbstractTypeBuilderThe optional description of the stream. *

Returns

LLMAssistantBuilder<Inputs, Functions & { [K in string]: LLMWriteFunction }, Outputs, Samples>

a new

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_the_price",
{
value: price.outputStream(),
}
)

Source

outputStreams

outputStreams(): Outputs

Return the

Stream containing the output of the agent.

Returns

Outputs