Skip to content

Commit 84cf23a

Browse files
authored
Fixed nested description (#7)
Fix estimate for nested descriptions --------- Co-authored-by: Piotr Kuczko <[email protected]>
1 parent 1ce17fa commit 84cf23a

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
.*
2+
!.gitignore
3+
!.github
14
node_modules/
25
dist/

src/functions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function formatFunctionDefinitions(functions: FunctionDef[]) {
6666
function formatObjectProperties(obj: ObjectProp, indent: number): string {
6767
const lines = [];
6868
for (const [name, param] of Object.entries(obj.properties ?? {})) {
69-
if (param.description) {
69+
if (param.description && indent < 2) {
7070
lines.push(`// ${param.description}`);
7171
}
7272
if (obj.required?.includes(name)) {

tests/token-counts.test.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,83 @@ const TEST_CASES: Example[] = [
304304
],
305305
tokens: 106,
306306
},
307+
{
308+
messages: [{ role: 'user', content: 'hello' }],
309+
functions: [
310+
{
311+
name: 'function',
312+
description: 'description',
313+
parameters: {
314+
type: 'object',
315+
properties: {
316+
quality: {
317+
type: 'object',
318+
properties: {
319+
pros: {
320+
type: 'array',
321+
items: {
322+
type: 'string',
323+
},
324+
description: 'Write 3 points why this text is well written',
325+
}
326+
},
327+
}
328+
},
329+
}
330+
}],
331+
tokens: 46,
332+
},
333+
{
334+
messages: [{ role: 'user', content: 'hello' }],
335+
functions: [
336+
{
337+
name: 'function',
338+
description: 'desctiption1',
339+
parameters: {
340+
type: 'object',
341+
description: 'desctiption2',
342+
properties: {
343+
mainField: {
344+
type: 'string',
345+
description: 'description3',
346+
},
347+
'field number one': {
348+
type: 'object',
349+
description: 'description4',
350+
properties: {
351+
yesNoField: {
352+
type: 'string',
353+
description: 'description5',
354+
enum: [
355+
'Yes',
356+
'No',
357+
],
358+
},
359+
howIsInteresting: {
360+
type: 'string',
361+
description: 'description6',
362+
},
363+
scoreInteresting: {
364+
type: 'number',
365+
description: 'description7',
366+
},
367+
isInteresting: {
368+
type: 'string',
369+
description: 'description8',
370+
enum: [
371+
'Yes',
372+
'No',
373+
],
374+
},
375+
},
376+
},
377+
},
378+
379+
}
380+
}
381+
],
382+
tokens: 96,
383+
}
307384
];
308385

309386
const validateAll = false;

0 commit comments

Comments
 (0)