Signal · guide

A conversation

Signal keeps nothing between calls. Each result carries the history so far, and you hand it to the next call.

Install it
pnpm add @niscorp/signal zod openai
Step 1 of 3

The client

createSignal names a provider and gives you a client. The key is read from GROQ_API_KEY when a call is made, and the model is the provider’s default unless you name one with .model().

The client
import { createSignal } from '@niscorp/signal';

const signal = createSignal('groq');
Step 2 of 3

The first question

systemPrompt gives a client whose call starts with that message.

A result has the response, and history: every message of the call, the system prompt and the answer included.

The first question
const first = await signal
  .systemPrompt('You answer for a theatre’s box office, in one sentence.')
  .complete('What is on this Saturday?');
console.log(first.response);
Step 3 of 3

The second

history gives a client that starts from those messages, so “it” means something. The history already holds the system prompt, so this call starts from the plain client.

Where the history is kept between two requests is yours to decide: it is plain data.

The second
const second = await signal.history(first.history).complete('How long does it run?');
console.log(second.response);
console.log(second.history.length, 'messages');
Then

Run it.

This file asks a model, so it is not run on this site. It prints the two answers, the second one about the show the first one named, and then 5 messages: the system prompt, two questions and two answers.

Run it
GROQ_API_KEY=your-key npx tsx history.mts