@justanotherkevin/awol
v0.1.0
Published
AWOL (audio wave object labeler) labels what each speaker in a live conversation is doing, using a small decision model running in LM Studio.
Maintainers
Readme
AWOL
AWOL stands for audio wave object labeler. It labels what each speaker in a live conversation is doing, using a small decision model running on your own machine.
What it does
You give AWOL the transcript text of each speaker as it arrives. When a speaker finishes a turn, AWOL sends that speaker's text to the decision model with one or more questions. The model answers, and AWOL hands you a labeled decision. The decision has the option the model chose and the probability of every option.
Results are kept per speaker. A new request for one speaker never drops or cancels the request of the other speaker. Within one speaker, if an older request finishes after a newer one has already been delivered, the older result is dropped. Each speaker can have at most 2 requests running at once. When a third starts, the oldest one for that speaker is cancelled.
Requirements
- Node.js 20.3 or newer.
- LM Studio with the System One endpoint
POST /v1/systemone. This package was tested with LM Studio 0.4.28. Older versions do not have this endpoint, so update LM Studio first. Documentation: https://lmstudio.ai/docs/developer/jev-compat/systemone - A decision model downloaded and loaded in LM Studio. It must be a decision model, not a chat model, because this endpoint rejects chat models. Load it with
lms load <model>. The LM Studio local server must be running. Its default address ishttp://localhost:1234. This README useskev-4bas an example identifier. Replace it with the identifier of your own decision model. - A speech to text service that gives you final transcript text for each speaker and a signal for the end of a turn. AWOL does not capture audio and does not transcribe. It starts from text. The
speech_finalevent from Deepgram is one example of an end of turn signal.
Install
npm install @justanotherkevin/awolCheck the model is ready
import { checkReady } from '@justanotherkevin/awol';
const readiness = await checkReady({
host: 'http://localhost:1234',
model: 'kev-4b',
signal: AbortSignal.timeout(5000),
});The result is one of these values:
ready: the model is loaded and can answer.not_loaded: LM Studio knows the model but it is not loaded. Runlms load kev-4b.not_found: LM Studio does not know a model with this identifier.unreachable: the server did not answer. Check that the LM Studio local server is running and that the host is right.
Quick start
import { classify, DecisionLoop } from '@justanotherkevin/awol';
type Speaker = 'them' | 'me';
const options = { host: 'http://localhost:1234', model: 'kev-4b' };
const loop = new DecisionLoop<Speaker>({
buildRequest: (speaker, text) => {
if (speaker === 'them') {
return {
state: { text },
questions: {
kind: {
type: 'choice',
instructions: 'Is this a short fact question or a hard question?',
criteria: {
short: 'A short question with a quick factual answer.',
hard: 'A question that needs reasoning or a long answer.',
},
},
},
};
}
return {
state: { text },
questions: {
topic: {
type: 'choice',
instructions: 'Which of these topics is the speaker choosing?',
criteria: {
pricing: 'The speaker picks pricing.',
schedule: 'The speaker picks the schedule.',
none: 'The speaker picks none of these topics.',
},
},
},
};
},
classify: (request, { signal }) => classify(request, { ...options, signal }),
onDecision: decision => {
if (!decision.answers) {
console.log(`${decision.speaker} failed: ${decision.failure}`);
return;
}
for (const [id, answer] of Object.entries(decision.answers)) {
if (typeof answer === 'number') continue;
const probability = answer.probabilities[answer.choice];
if (probability >= 0.6) {
console.log(`${decision.speaker} ${id}: ${answer.choice} (${probability})`);
}
}
},
});
speechToText.on('transcript', event => {
loop.transcript({ speaker: event.speaker, text: event.text, final: event.isFinal });
});
speechToText.on('speech_final', event => {
loop.endOfTurn(event.speaker);
});
process.on('SIGINT', () => loop.stop());speechToText stands for your own speech to text client. Any service that gives you text per speaker and an end of turn signal will work.
API reference
classify(request, options)
Sends one request to POST {host}/v1/systemone and returns a ClassifyResult. It never throws for server or network problems. It throws only if you abort it with your own signal.
Options:
host: the LM Studio address, for examplehttp://localhost:1234.model: the identifier of the decision model.signal: anAbortSignalthat cancels the request.timeoutMs: optional. The default is 4000.
A ClassifyRequest has state, an object with the facts the model can see, and questions, an object that maps a question id to a question.
checkReady(options)
Takes the same options as classify. Returns 'ready' | 'not_loaded' | 'not_found' | 'unreachable'.
DecisionLoop<S extends string>
S is the type of your speaker names.
new DecisionLoop<S>({
buildRequest(speaker: S, text: string): ClassifyRequest | null,
classify(request: ClassifyRequest, options: { signal: AbortSignal }): Promise<ClassifyResult>,
onDecision(decision: Decision<S>): void,
})buildRequestturns a speaker's text into a request. Returnnullto skip that turn.classifysends the request. Pass thesignalon toclassifyfrom this package.onDecisionreceives each decision.
Methods:
transcript({ speaker, text, final }): gives the loop some text. Only final, non empty text is kept. Kept pieces are joined with a space.endOfTurn(speaker): sends the kept text of that speaker. If there is no kept text, nothing is sent.stop(): cancels all running requests, drops their results and clears the kept text.
Decision<S>
{
speaker: S;
text: string;
request: ClassifyRequest;
answers: Record<string, ClassifierAnswer> | null;
failure: ClassifyFailureReason | null;
durationMs: number;
}When the request worked, answers is set and failure is null. When it failed, answers is null and failure says why.
Questions
A question with type: 'choice' and a criteria object asks the model to pick one option. The keys of criteria are the options and the values describe them.
{ type: 'choice', instructions: '...', criteria: { a: '...', b: '...' } }A question with only instructions is sent as a noul question. The model answers it with a single number.
{ instructions: '...' }Answers
- A
choicequestion gives{ choice: string; probabilities: Record<string, number> }.choiceis the chosen option andprobabilitieshas one number for every option. - A plain question gives a
number.
Failure reasons
timeout: the request took longer thantimeoutMs.network: the server could not be reached.status: the server answered with an error status. The result hasstatusand, when the server sent one, amessage.invalid: the server answered with a body that AWOL could not read.
Tips
- Keep one question per request. It gives the lowest delay.
- Send a warm up request after you load the model, because the first call is slow.
- Choose your probability thresholds from your own data.
License
MIT
