0.0.520 • Published 9 months ago

@literalai/client v0.0.520

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
9 months ago

Literal AI Node API Library

This library provides convenient access to the Literal GraphQL API and other utilities.

Installation

npm i @literalai/client

Get an API key

To get an API key, go to the Literal AI, create an account and copy your API key from the settings page.

Usage

The full documentation of the SDK can be found here.

You can also find more involved examples in our cookbooks repository.

Basic usage

The following example will create a Thread on Literal AI and create a Step inside this Thread.

import { LiteralClient } from '@literalai/client';

const client = new LiteralClient();

await client.thread({ name: 'Test Wrappers Thread' }).wrap(async () => {
  // You can access the current thread and step using the client
  const thread = client.getCurrentThread();

  // This step will be created with the thread as its parent
  await client
    .step({ name: 'Test Wrappers Step', type: 'assistant_message' })
    .send();
});

Advanced usage

The following example will create a Thread with a Run step nested inside. In the Run step, we will create two child steps: one for a retrieval and another for an LLM completion.

import { LiteralClient } from '@literalai/client';

const client = new LiteralClient();

// Wrapped functions can be defined anywhere
// When they run, they will inherit the current thread and step from the context
const retrieve = async (_query: string) =>
  client.step({ name: 'Retrieve', type: 'retrieval' }).wrap(async () => {
    // Fetch data from the vector database ...

    return [
      { score: 0.8, text: 'France is a country in Europe' },
      { score: 0.7, text: 'Paris is the capital of France' }
    ]
  });

const completion = async (_query: string, _augmentations: string[]) =>
  client.step({ name: 'Completion', type: 'llm' }).wrap(async () => {
    // Fetch completions from the language model ...
    return { content: 'Paris is a city in Europe' };
  });

  // The output of wrapped functions will always bubble up the wrapper chain
  const result = await client
    .thread({ name: 'Test Wrappers Thread' })
    .wrap(async () => {
      return client.run({ name: 'Test Wrappers Run' }).wrap(async () => {
        const results = await retrieve(query);
        const augmentations = results.map((result) => result.text);
        const completionText = await completion(query, augmentations);
        return completionText.content;
      });
    });

  return result;
0.0.520

9 months ago

0.0.517

10 months ago

0.0.518

10 months ago

0.0.516

10 months ago

0.0.513

11 months ago

0.0.512

12 months ago

0.0.511

12 months ago

0.0.510

12 months ago

0.0.515

11 months ago

0.0.514

11 months ago

0.0.509

1 year ago

0.0.508

1 year ago

0.0.507

1 year ago

0.0.506

1 year ago

0.0.505

1 year ago

0.0.504

1 year ago

0.0.503

1 year ago

0.0.502

1 year ago

0.0.501

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.302

1 year ago

0.0.301

1 year ago

0.0.300

1 year ago

0.0.201

1 year ago

0.0.200

1 year ago

0.0.101

2 years ago

0.0.1

2 years ago