Module: batteries/use-tools
This module provides the UseTools component to allow a Large Language Model to invoke external functions.
Interfaces
Type Aliases
ToolChoice
Ƭ ToolChoice: z.infer
<typeof toolChoiceSchema
> | null
Defined in
packages/ai-jsx/src/batteries/use-tools.tsx:25
Functions
UseTools
▸ UseTools(props
, «destructured»
): AsyncGenerator
<string
, string
| Element
, unknown
>
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}
fallback="Politely explain you aren't able to help with that request."
query={ "You control a home automation system. The user has requested you take some
action in their home: " + userRequest }
</UseTools>;
Parameters
Name | Type |
---|---|
props | UseToolsProps |
«destructured» | RenderContext |
Returns
AsyncGenerator
<string
, string
| Element
, unknown
>