Module: batteries/use-tools
This module provides the UseTools component to allow a Large Language Model to invoke external functions.
Interfaces
Functions
UseTools
▸ UseTools(props
, «destructured»
): Promise
<0
| Element
| Element
<{ children
: Node
; name?
: string
}> | Element
<{ children
: Node
}> | Element
<{ args
: Record
<string
, null
| string
| number
| boolean
> ; name
: string
; partial?
: boolean
}> | Element
<{ children
: Node
; name
: string
; failed?
: boolean
}>>
Give a model tools it can use, like a calculator, or ability to call an API.
This is conceptually similar to chatGPT plugins.
Example
async function turnLightsOn() { ... Code to turn lights on ... }
async function turnLightsOff() { ... Code to turn lights off ... }
// Activate a scene in the user's lighting settings, like "Bedtime" or "Midday".
async function activeScene({sceneName}: {sceneName: string}) { ... Code to activate a scene ... }
import z from 'zod';
const tools: Record<string, Tool> = {
turnLightsOn: {
description: "Turn the lights on in the user's home",
parameters: {},
func: turnLightsOn,
},
turnLightsOff: {
description: "Turn the lights off in the user's home",
parameters: {},
func: turnLightsOff,
},
activeScene: {
description: `Activate a scene in the user's lighting settings, like "Bedtime" or "Midday".`,
parameters: {
sceneName: {
description: "The scene to activate the lighting in.",
type: "string",
required: true,
},
},
func: activeScene,
},
};
<UseTools tools={tools}>
<SystemMessage>
You control a home automation system. The user will request an action in their home. You should take an action and
then generate a response telling the user what you've done.
</SystemMessage>
<UserMessage>{userRequest}</UserMessage>
</UseTools>;
Parameters
Name | Type |
---|---|
props | UseToolsProps |
«destructured» | RenderContext |
Returns
Promise
<0
| Element
| Element
<{ children
: Node
; name?
: string
}> | Element
<{ children
: Node
}> | Element
<{ args
: Record
<string
, null
| string
| number
| boolean
> ; name
: string
; partial?
: boolean
}> | Element
<{ children
: Node
; name
: string
; failed?
: boolean
}>>