feat: add resident BingShuo TCS controller
This commit is contained in:
parent
125ea896c8
commit
bc169824fc
9 changed files with 890 additions and 1 deletions
34
server-tools/bingshuo-tcs-controller/model-client.test.mjs
Normal file
34
server-tools/bingshuo-tcs-controller/model-client.test.mjs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { DeepSeekJsonClient, extractJson } from "./model-client.mjs";
|
||||
|
||||
test("extractJson accepts strict JSON and fenced JSON", () => {
|
||||
assert.deepEqual(extractJson('{"ok":true}'), { ok: true });
|
||||
assert.deepEqual(extractJson('```json\n{"ok":true}\n```'), { ok: true });
|
||||
});
|
||||
|
||||
test("DeepSeek client sends the secret only as authorization and returns JSON", async () => {
|
||||
let observed;
|
||||
const client = new DeepSeekJsonClient({
|
||||
apiKey: "test-secret",
|
||||
apiUrl: "https://model.invalid/v1",
|
||||
model: "fixture-model",
|
||||
fetchImpl: async (url, options) => {
|
||||
observed = { url, options };
|
||||
return {
|
||||
ok: true,
|
||||
async json() {
|
||||
return { choices: [{ message: { content: '{"decision":"ok"}' } }] };
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
const result = await client.generate({
|
||||
role: "fixture",
|
||||
instruction: "return json",
|
||||
input: { event: "test" },
|
||||
});
|
||||
assert.deepEqual(result, { decision: "ok" });
|
||||
assert.equal(observed.options.headers.authorization, "Bearer test-secret");
|
||||
assert.equal(observed.options.body.includes("test-secret"), false);
|
||||
});
|
||||
Loading…
Reference in a new issue