A conversation
Signal keeps nothing between calls. Each result carries the history so far, and you hand it to the next call.
pnpm add @niscorp/signal zod openaiThe 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().
import { createSignal } from '@niscorp/signal';
const signal = createSignal('groq');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.
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);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.
const second = await signal.history(first.history).complete('How long does it run?');
console.log(second.response);
console.log(second.history.length, 'messages');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.
GROQ_API_KEY=your-key npx tsx history.mts