5.0.3 • Published 8 months ago

@llamaindex/autotool v5.0.3

Weekly downloads
-
License
-
Repository
-
Last release
8 months ago

@llamaindex/autotool

Auto transpile your JS function to LLM Agent compatible

Usage

First, Install the package

npm install @llamaindex/autotool
pnpm add @llamaindex/autotool
yarn add @llamaindex/autotool

Second, Add the plugin/loader to your configuration:

Next.js

import { withNext } from "@llamaindex/autotool/next";

/** @type {import('next').NextConfig} */
const nextConfig = {};

export default withNext(nextConfig);

Node.js

node --import @llamaindex/autotool/node ./path/to/your/script.js

Third, add "use tool" on top of your tool file or change to .tool.ts.

"use tool";

export function getWeather(city: string) {
  // ...
}
// ...

Finally, export a chat handler function to the frontend using llamaindex Agent

"use server";

// imports ...

export async function chatWithAI(message: string): Promise<JSX.Element> {
  const agent = new OpenAIAgent({
    tools: convertTools("llamaindex"),
  });
  const uiStream = createStreamableUI();
  agent
    .chat({
      stream: true,
      message,
    })
    .then(async (responseStream) => {
      return responseStream.pipeTo(
        new WritableStream({
          start: () => {
            uiStream.append("\n");
          },
          write: async (message) => {
            uiStream.append(message.response.delta);
          },
          close: () => {
            uiStream.done();
          },
        }),
      );
    });
  return uiStream.value;
}

License

MIT

5.0.3

8 months ago

5.0.2

8 months ago

5.0.1

8 months ago

5.0.0

9 months ago

4.0.9

9 months ago

4.0.8

9 months ago

4.0.10

9 months ago

4.0.5

9 months ago

4.0.7

9 months ago

4.0.6

9 months ago

4.0.4

9 months ago

4.0.1

9 months ago

4.0.0

9 months ago

4.0.3

9 months ago

4.0.2

9 months ago

3.0.22

9 months ago

3.0.21

9 months ago

3.0.20

9 months ago

3.0.18

9 months ago

3.0.19

9 months ago

3.0.12

9 months ago

3.0.13

9 months ago

3.0.10

10 months ago

3.0.11

10 months ago

3.0.16

9 months ago

3.0.17

9 months ago

3.0.14

9 months ago

3.0.15

9 months ago

3.0.8

10 months ago

3.0.7

10 months ago

3.0.6

10 months ago

3.0.9

10 months ago

3.0.4

10 months ago

3.0.3

10 months ago

3.0.2

10 months ago

3.0.1

10 months ago

3.0.5

10 months ago

3.0.0

10 months ago

1.0.0

1 year ago

2.0.1

11 months ago

2.0.0

1 year ago

0.0.1

1 year ago