File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -84,6 +84,9 @@ export function isParseableJson(text: string): boolean {
8484export function mergePrefill ( prefill : string , raw : string ) : string {
8585 const trimmed = raw . trimStart ( )
8686 const trimmedPrefill = prefill . trimEnd ( )
87+ if ( extractJsonFence ( trimmed ) !== undefined ) {
88+ return raw
89+ }
8790 if ( trimmed . startsWith ( trimmedPrefill ) ) {
8891 return raw
8992 }
Original file line number Diff line number Diff line change @@ -46,6 +46,11 @@ describe('json', () => {
4646 expect ( mergePrefill ( '{"a":' , '{"a":1}' ) ) . toBe ( '{"a":1}' )
4747 } )
4848
49+ it ( 'does not prepend a prefill to a complete fenced response' , ( ) => {
50+ const raw = '```json\n{"a":1}\n```'
51+ expect ( mergePrefill ( '{"a":' , raw ) ) . toBe ( raw )
52+ } )
53+
4954 it ( 'wraps an array-element continuation of a nested-array prefill' , ( ) => {
5055 // The model continued from `{"updates":[` without echoing it, so raw alone
5156 // is unbalanced (`{…}] }`) but prefill+raw parses.
You can’t perform that action at this time.
0 commit comments