MCPcopy Create free account
hub / github.com/Superflows-AI/superflows / addGPTdataToProperties

Function addGPTdataToProperties

lib/utils.ts:373–414  ·  view source on GitHub ↗
(
  properties: Properties,
  gptOutput: string,
  arrayIdx: number | null = null,
)

Source from the content-addressed store, hash-verified

371}
372
373export function addGPTdataToProperties(
374 properties: Properties,
375 gptOutput: string,
376 arrayIdx: number | null = null,
377): Properties {
378 /**
379 Add the data outputted by gpt to the properties object.
380
381 If working with an array type (and gpt has output a comma separated list of values)
382 pass arrayIdx to select which value in an semi-colon separate list to use.
383
384 TODO: currently always treats data as a string.
385 **/
386
387 gptOutput.split("\n").forEach((line) => {
388 let [key, value] = [
389 line.slice(0, line.indexOf(":")).trim(),
390 line.slice(line.indexOf(":") + 1).trim(),
391 ];
392
393 if (key in properties) {
394 if (arrayIdx !== null) {
395 value = value
396 .replace("[", "")
397 .replaceAll("]", "")
398 .split(",")
399 [arrayIdx].trim(); // TODO: Add fallback for if the commaIdx is out of range
400 }
401
402 if (!value) return;
403
404 // Remove leading or trailing single or double quotes
405 value = value.replace(/^["'](.+(?=["']$))["']$/, "$1");
406 try {
407 value = JSON.parse(value);
408 } catch {}
409 properties[key].data = value;
410 }
411 });
412
413 return properties;
414}
415
416export function propertiesToChunks(properties: Properties): Chunk[] {
417 /**

Callers 2

rebuildPropertiesFunction · 0.90
rebuildPropertiesArrayFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected