LLM - LLMAssistantBuilder
LLM.LLMAssistantBuilderConstruct a multi-modal LLM agent from a purpose, prompt, functions and streams.
Type parameters
Name | Type |
---|---|
Inputs | extends Record = Record |
Functions | extends Record = Record |
Outputs | extends Record = Record |
Samples | extends 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
Name | Type |
---|---|
Name | extends string |
R | extends DictType |
Parameters
Name | Type | Description |
---|---|---|
function_name | Name extends keyof Functions ? never : Name | The unique identifier for the function. |
config | Object | A configuration object providing options for the aggregation operation. |
config.function_description? | string | The description of the function. * |
config.silent? | boolean | False if the function should return the value to the agent. * |
config.value | (inputs : Inputs ) => Variable | The Variable to be aggregated. * |
config.value_description? | AbstractTypeBuilder | (builder : TypeBuilder ) => AbstractTypeBuilder | The optional description of the entries in the collection. * |
Returns
LLMAssistantBuilder
<Inputs
, Functions
& { [K in string]: LLMAggregateFunction }, Outputs
, Samples
>
a new
LLMBuilderExample
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
Name | Type |
---|---|
Name | extends string |
T | extends DictType |
Parameters
Name | Type | Description |
---|---|---|
function_name | Name extends keyof Functions ? never : Name | The unique identifier for the function. |
config | Object | A configuration object providing options for the chart operation. |
config.function_description? | string | The description of the function. * |
config.value | Stream | The Stream to visualize. * |
config.value_description? | AbstractTypeBuilder | (builder : TypeBuilder ) => AbstractTypeBuilder | The optional description of the Stream to visualize. * |
Returns
LLMAssistantBuilder
<Inputs
, Functions
& { [K in string]: LLMChartFunction }, Outputs
, Samples
>
a new
LLMBuilderExample
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
Name | Type | Description |
---|---|---|
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
LLMBuilderExample
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
Name | Type |
---|---|
Name | extends string |
I | extends EastType |
R | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
function_name | Name extends keyof Functions ? never : Name | The unique identifier for the function. |
config | Object | A configuration object providing options for the expression operation. |
config.function_args | AbstractTypeBuilder | (builder : TypeBuilder ) => AbstractTypeBuilder | The StructType function arguments that must be passed in by the agent. * |
config.function_description? | string | The description of the function. * |
config.return_description? | AbstractTypeBuilder | (builder : TypeBuilder ) => AbstractTypeBuilder | The optional description of the return value. * |
config.return_error? | Object | The 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 ) => EastFunction | the EastFunction with a predicate indicating if an has occurred |
config.return_error.message | (args : Variable , ret : Variable , inputs : Inputs ) => EastFunction | the EastFunction with an error message |
config.return_value | (args : Variable , inputs : Inputs ) => EastFunction | The EastFunction value returned to the agent. * |
config.silent? | boolean | False 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
LLMBuilderExample
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
Name | Type |
---|---|
Name | extends string |
I | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
config | Object | the input stream and the resulting variable name |
config.name | Name extends "input" | keyof Inputs ? never : Name | The name of the input. * |
config.stream | Stream | The Stream to input. * |
Returns
LLMAssistantBuilder
<Inputs
& { [K in string]: Variable }, Functions
, Outputs
, Samples
>
a new
LLMBuilderExample
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
Name | Type |
---|---|
Name | extends string |
I | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
function_name | Name extends keyof Functions ? never : Name | The unique identifier for the function. |
config | Object | A configuration object providing options for the output operation. |
config.function_description? | string | The description of the function. * |
config.return_error? | Object | The 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 ) => EastFunction | the EastFunction with a predicate indicating if an has occurred |
config.return_error.message | (args : Variable , inputs : Inputs ) => EastFunction | the EastFunction with an error message |
config.value | AbstractTypeBuilder | (builder : TypeBuilder ) => AbstractTypeBuilder | The TypeBuilder describing the output value. * |
Returns
LLMAssistantBuilder
<Inputs
, Functions
& { [K in string]: LLMOutputFunction }, Outputs
& { [K in string]: Stream }, Samples
>
a new
LLMBuilderExample
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
Name | Type |
---|---|
Name | extends string |
T | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
function_name | Name extends keyof Functions ? never : Name | The unique identifier for the function. |
config | Object | A configuration object providing options for the read operation. |
config.function_description? | string | The description of the function. * |
config.return_description? | AbstractTypeBuilder | (builder : TypeBuilder ) => AbstractTypeBuilder | The optional description of the stream value. * |
config.return_value | (inputs : Inputs ) => Variable | The value returned to the assistant, Remarks this is not an Expression * |
config.silent? | boolean | False 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
LLMBuilderExample
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
Name | Type |
---|---|
Name | extends string |
T | extends EastType |
Parameters
Name | Type | Description |
---|---|---|
function_name | Name extends keyof Functions ? never : Name | The unique identifier for the function. |
config | Object | A configuration object providing options for the write operation. |
config.function_description? | string | The description of the function. * |
config.return_error? | Object | The 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 ) => EastFunction | the EastFunction with a predicate indicating if an has occurred |
config.return_error.message | (args : Variable , inputs : Inputs ) => EastFunction | the EastFunction with an error message |
config.value | Stream | The stream containing the value * |
config.value_description? | AbstractTypeBuilder | (builder : TypeBuilder ) => AbstractTypeBuilder | The optional description of the stream. * |
Returns
LLMAssistantBuilder
<Inputs
, Functions
& { [K in string]: LLMWriteFunction }, Outputs
, Samples
>
a new
LLMBuilderExample
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