mirror of
https://github.com/laurent22/joplin.git
synced 2026-10-25 02:47:28 +00:00
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8905795ed1
commit
c51a2cb7e1
2 files changed
+15
-4
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { _internal, ChatCommands, runNoteChat } from './noteChat';
|
||||
import { ChatRole, ChatToolCall } from './types';
|
||||
import { ChatRole, ChatToolCall, ChatToolMessage } from './types';
|
||||
import { expectThrow, setupDatabase, switchClient, withWarningSilenced } from '../../testing/test-utils';
|
||||
import Setting from '../../models/Setting';
|
||||
import { NoteContext } from './tools/types';
|
||||
@@ -159,6 +159,20 @@ describe('noteChat', () => {
|
||||
}, 'aiNoteTooLarge');
|
||||
});
|
||||
|
||||
test('assertWithinTokenBudget should count tool results once', async () => {
|
||||
const toolResult = (content: string): ChatToolMessage => ({
|
||||
role: ChatRole.Tool, content, toolName: 'editor_readNoteBody', toolCallId: 'call-1', userDescription: '', isEdit: false, isError: false,
|
||||
});
|
||||
|
||||
// About 75 tokens
|
||||
_internal.assertWithinTokenBudget([toolResult('Testing... '.repeat(27))], 100);
|
||||
|
||||
await expectThrow(async () => {
|
||||
// About 125 tokens
|
||||
_internal.assertWithinTokenBudget([toolResult('Testing... '.repeat(45))], 100);
|
||||
}, 'aiNoteTooLarge');
|
||||
});
|
||||
|
||||
test('runTools should describe successful edit operations', async () => {
|
||||
const toolCalls: ChatToolCall[] = [
|
||||
{ toolName: 'editor_appendToNote', callId: 'call-1', arguments: { text: 'Test.' }, parseError: null },
|
||||
|
||||
@@ -241,9 +241,6 @@ const assertWithinTokenBudget = (history: ChatMessage[], budget: number) => {
|
||||
if (message.role === ChatRole.Assistant) {
|
||||
totalTokens += estimateToolCallTokens(message.toolCalls ?? []);
|
||||
}
|
||||
if (message.role === ChatRole.Tool) {
|
||||
totalTokens += estimateTokens(message.content);
|
||||
}
|
||||
}
|
||||
|
||||
if (totalTokens > budget) {
|
||||
|
||||
Reference in new issue
Block a user