mdi-llmkit 1.0.1 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -175,170 +175,170 @@ export const jsonSurgery = async (openaiClient, obj, modificationInstructions, o
175
175
  obj = JSON.parse(JSON.stringify(obj));
176
176
  const timeStarted = Date.now();
177
177
  const convoBase = new GptConversation([], { openaiClient });
178
- convoBase.addDeveloperMessage(`
179
- You are an expert software developer AI assistant.
180
- The user will show you a JSON object and provide modification instructions.
181
- The modification instructions might not be entirely straightforward, so the
182
- process of implementing these changes may require careful thought and planning.
183
- Through a series of individual insertions, deletions, or updates, you will modify the JSON object
184
- to satisfy the user's instructions.
185
- You will not be doing this alone. I will be holding your hand through the entire process,
186
- providing feedback and guidance after each modification. You will also be getting verification
187
- from the system itself, to ensure that your modifications are valid and correct.
178
+ convoBase.addDeveloperMessage(`
179
+ You are an expert software developer AI assistant.
180
+ The user will show you a JSON object and provide modification instructions.
181
+ The modification instructions might not be entirely straightforward, so the
182
+ process of implementing these changes may require careful thought and planning.
183
+ Through a series of individual insertions, deletions, or updates, you will modify the JSON object
184
+ to satisfy the user's instructions.
185
+ You will not be doing this alone. I will be holding your hand through the entire process,
186
+ providing feedback and guidance after each modification. You will also be getting verification
187
+ from the system itself, to ensure that your modifications are valid and correct.
188
188
  `);
189
- convoBase.addUserMessage(`
190
-
191
- Here is the JSON object to modify, in its original state prior to any modifications.
192
- It has been formatted with placemarks (comments) to indicate the positions of elements for
193
- better readability and easier navigation.
194
-
195
- ---
196
-
197
- ${placemarkedJSONStringify(obj, 2, options.skippedKeys)}
189
+ convoBase.addUserMessage(`
190
+
191
+ Here is the JSON object to modify, in its original state prior to any modifications.
192
+ It has been formatted with placemarks (comments) to indicate the positions of elements for
193
+ better readability and easier navigation.
194
+
195
+ ---
196
+
197
+ ${placemarkedJSONStringify(obj, 2, options.skippedKeys)}
198
198
  `);
199
199
  if (options.schemaDescription) {
200
- convoBase.addUserMessage(`
201
- Here is the schema definition for the JSON object, so that you know the expected structure
202
- and data types of its properties. Make sure that your final results conform to this schema.
203
- DO NOT introduce any properties or values that violate this schema!
204
-
205
- ---
206
-
207
- ${options.schemaDescription}
200
+ convoBase.addUserMessage(`
201
+ Here is the schema definition for the JSON object, so that you know the expected structure
202
+ and data types of its properties. Make sure that your final results conform to this schema.
203
+ DO NOT introduce any properties or values that violate this schema!
204
+
205
+ ---
206
+
207
+ ${options.schemaDescription}
208
208
  `);
209
209
  }
210
- convoBase.addUserMessage(`
211
-
212
- Here are the modification instructions.
213
-
214
- ---
215
-
216
- ${modificationInstructions}
210
+ convoBase.addUserMessage(`
211
+
212
+ Here are the modification instructions.
213
+
214
+ ---
215
+
216
+ ${modificationInstructions}
217
217
  `);
218
- convoBase.addDeveloperMessage(`
219
- Before we begin, please provide a detailed plan outlining the specific steps you will take to
220
- implement the requested modifications to the JSON object. This plan should break down the
221
- modification instructions into a clear sequence of actions that you will perform, where each
222
- action corresponds to a specific change in the JSON structure -- either the adding, removing,
223
- or updating of specific individual properties or values.
224
-
225
- Your response should start with "Modification Plan:" followed by the detailed plan.
218
+ convoBase.addDeveloperMessage(`
219
+ Before we begin, please provide a detailed plan outlining the specific steps you will take to
220
+ implement the requested modifications to the JSON object. This plan should break down the
221
+ modification instructions into a clear sequence of actions that you will perform, where each
222
+ action corresponds to a specific change in the JSON structure -- either the adding, removing,
223
+ or updating of specific individual properties or values.
224
+
225
+ Your response should start with "Modification Plan:" followed by the detailed plan.
226
226
  `);
227
227
  await convoBase.submit();
228
- convoBase.addSystemMessage(`
229
- NAVIGATING THE JSON OBJECT AND JSON PATHS
230
-
231
- You have probably already noticed that the JSON object is annotated with placemarks
232
- (comments) to indicate the positions of objects and indexes for better readability.
233
- The syntax of these placemarks is quite straightforward, as it follows JavaScript/TypeScript
234
- notation for accessing properties and array elements.
235
-
236
- E.g. root["items"][0]["keywords"][1] refers to the second element of the "keywords" array
237
- of the first element of the "items" array in the root object.
238
-
239
- When prompted for a location in the JSON object, you'll emit a JSON list that corresponds
240
- to the path to that location, where each element in the list is either a property name (string)
241
- or an array index (number).
242
-
243
- Thus, the path to root["items"][0]["keywords"][1] would be represented as:
244
- json_path = ["items", 0, "keywords", 1]
228
+ convoBase.addSystemMessage(`
229
+ NAVIGATING THE JSON OBJECT AND JSON PATHS
230
+
231
+ You have probably already noticed that the JSON object is annotated with placemarks
232
+ (comments) to indicate the positions of objects and indexes for better readability.
233
+ The syntax of these placemarks is quite straightforward, as it follows JavaScript/TypeScript
234
+ notation for accessing properties and array elements.
235
+
236
+ E.g. root["items"][0]["keywords"][1] refers to the second element of the "keywords" array
237
+ of the first element of the "items" array in the root object.
238
+
239
+ When prompted for a location in the JSON object, you'll emit a JSON list that corresponds
240
+ to the path to that location, where each element in the list is either a property name (string)
241
+ or an array index (number).
242
+
243
+ Thus, the path to root["items"][0]["keywords"][1] would be represented as:
244
+ json_path = ["items", 0, "keywords", 1]
245
245
  `);
246
- convoBase.addSystemMessage(`
247
- INSTRUCTIONS FOR MODIFICATION OPERATIONS
248
-
249
- You will be implementing the modification plan through a series of modification operations.
250
- By incrementally applying these operations, we will arrive at the final modified JSON object that
251
- satisfies the modification instructions.
252
-
253
- We will be permitted to take multiple passes over the JSON object, and make multiple
254
- modifications, so don't feel obligated to get everything right in the first few steps.
255
- We will have plenty of opportunities to iteratively develop the final result. Your initial list
256
- of operations to execute doesn't necessarily need to achieve the final result; if it merely
257
- "walks" towards the final result, that's perfectly fine, as we'll be able to continue to "walk"
258
- further towards the final result in subsequent iterations.
259
-
260
- Structure of a Modification Operation:
261
-
262
- - **json_path_of_parent**: A JSON path indicating the location in the JSON object where the
263
- modification should be applied. We call this the "parent" location because we specify
264
- the key or index within the parent later. For example, if you want to set the string
265
- property "foo" to the value "bar" on the root object (i.e. root["foo"]="bar"), then
266
- json_path_of_parent would be an empty list [], since the parent of "foo" is the root object.
267
- If you want to append a new string value into the "keywords" array of the first
268
- element of the "items" array (i.e. root["items"][0]["keywords"].push("new_keyword")), then
269
- json_path_of_parent would be ["items", 0, "keywords"], since the parent of the new element
270
- is the "keywords" array itself. The syntax of the json_path should follow the same notation
271
- as described in the "Navigating the JSON Object and JSON Paths" section above.
272
-
273
- - **key_or_index**: The key (string) or array index (number) of the property or element to modify.
274
- If the parent location (json_path_of_parent) is an object, then this will be a string key.
275
- If the parent location is an array, then this will be a numeric index.
276
- SPECIAL: If you're using the "append" action (see below) to add a new element to the end of
277
- an array, then key_or_index is ignored; set it to -1 to indicate to yourself that it's
278
- irrelevant.
279
-
280
- - **action**: The type of modification to perform. This can be one of the following values:
281
- - "delete": Delete the specified property or array element. (The "data" field is ignored,
282
- and should be set to null.) This "delete" action is functionally equivalent to
283
- \`delete parent[key]\` for objects, or \`parent.splice(index, 1)\` for arrays.
284
- - "assign": Set the property or element to a new value. If the parent is an array, then the
285
- "assign" action will replace the existing element at the specified index. If the parent
286
- is an object, then the "assign" action will set the value of the specified key, replacing
287
- any existing value for that key if it already exists, or creating a new key-value pair if
288
- the key does not already exist. This is functionally equivalent to:
289
- \`parent[key] = data\` for objects, or
290
- \`parent[index] = data\` for arrays.
291
- - "append": Applicable only when the parent object is an array. Append a new element to the
292
- end of the array. The "key_or_index" field is ignored. This is functionally equivalent to:
293
- \`parent.push(data)\`.
294
- - "insert": Applicable only when the parent object is an array. Insert a new element at the
295
- specified index in the array. This is functionally equivalent to:
296
- \`parent.splice(index, 0, data)\`.
297
- - "rename": Applicable only when the parent object is an object. Rename a property from the
298
- old key name (specified in "key_or_index") to a new key name. The "new_key_name" field
299
- (see below) *must* be provided. The "data" field is ignored for this action; you should
300
- just set it to null. This is functionally equivalent to:
301
- \`parent[new_key_name] = parent[key_or_index]; delete parent[key_or_index]\`.
302
-
303
- - **new_key_name**: Applicable only for the "rename" action. This field specifies the new key name
304
- to rename a property to. For all other actions, this field is ignored and should just be set
305
- to an empty string.
306
-
307
- - **data**: The new value to set for "assign", "append", or "insert" actions. This field comes in
308
- the following forms:
309
-
310
- - **null**: You should set the data field to null when the action does not require a value,
311
- such as "delete" or "rename". For all other actions, the data field cannot be null.
312
-
313
- - **inline_value**: You explicitly write out the value to set. The value you construct will be
314
- one of the following:
315
- - A primitive value (string, number, boolean, null)
316
- - An empty object ({}). This is useful for gradually building up complex objects through
317
- a series of subsequent modifications.
318
- - An empty array ([]). This is useful for gradually building up complex collections
319
- through a series of subsequent modifications.
320
- - An array whose elements are all either primitive values or empty objects/arrays. This is
321
- useful for adding multiple related elements at once. If the array contains empty
322
- objects/arrays, you can fill these in with actual values in subsequent modifications,
323
- if needed.
324
- - An object whose values are all either primitive values or empty objects/arrays. Again,
325
- just like with arrays, if the object contains empty objects/arrays, you can fill these
326
- in with actual values in subsequent modifications, if needed.
327
- Note that "value" cannot recursively describe deeply nested structures in one step; it can
328
- only describe at most a single layer of nesting. That's okay; you can build up complex
329
- nested structures through a series of modifications, gradually filling in more and more
330
- details with each modification. Just make sure to provide detailed notes about your plans
331
- and intentions with each modification, so that we can keep track of the overall plan and
332
- ensure that we're on the right track.
333
-
334
- - **json_path_of_copy_source**: If you need to construct a deeply nested object, and there
335
- happens to be a source object or array elsewhere in the JSON that already has a very
336
- similar (or identical) structure, you can specify the JSON path to that source object
337
- or array here. This can be a handy shortcut for creating complex structures without
338
- having to manually specify every detail. PRO TIP: This is also a great way to **move**
339
- existing structures around within the JSON, by copying from one path and then deleting
340
- the original -- this makes moving a structure from one place to another a two-step process
341
- instead of a long series of inline_value assignments.
246
+ convoBase.addSystemMessage(`
247
+ INSTRUCTIONS FOR MODIFICATION OPERATIONS
248
+
249
+ You will be implementing the modification plan through a series of modification operations.
250
+ By incrementally applying these operations, we will arrive at the final modified JSON object that
251
+ satisfies the modification instructions.
252
+
253
+ We will be permitted to take multiple passes over the JSON object, and make multiple
254
+ modifications, so don't feel obligated to get everything right in the first few steps.
255
+ We will have plenty of opportunities to iteratively develop the final result. Your initial list
256
+ of operations to execute doesn't necessarily need to achieve the final result; if it merely
257
+ "walks" towards the final result, that's perfectly fine, as we'll be able to continue to "walk"
258
+ further towards the final result in subsequent iterations.
259
+
260
+ Structure of a Modification Operation:
261
+
262
+ - **json_path_of_parent**: A JSON path indicating the location in the JSON object where the
263
+ modification should be applied. We call this the "parent" location because we specify
264
+ the key or index within the parent later. For example, if you want to set the string
265
+ property "foo" to the value "bar" on the root object (i.e. root["foo"]="bar"), then
266
+ json_path_of_parent would be an empty list [], since the parent of "foo" is the root object.
267
+ If you want to append a new string value into the "keywords" array of the first
268
+ element of the "items" array (i.e. root["items"][0]["keywords"].push("new_keyword")), then
269
+ json_path_of_parent would be ["items", 0, "keywords"], since the parent of the new element
270
+ is the "keywords" array itself. The syntax of the json_path should follow the same notation
271
+ as described in the "Navigating the JSON Object and JSON Paths" section above.
272
+
273
+ - **key_or_index**: The key (string) or array index (number) of the property or element to modify.
274
+ If the parent location (json_path_of_parent) is an object, then this will be a string key.
275
+ If the parent location is an array, then this will be a numeric index.
276
+ SPECIAL: If you're using the "append" action (see below) to add a new element to the end of
277
+ an array, then key_or_index is ignored; set it to -1 to indicate to yourself that it's
278
+ irrelevant.
279
+
280
+ - **action**: The type of modification to perform. This can be one of the following values:
281
+ - "delete": Delete the specified property or array element. (The "data" field is ignored,
282
+ and should be set to null.) This "delete" action is functionally equivalent to
283
+ \`delete parent[key]\` for objects, or \`parent.splice(index, 1)\` for arrays.
284
+ - "assign": Set the property or element to a new value. If the parent is an array, then the
285
+ "assign" action will replace the existing element at the specified index. If the parent
286
+ is an object, then the "assign" action will set the value of the specified key, replacing
287
+ any existing value for that key if it already exists, or creating a new key-value pair if
288
+ the key does not already exist. This is functionally equivalent to:
289
+ \`parent[key] = data\` for objects, or
290
+ \`parent[index] = data\` for arrays.
291
+ - "append": Applicable only when the parent object is an array. Append a new element to the
292
+ end of the array. The "key_or_index" field is ignored. This is functionally equivalent to:
293
+ \`parent.push(data)\`.
294
+ - "insert": Applicable only when the parent object is an array. Insert a new element at the
295
+ specified index in the array. This is functionally equivalent to:
296
+ \`parent.splice(index, 0, data)\`.
297
+ - "rename": Applicable only when the parent object is an object. Rename a property from the
298
+ old key name (specified in "key_or_index") to a new key name. The "new_key_name" field
299
+ (see below) *must* be provided. The "data" field is ignored for this action; you should
300
+ just set it to null. This is functionally equivalent to:
301
+ \`parent[new_key_name] = parent[key_or_index]; delete parent[key_or_index]\`.
302
+
303
+ - **new_key_name**: Applicable only for the "rename" action. This field specifies the new key name
304
+ to rename a property to. For all other actions, this field is ignored and should just be set
305
+ to an empty string.
306
+
307
+ - **data**: The new value to set for "assign", "append", or "insert" actions. This field comes in
308
+ the following forms:
309
+
310
+ - **null**: You should set the data field to null when the action does not require a value,
311
+ such as "delete" or "rename". For all other actions, the data field cannot be null.
312
+
313
+ - **inline_value**: You explicitly write out the value to set. The value you construct will be
314
+ one of the following:
315
+ - A primitive value (string, number, boolean, null)
316
+ - An empty object ({}). This is useful for gradually building up complex objects through
317
+ a series of subsequent modifications.
318
+ - An empty array ([]). This is useful for gradually building up complex collections
319
+ through a series of subsequent modifications.
320
+ - An array whose elements are all either primitive values or empty objects/arrays. This is
321
+ useful for adding multiple related elements at once. If the array contains empty
322
+ objects/arrays, you can fill these in with actual values in subsequent modifications,
323
+ if needed.
324
+ - An object whose values are all either primitive values or empty objects/arrays. Again,
325
+ just like with arrays, if the object contains empty objects/arrays, you can fill these
326
+ in with actual values in subsequent modifications, if needed.
327
+ Note that "value" cannot recursively describe deeply nested structures in one step; it can
328
+ only describe at most a single layer of nesting. That's okay; you can build up complex
329
+ nested structures through a series of modifications, gradually filling in more and more
330
+ details with each modification. Just make sure to provide detailed notes about your plans
331
+ and intentions with each modification, so that we can keep track of the overall plan and
332
+ ensure that we're on the right track.
333
+
334
+ - **json_path_of_copy_source**: If you need to construct a deeply nested object, and there
335
+ happens to be a source object or array elsewhere in the JSON that already has a very
336
+ similar (or identical) structure, you can specify the JSON path to that source object
337
+ or array here. This can be a handy shortcut for creating complex structures without
338
+ having to manually specify every detail. PRO TIP: This is also a great way to **move**
339
+ existing structures around within the JSON, by copying from one path and then deleting
340
+ the original -- this makes moving a structure from one place to another a two-step process
341
+ instead of a long series of inline_value assignments.
342
342
  `);
343
343
  convoBase.addDeveloperMessage(`Alrighty then. Let's get to work!`);
344
344
  const operationsDoneSoFar = [];
@@ -368,74 +368,74 @@ Structure of a Modification Operation:
368
368
  numIterations > options.giveUpAfterIterations) {
369
369
  throw new JSONSurgeryError(`Giving up after ${options.giveUpAfterIterations}. Maximum iterations reached. `, obj);
370
370
  }
371
- convo.addUserMessage(`
372
- CURRENT STATUS:
373
- We've been processing for ${secondsElapsed} seconds.
374
- We've performed ${operationsDoneSoFar.length} operations across ${numIterations - 1} iterations.
371
+ convo.addUserMessage(`
372
+ CURRENT STATUS:
373
+ We've been processing for ${secondsElapsed} seconds.
374
+ We've performed ${operationsDoneSoFar.length} operations across ${numIterations - 1} iterations.
375
375
  `);
376
376
  if (operationsDoneSoFar.length > 0) {
377
377
  let msgOpsSoFar = ``;
378
378
  for (let i = 0; i < operationsDoneSoFar.length; i++) {
379
379
  msgOpsSoFar += `${i + 1}. ${operationsDoneSoFar[i]}\n`;
380
380
  }
381
- convo.addUserMessage(`
382
- Here are the operations that we've performed so far:
383
- ${msgOpsSoFar}
381
+ convo.addUserMessage(`
382
+ Here are the operations that we've performed so far:
383
+ ${msgOpsSoFar}
384
384
  `);
385
385
  }
386
386
  convo.addUserMessage({
387
387
  role: 'user',
388
- content: `
389
- Here is the JSON object in its current state, with our modifications up to this point applied.
390
-
391
- ---
392
-
393
- ${placemarkedJSONStringify(obj, 2, options.skippedKeys)}
388
+ content: `
389
+ Here is the JSON object in its current state, with our modifications up to this point applied.
390
+
391
+ ---
392
+
393
+ ${placemarkedJSONStringify(obj, 2, options.skippedKeys)}
394
394
  `,
395
395
  });
396
396
  convo.addUserMessage({
397
397
  role: 'user',
398
- content: `
399
- Just to help re-establish context from previous iterations, here is the last operation we
400
- performed on this JSON object:
401
- ${operationLast}
402
-
403
- Here's what we were planning to do next:
404
- ${operationNext}
398
+ content: `
399
+ Just to help re-establish context from previous iterations, here is the last operation we
400
+ performed on this JSON object:
401
+ ${operationLast}
402
+
403
+ Here's what we were planning to do next:
404
+ ${operationNext}
405
405
  `,
406
406
  });
407
407
  if (!operationLastWasSuccessful) {
408
408
  convo.addDeveloperMessage({
409
409
  role: 'user',
410
- content: `
411
- !CRITICAL: The last operation we attempted FAILED! DO NOT DO THE SAME OPERATION AGAIN!
412
- Think of a *different* operation to perform. Think of a different *way* to perform
413
- the modifications that we need to make. Break them up over different steps, or
414
- re-think your approach, or SOMETHING. Just DO NOT keep trying to do the same thing
415
- over and over again expecting a different result.
410
+ content: `
411
+ !CRITICAL: The last operation we attempted FAILED! DO NOT DO THE SAME OPERATION AGAIN!
412
+ Think of a *different* operation to perform. Think of a different *way* to perform
413
+ the modifications that we need to make. Break them up over different steps, or
414
+ re-think your approach, or SOMETHING. Just DO NOT keep trying to do the same thing
415
+ over and over again expecting a different result.
416
416
  `,
417
417
  });
418
418
  }
419
419
  }
420
- convo.addDeveloperMessage(`
421
- Refer to the "Instructions for Modification Operations" section above for the
422
- structure of a modification operation.
423
-
424
- Based on the overall modification plan and the current state of the JSON object,
425
- determine and describe the next modifications to apply to the JSON object. Your
426
- output for now should just be plain English. Later, when I ask you to, you'll
427
- formalize it into a JSON object -- but for now, just talk your way through it.
428
-
429
- If the modification instructions require multiple changes to the JSON object, you can describe
430
- multiple modifications to apply in this step. You can also break down a complex modification into
431
- a series of simpler modifications that can be applied incrementally, if that makes it easier to
432
- implement the overall modification instructions correctly. Just make sure to be very clear and
433
- detailed in describing your intended modifications, so that we can ensure that we're on the
434
- right track and that the modifications you propose are correctly implementing the modification
435
- instructions.
436
-
437
- If the modification instructions have already been fully satisfied and no further modifications
438
- are needed, then just say that we're done and don't propose any further modifications.
420
+ convo.addDeveloperMessage(`
421
+ Refer to the "Instructions for Modification Operations" section above for the
422
+ structure of a modification operation.
423
+
424
+ Based on the overall modification plan and the current state of the JSON object,
425
+ determine and describe the next modifications to apply to the JSON object. Your
426
+ output for now should just be plain English. Later, when I ask you to, you'll
427
+ formalize it into a JSON object -- but for now, just talk your way through it.
428
+
429
+ If the modification instructions require multiple changes to the JSON object, you can describe
430
+ multiple modifications to apply in this step. You can also break down a complex modification into
431
+ a series of simpler modifications that can be applied incrementally, if that makes it easier to
432
+ implement the overall modification instructions correctly. Just make sure to be very clear and
433
+ detailed in describing your intended modifications, so that we can ensure that we're on the
434
+ right track and that the modifications you propose are correctly implementing the modification
435
+ instructions.
436
+
437
+ If the modification instructions have already been fully satisfied and no further modifications
438
+ are needed, then just say that we're done and don't propose any further modifications.
439
439
  `);
440
440
  await convo.submit();
441
441
  await convo.submit(undefined, undefined, {
@@ -443,12 +443,12 @@ are needed, then just say that we're done and don't propose any further modifica
443
443
  format: {
444
444
  type: 'json_schema',
445
445
  name: 'json_object_modifications',
446
- description: `
447
- A JSON formalization of the next set of modifications to apply to the JSON object,
448
- as we have just determined and described. If there are multiple modifications to apply,
449
- you can include all of them in this JSON object. If there are no modifications to apply
450
- because the modification instructions have already been fully satisfied, then set the
451
- "modifications" field to an empty list.
446
+ description: `
447
+ A JSON formalization of the next set of modifications to apply to the JSON object,
448
+ as we have just determined and described. If there are multiple modifications to apply,
449
+ you can include all of them in this JSON object. If there are no modifications to apply
450
+ because the modification instructions have already been fully satisfied, then set the
451
+ "modifications" field to an empty list.
452
452
  `,
453
453
  schema: {
454
454
  type: 'object',
@@ -478,19 +478,19 @@ because the modification instructions have already been fully satisfied, then se
478
478
  properties: {
479
479
  inline_value: {
480
480
  ...JSON_SCHEMA_SET_VALUE,
481
- description: `
482
- The new value to set for "assign", "append", or "insert" actions.
483
- For "delete" and "rename" actions, this field is ignored and should be set to null.
484
- This can be one of the following:
485
- - A primitive value (string, number, boolean, null)
486
- - An empty object ({}).
487
- - An empty array ([]).
488
- - An array whose elements are all either primitive values or empty objects/arrays.
489
- - An object(*) whose values are all either primitive values or empty objects/arrays.
490
- (*) NOTE: Due to some limitations in our JSON schema processor, we cannot have you
491
- provide an object with arbitrary keys directly. Instead, please provide an array of
492
- key-value pair objects. I know it *looks like* an array, but we'll interpret it as
493
- an object.
481
+ description: `
482
+ The new value to set for "assign", "append", or "insert" actions.
483
+ For "delete" and "rename" actions, this field is ignored and should be set to null.
484
+ This can be one of the following:
485
+ - A primitive value (string, number, boolean, null)
486
+ - An empty object ({}).
487
+ - An empty array ([]).
488
+ - An array whose elements are all either primitive values or empty objects/arrays.
489
+ - An object(*) whose values are all either primitive values or empty objects/arrays.
490
+ (*) NOTE: Due to some limitations in our JSON schema processor, we cannot have you
491
+ provide an object with arbitrary keys directly. Instead, please provide an array of
492
+ key-value pair objects. I know it *looks like* an array, but we'll interpret it as
493
+ an object.
494
494
  `,
495
495
  },
496
496
  },
@@ -552,16 +552,16 @@ an object.
552
552
  }
553
553
  // Kick it back for further processing.
554
554
  operationLastWasSuccessful = false;
555
- let actionDesc = `
556
- ERROR: Validation failure on attempted exit.
557
- We thought we had finished processing, but the object didn't pass an automated
558
- validation check. This is often the result of undocumented requirements,
559
- and isn't necessarily because you did anything wrong. Nonetheless, these remaining
560
- issues must be addressed before we can consider the object valid.)
561
-
562
- The validator returned the following errors:
563
-
564
- - ${validationErrors.join('\n -')}
555
+ let actionDesc = `
556
+ ERROR: Validation failure on attempted exit.
557
+ We thought we had finished processing, but the object didn't pass an automated
558
+ validation check. This is often the result of undocumented requirements,
559
+ and isn't necessarily because you did anything wrong. Nonetheless, these remaining
560
+ issues must be addressed before we can consider the object valid.)
561
+
562
+ The validator returned the following errors:
563
+
564
+ - ${validationErrors.join('\n -')}
565
565
  `;
566
566
  operationsDoneSoFar.push(actionDesc);
567
567
  operationLast = actionDesc;
@@ -649,67 +649,67 @@ The validator returned the following errors:
649
649
  else {
650
650
  throw new Error(`Unknown action: ${action}`);
651
651
  }
652
- convo.addSystemMessage(`
653
- The following modification was applied to the JSON object without any errors:
654
-
655
- json_path_of_parent: ${JSON.stringify(json_path_of_parent)}
656
- key_or_index: ${JSON.stringify(key_or_index)}
657
- action: ${JSON.stringify(action)}
658
- new_key_name: ${JSON.stringify(new_key_name)}
659
- value: ${JSON.stringify(value, null, 2)}
652
+ convo.addSystemMessage(`
653
+ The following modification was applied to the JSON object without any errors:
654
+
655
+ json_path_of_parent: ${JSON.stringify(json_path_of_parent)}
656
+ key_or_index: ${JSON.stringify(key_or_index)}
657
+ action: ${JSON.stringify(action)}
658
+ new_key_name: ${JSON.stringify(new_key_name)}
659
+ value: ${JSON.stringify(value, null, 2)}
660
660
  `);
661
661
  }
662
662
  catch (error) {
663
- convo.addSystemMessage(`
664
- An error occurred while attempting to apply the proposed modification:
665
- ${error.message}
663
+ convo.addSystemMessage(`
664
+ An error occurred while attempting to apply the proposed modification:
665
+ ${error.message}
666
666
  `);
667
667
  }
668
668
  }
669
669
  // Verify the modified object with the LLM
670
- convo.addUserMessage(`
671
- Here is the JSON object after applying the proposed modification.
672
-
673
- ---
674
-
675
- ${placemarkedJSONStringify(objModified, 2, options.skippedKeys)}
670
+ convo.addUserMessage(`
671
+ Here is the JSON object after applying the proposed modification.
672
+
673
+ ---
674
+
675
+ ${placemarkedJSONStringify(objModified, 2, options.skippedKeys)}
676
676
  `);
677
- convo.addDeveloperMessage(`
678
- Examining the modified JSON object after the proposed modifications have been applied,
679
- let's discuss and analyze whether or not these modifications are correct, i.e. whether
680
- or not they properly implement the intended changes.
681
-
682
- Specifically, check the following:
683
-
684
- - Does the modified JSON object now correctly contain the modifications?
685
-
686
- - Does the modified JSON object contain any unintended changes? This typically results from
687
- one or more poorly structured modification objects, where json_path_of_parent point to
688
- the wrong location in the JSON object.
689
-
690
- - Are the modifications *correct but incomplete*? In other words, were the modifications
691
- that were applied correct in the sense that they were consistent with the modification
692
- instructions, but they only represent one step in a multi-step process? If so, then this
693
- is not a problem at all. We will continue to apply more modifications in subsequent
694
- iterations.
695
-
696
- At the end of your analysis, write a conclusion. Your conclusion should be one of the
697
- following, or some variant thereof:
698
-
699
- - The changes are correct and complete for this step in the modification process.
700
- We can keep them, and we can move on to the next step in the modification process.
701
-
702
- - The changes are correct but incomplete for this step in the modification process.
703
- They are consistent with the modification instructions, but they only represent one step
704
- in a multi-step process. This is not a problem at all. We will keep these changes,
705
- and we will continue to apply more modifications in subsequent iterations,
706
- to make further progress towards satisfying the modification instructions.
707
-
708
- - The changes are incorrect for this step in the modification process. They do not progress
709
- us towards satisfying the modification instructions, and they may even break things and
710
- take us further away from satisfying the modification instructions. We should reject these
711
- changes, revert back to the previous version of the JSON object, and try a different
712
- modification operation that is more likely to be correct.
677
+ convo.addDeveloperMessage(`
678
+ Examining the modified JSON object after the proposed modifications have been applied,
679
+ let's discuss and analyze whether or not these modifications are correct, i.e. whether
680
+ or not they properly implement the intended changes.
681
+
682
+ Specifically, check the following:
683
+
684
+ - Does the modified JSON object now correctly contain the modifications?
685
+
686
+ - Does the modified JSON object contain any unintended changes? This typically results from
687
+ one or more poorly structured modification objects, where json_path_of_parent point to
688
+ the wrong location in the JSON object.
689
+
690
+ - Are the modifications *correct but incomplete*? In other words, were the modifications
691
+ that were applied correct in the sense that they were consistent with the modification
692
+ instructions, but they only represent one step in a multi-step process? If so, then this
693
+ is not a problem at all. We will continue to apply more modifications in subsequent
694
+ iterations.
695
+
696
+ At the end of your analysis, write a conclusion. Your conclusion should be one of the
697
+ following, or some variant thereof:
698
+
699
+ - The changes are correct and complete for this step in the modification process.
700
+ We can keep them, and we can move on to the next step in the modification process.
701
+
702
+ - The changes are correct but incomplete for this step in the modification process.
703
+ They are consistent with the modification instructions, but they only represent one step
704
+ in a multi-step process. This is not a problem at all. We will keep these changes,
705
+ and we will continue to apply more modifications in subsequent iterations,
706
+ to make further progress towards satisfying the modification instructions.
707
+
708
+ - The changes are incorrect for this step in the modification process. They do not progress
709
+ us towards satisfying the modification instructions, and they may even break things and
710
+ take us further away from satisfying the modification instructions. We should reject these
711
+ changes, revert back to the previous version of the JSON object, and try a different
712
+ modification operation that is more likely to be correct.
713
713
  `);
714
714
  await convo.submit();
715
715
  await convo.submit(undefined, undefined, {
@@ -717,9 +717,9 @@ following, or some variant thereof:
717
717
  format: {
718
718
  type: 'json_schema',
719
719
  name: 'modification_verification',
720
- description: `
721
- A JSON formalization of the analysis and verification of the modifications that were just applied
722
- to the JSON object, as we have just discussed and analyzed.
720
+ description: `
721
+ A JSON formalization of the analysis and verification of the modifications that were just applied
722
+ to the JSON object, as we have just discussed and analyzed.
723
723
  `,
724
724
  schema: {
725
725
  type: 'object',