fix(ts-sdk): send null instead of undefined when includeEntities is false (#476)
* fix(ts-sdk): send null instead of undefined when includeEntities is false When `includeEntities: false` was passed, the client serialized `entities` as `undefined`, which is stripped from JSON. The API then applied its default (`EntityIncludeOptions()` — enabled), silently ignoring the flag. Fix: send `null` explicitly when `includeEntities === false` so the API correctly interprets it as "disable entities". chunks and source_facts are unaffected since their API defaults are null (disabled), so omitting them from JSON produces the correct behaviour. Also adds integration tests covering all three states of includeEntities. * fix(ts-sdk): use toBeFalsy for null entity check in test
This commit is contained in:
parent
61bf428ba9
commit
15f4b8769b
2 changed files with 43 additions and 1 deletions
|
|
@ -286,7 +286,7 @@ export class HindsightClient {
|
|||
trace: options?.trace,
|
||||
query_timestamp: options?.queryTimestamp,
|
||||
include: {
|
||||
entities: options?.includeEntities ? { max_tokens: options?.maxEntityTokens ?? 500 } : undefined,
|
||||
entities: options?.includeEntities === false ? null : options?.includeEntities ? { max_tokens: options?.maxEntityTokens ?? 500 } : undefined,
|
||||
chunks: options?.includeChunks ? { max_tokens: options?.maxChunkTokens ?? 8192 } : undefined,
|
||||
source_facts: options?.includeSourceFacts ? { max_tokens: options?.maxSourceFactsTokens ?? 4096 } : undefined,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -413,6 +413,48 @@ describe('TestDeleteBank', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('TestRecallIncludeOptions', () => {
|
||||
let bankId: string;
|
||||
|
||||
beforeAll(async () => {
|
||||
bankId = randomBankId();
|
||||
await client.retainBatch(bankId, [
|
||||
{ content: 'Alice works at Google as a software engineer' },
|
||||
{ content: 'Bob is a researcher at OpenAI' },
|
||||
]);
|
||||
});
|
||||
|
||||
test('entities included by default', async () => {
|
||||
const response = await client.recall(bankId, 'Where does Alice work?');
|
||||
|
||||
expect(response).not.toBeNull();
|
||||
expect(response.results!.length).toBeGreaterThan(0);
|
||||
// entities should be present when includeEntities is not specified (default: true)
|
||||
expect(response.entities).toBeDefined();
|
||||
});
|
||||
|
||||
test('entities excluded when includeEntities is false', async () => {
|
||||
const response = await client.recall(bankId, 'Where does Alice work?', {
|
||||
includeEntities: false,
|
||||
});
|
||||
|
||||
expect(response).not.toBeNull();
|
||||
expect(response.results!.length).toBeGreaterThan(0);
|
||||
// entities should be absent when explicitly disabled
|
||||
expect(response.entities).toBeFalsy();
|
||||
});
|
||||
|
||||
test('entities included when includeEntities is true', async () => {
|
||||
const response = await client.recall(bankId, 'Where does Alice work?', {
|
||||
includeEntities: true,
|
||||
});
|
||||
|
||||
expect(response).not.toBeNull();
|
||||
expect(response.results!.length).toBeGreaterThan(0);
|
||||
expect(response.entities).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('TestMission', () => {
|
||||
test('set mission', async () => {
|
||||
const bankId = randomBankId();
|
||||
|
|
|
|||
Loading…
Reference in a new issue