( calledActions: CalledAction[], varNames: string[], )
| 87 | } |
| 88 | |
| 89 | export function getFunctionCallCode( |
| 90 | calledActions: CalledAction[], |
| 91 | varNames: string[], |
| 92 | ): string { |
| 93 | // Write code to include in prior assistant message |
| 94 | |
| 95 | return calledActions |
| 96 | .map((a, idx) => { |
| 97 | const funcName = snakeToCamel(a.action.name); |
| 98 | let argsText = Object.entries(a.args) |
| 99 | .map(([key, value]) => { |
| 100 | return `${key}:${JSON.stringify(value)}`; |
| 101 | }) |
| 102 | .join(","); |
| 103 | let lengthStr = ""; |
| 104 | if (a.output && Array.isArray(a.output)) { |
| 105 | lengthStr = `// Length: ${a.output.length}`; |
| 106 | } else if ( |
| 107 | a.output && |
| 108 | typeof a.output === "object" && |
| 109 | "items" in a.output && |
| 110 | Array.isArray(a.output.items) |
| 111 | ) { |
| 112 | lengthStr = `// ${varNames[idx]}.items.length = ${a.output.items.length}`; |
| 113 | } |
| 114 | argsText = argsText ? `{${argsText}}` : ""; |
| 115 | return `const ${varNames[idx]} = ${funcName}(${argsText});${lengthStr}`; |
| 116 | }) |
| 117 | .join("\n"); |
| 118 | } |
| 119 | |
| 120 | function formatValueForVarName(key: string, value: any): string { |
| 121 | if (Array.isArray(value)) { |
no test coverage detected