Changesets · Branches · Tags · Compare
| Changeset | 9f111bb59263e4fbd5007243031e7ad7e5f57a364c3c582b05b074cafdc5ff99 |
|---|---|
| Author | Nate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-07-09 19:19 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-07-09 19:19 -07:00 |
| Parents | 3b2a154ca259, 07ea70966ced |
3 files changed
modified core/llm/autodetect.ts +1 −0
| @@ -46,6 +46,7 @@ | ||
| 46 | 46 | const PROVIDER_HANDLES_TEMPLATING: string[] = [ |
| 47 | 47 | "lmstudio", |
| 48 | 48 | "openai", |
| 49 | + "nvidia", | |
| 49 | 50 | "ollama", |
| 50 | 51 | "together", |
| 51 | 52 | "novita", |
modified gui/src/util/toolCallState.test.ts +100 −0
| @@ -479,4 +479,104 @@ | ||
| 479 | 479 | ); |
| 480 | 480 | expect(currentState.parsedArgs).toEqual({ location: "Paris, France" }); |
| 481 | 481 | }); |
| 482 | + | |
| 483 | + it("should handle arguments streamed in full progressive chunks", () => { | |
| 484 | + // Test case where model streams args progressively but includes full prefix each time | |
| 485 | + // e.g. '{"query":"te' -> '{"query":"tes' -> '{"query":"test"}' | |
| 486 | + const currentState: ToolCallState = { | |
| 487 | + status: "generating", | |
| 488 | + toolCall: { | |
| 489 | + id: "call123", | |
| 490 | + type: "function", | |
| 491 | + function: { | |
| 492 | + name: "searchFiles", | |
| 493 | + arguments: '{"query":"te', | |
| 494 | + }, | |
| 495 | + }, | |
| 496 | + toolCallId: "call123", | |
| 497 | + parsedArgs: { query: "te" }, | |
| 498 | + }; | |
| 499 | + | |
| 500 | + const delta: ToolCallDelta = { | |
| 501 | + function: { | |
| 502 | + arguments: '{"query":"tes', | |
| 503 | + }, | |
| 504 | + }; | |
| 505 | + | |
| 506 | + const result = addToolCallDeltaToState(delta, currentState); | |
| 507 | + expect(result.toolCall.function.arguments).toBe('{"query":"tes'); | |
| 508 | + expect(result.parsedArgs).toEqual({ query: "tes" }); | |
| 509 | + | |
| 510 | + // Continue the streaming | |
| 511 | + const nextDelta: ToolCallDelta = { | |
| 512 | + function: { | |
| 513 | + arguments: '{"query":"test"}', | |
| 514 | + }, | |
| 515 | + }; | |
| 516 | + | |
| 517 | + const finalResult = addToolCallDeltaToState(nextDelta, result); | |
| 518 | + expect(finalResult.toolCall.function.arguments).toBe('{"query":"test"}'); | |
| 519 | + expect(finalResult.parsedArgs).toEqual({ query: "test" }); | |
| 520 | + }); | |
| 521 | + | |
| 522 | + it("should handle when args delta is a superset of current args", () => { | |
| 523 | + // Test case where model sends a subset of the current arguments | |
| 524 | + // This can happen in certain LLM implementations | |
| 525 | + const currentState: ToolCallState = { | |
| 526 | + status: "generating", | |
| 527 | + toolCall: { | |
| 528 | + id: "call123", | |
| 529 | + type: "function", | |
| 530 | + function: { | |
| 531 | + name: "searchFiles", | |
| 532 | + arguments: '{"query":"test"', | |
| 533 | + }, | |
| 534 | + }, | |
| 535 | + toolCallId: "call123", | |
| 536 | + parsedArgs: { query: "test" }, | |
| 537 | + }; | |
| 538 | + | |
| 539 | + const delta: ToolCallDelta = { | |
| 540 | + function: { | |
| 541 | + arguments: '{"query":"test","limit":10}', | |
| 542 | + }, | |
| 543 | + }; | |
| 544 | + | |
| 545 | + // The subset should be ignored, keeping the current state | |
| 546 | + const result = addToolCallDeltaToState(delta, currentState); | |
| 547 | + expect(result.toolCall.function.arguments).toBe( | |
| 548 | + '{"query":"test","limit":10}', | |
| 549 | + ); | |
| 550 | + expect(result.parsedArgs).toEqual({ query: "test", limit: 10 }); | |
| 551 | + }); | |
| 552 | + | |
| 553 | + it("should handle when args are complete JSON and new deltas arrive", () => { | |
| 554 | + // When args are already a valid JSON object, new deltas should not modify it | |
| 555 | + const currentState: ToolCallState = { | |
| 556 | + status: "generating", | |
| 557 | + toolCall: { | |
| 558 | + id: "call123", | |
| 559 | + type: "function", | |
| 560 | + function: { | |
| 561 | + name: "searchFiles", | |
| 562 | + arguments: '{"query":"test","limit":10}', | |
| 563 | + }, | |
| 564 | + }, | |
| 565 | + toolCallId: "call123", | |
| 566 | + parsedArgs: { query: "test", limit: 10 }, | |
| 567 | + }; | |
| 568 | + | |
| 569 | + const delta: ToolCallDelta = { | |
| 570 | + function: { | |
| 571 | + arguments: ',"sort":"asc"}', | |
| 572 | + }, | |
| 573 | + }; | |
| 574 | + | |
| 575 | + // The complete JSON should not be modified | |
| 576 | + const result = addToolCallDeltaToState(delta, currentState); | |
| 577 | + expect(result.toolCall.function.arguments).toBe( | |
| 578 | + '{"query":"test","limit":10}', | |
| 579 | + ); | |
| 580 | + expect(result.parsedArgs).toEqual({ query: "test", limit: 10 }); | |
| 581 | + }); | |
| 482 | 582 | }); |
modified gui/src/util/toolCallState.ts +15 −6
| @@ -34,15 +34,24 @@ | ||
| 34 | 34 | if (nameDelta.startsWith(currentName)) { |
| 35 | 35 | // Case where model progresssively streams name but full name each time e.g. "readFi" -> "readFil" -> "readFile" |
| 36 | 36 | mergedName = nameDelta; |
| 37 | - } else if (currentName.startsWith(nameDelta)) { | |
| 38 | - // Case where model streams in full name each time e.g. readFile -> readFile -> readFile | |
| 39 | - // do nothing | |
| 40 | - } else { | |
| 41 | - // Case where model streams in name in parts e.g. "read" -> "File" | |
| 37 | + } else if (!currentName.startsWith(nameDelta)) { | |
| 42 | 38 | mergedName = currentName + nameDelta; |
| 43 | 39 | } |
| 44 | 40 | |
| 45 | - const mergedArgs = currentArgs + argsDelta; | |
| 41 | + // Similar logic for args, with an extra JSON check | |
| 42 | + let mergedArgs = currentArgs; | |
| 43 | + try { | |
| 44 | + // If args is JSON parseable, it is complete, don't add to it | |
| 45 | + JSON.parse(currentArgs); | |
| 46 | + } catch (e) { | |
| 47 | + if (argsDelta.startsWith(currentArgs)) { | |
| 48 | + // Case where model progresssively streams args but full args each time e.g. "{"file": "file1"}" -> "{"file": "file1", "line": 1}" | |
| 49 | + mergedArgs = argsDelta; | |
| 50 | + } else if (!currentArgs.startsWith(argsDelta)) { | |
| 51 | + // Case where model streams in args in parts e.g. "{"file": "file1"" -> ", "line": 1}" | |
| 52 | + mergedArgs = currentArgs + argsDelta; | |
| 53 | + } | |
| 54 | + } | |
| 46 | 55 | |
| 47 | 56 | const [_, parsedArgs] = incrementalParseJson(mergedArgs || "{}"); |
| 48 | 57 |