Add configurable SystemOne batching and release version 4.1.0
This commit is contained in:
parent
9a5404cb62
commit
7edae937b3
13 changed files with 400 additions and 31 deletions
|
|
@ -1,17 +1,22 @@
|
|||
export const path = '/v1/systemone';
|
||||
export function buildRequest(text, criterion, config) {
|
||||
const payload = {
|
||||
state: text,
|
||||
questions: { match: { type: 'noul', instructions: `Does this email satisfy the following criterion: ${criterion}` } }
|
||||
};
|
||||
return buildBatchRequest(text, [{ id: 'match', criterion }], config);
|
||||
}
|
||||
export function buildBatchRequest(text, questions, config) {
|
||||
const payload = { state: text, questions: Object.fromEntries(questions.map(({ id, criterion }) =>
|
||||
[id, { type: 'noul', instructions: `Does this email satisfy the following criterion: ${criterion}` }])) };
|
||||
if (config.model) payload.model = config.model;
|
||||
return payload;
|
||||
}
|
||||
export function parseResponse(result) {
|
||||
const answer = result?.answers?.match;
|
||||
export function parseResponse(result) { return parseAnswer(result, 'match'); }
|
||||
export function parseBatchResponse(result, questions) {
|
||||
return questions.map(({ id }) => parseAnswer(result, id));
|
||||
}
|
||||
function parseAnswer(result, id) {
|
||||
const answer = result?.answers?.[id];
|
||||
if (answer?.type !== 'noul' || typeof answer.noul !== 'number' ||
|
||||
!Number.isFinite(answer.noul) || answer.noul < 0 || answer.noul > 1) {
|
||||
throw new Error('SystemOne response must contain answers.match with type noul and a probability from 0 to 1.');
|
||||
throw new Error(`SystemOne response must contain answers.${id} with type noul and a probability from 0 to 1.`);
|
||||
}
|
||||
return { matched: null, reason: null, probability: answer.noul };
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue