SPB Git

Repository Public MIT Selected

fake.mjs 1.4 KB 32 lines javascript

1/**2 * ─────────────────────────────────────────────3 *  SPB Git — Personal Git Platform4 * ─────────────────────────────────────────────5 *  Author  : Simon-Pierre Boucher6 *  Contact : contact@spboucher.ai7 *  File    : src/ai/providers/fake.mjs8 *  Purpose : AI provider — deterministic test double (only loadable under SPBGIT_ENV=test; never a production fallback)9 *  License : MIT © Simon-Pierre Boucher10 * ─────────────────────────────────────────────11 */1213/** Echoes the first cited chunk so tests can assert grounding + citation validation. */14export function createFakeProvider() {15  return {16    name: 'fake',17    model: 'fake-1',18    async complete({ prompt, maxTokens }) {19      const ids = [...prompt.matchAll(/<chunk id="(\d+)" path="([^"]+)" lines="(\d+)-(\d+)"/g)];20      const first = ids[0];21      const cite = first ? `[${first[2]}#L${first[3]}-L${first[4]}]` : '';22      const bogus = '[does/not/exist.txt#L1-L2]';23      return {24        text: `FAKE ANSWER grounded in ${ids.length} chunks ${cite} ${bogus}`.slice(0, maxTokens * 4),25        truncated: false,26        usage: { input: Math.ceil(prompt.length / 4), output: 32 },27        model: 'fake-1',28      };29    },30  };31}32
Files main
Menu

Theme