Class Service

This is the definition of a service that can be called by the LLM. The methods are defined by a Method. The services can be added to a Chat.

Example

Here's an example of how to create a service:

const hotelService = new Service({
name: 'hotel',
description: 'A service for hotels',
keywords: ['hotel', 'reservation'],
});

Hierarchy

  • Service

Constructors

  • Parameters

    • config: {
          description?: string;
          keywords?: string[];
          name: string;
      }
      • Optional description?: string
      • Optional keywords?: string[]
      • name: string

    Returns Service

Properties

_description?: string
_keywords?: string[]
_methods: Record<string, Method<any, any>> = {}
_name: string

Accessors

Methods

  • Get a method by name.

    Parameters

    • name: string

      The name of the method.

    Returns undefined | Method<unknown, unknown>

    The method or undefined if it doesn't exist.

    See

    Method

    Example

    Here's an example of how to get a method:

    hotelService.getMethod('reserveHotelRoom');
    
  • Register a method to the service.

    Type Parameters

    • N extends string

    • I

    • O

    Parameters

    • name: N & (N extends keyof Service
          ? never
          : N)

      The name of the method. It should be unique within the service and not be a reserved name.

    • method: Method<I, O>

      The method to register.

    Returns Service & {
        [K in string]: Method<I, O>
    }

    Service with the new method registered. Use this to chain method registrations.

    Example

    Here's an example of how to register a method:

    const reserveHotelRoomMethod = new Method({
    input: {
    type: 'object',
    properties: { beginDate: {type:'string'}, endDate: {type:'string'} },
    },
    output: { type: 'object', properties: { orderId: {type:'string'} } },
    handler: async (input: { beginDate: string; endDate: string }) => {
    return { orderId: '123' };
    },
    });
    const hotelService = new Service({ name: 'hotel' })
    .registerMethod('reserveHotelRoom', reserveHotelRoomMethod);
    hotelService.reserveHotelRoom.handler({
    beginDate: '2020-01-01', endDate: '2020-01-02'
    });

    See

    Method

Generated using TypeDoc