Class Method<Input, Output>

This is the definition of a method that can be called by the LLM. The input and output are defined by a Schema. The handler is an async function that takes the input and returns the output. Methods can be added to a Service. The services can be added to a Chat.

Example

Here's a simple example:

const isEvenMethod = new Method<number, boolean>(
async (input) => input % 2 === 0,
{ type: 'number' },
{ type: 'boolean' }
);
const result = await isEvenMethod.handler(123); // false

Example

Here's a more complex example:

type ReserveIn = { hotelId: number; roomId: number; userEmail: string };
type ReserveOut = { reservationId?: number; error?: string };
const reserveHotelRoomMethod = new Method<ReserveIn, ReserveOut>(
{
async (input) => {
const { data } = await axios.post('/user', input);
if (data.error) {
return { error: data.error };
}
return { reservationId: data.reservationId };
}
type: 'object',
properties: {
hotelId: { type: 'number' },
roomId: { type: 'number' },
userEmail: { type: 'string' },
},
required: ['hotelId', 'roomId', 'userEmail'],
},
{
type: 'object',
properties: {
reservationId: { type: 'number' },
error: { type: 'string' },
},
},
);

Type Parameters

  • Input

    The input type for this method. This will be generated by the LLM.

  • Output

    The output type for this method. This will be interpreted by the LLM.

Hierarchy

  • Method

Constructors

  • Type Parameters

    • Input

    • Output

    Parameters

    • config: {
          description?: string;
          handler: ((input) => Promise<Output>);
          input: Schema<Input>;
          keywords?: string[];
          output?: Schema<Output>;
      }
      • Optional description?: string

        This description can be used to describe the method. This can be read by the LLM.

      • handler: ((input) => Promise<Output>)
          • (input): Promise<Output>
          • The async function that handles the method call. It takes an input of type Input and returns a value of type Output or a Promise that resolves to Output.

            Parameters

            • input: Input

            Returns Promise<Output>

      • input: Schema<Input>

        This Schema defines the input type. It can be a simple type like number or string, or it can be a complex type like an object or an array. Nested objects and arrays are also supported.

        The expectation is that this methods input will be generated by a LLM. The LLM will generate the input based on the input definition.

      • Optional keywords?: string[]

        A number of keywords that describe the method. This can be used by the LLM to filter methods.

      • Optional output?: Schema<Output>

        This Schema defines the output type. It can be a simple type like number or string, or it can be a complex type like an object or an array. Nested objects and arrays are also supported.

    Returns Method<Input, Output>

Properties

_description?: string
_handler: ((input) => Promise<Output>)

Type declaration

    • (input): Promise<Output>
    • Parameters

      • input: Input

      Returns Promise<Output>

_input: Schema<Input>
_keywords?: string[]
_output?: Schema<Output>

Accessors

  • get handler(): ((input) => Promise<Output>)
  • Returns ((input) => Promise<Output>)

      • (input): Promise<Output>
      • Parameters

        • input: Input

        Returns Promise<Output>

Methods

Generated using TypeDoc