This topic was automatically generated from Slack. You can find the original thread here.
Here is my code:
// Access the response from ChatGPT step
let chatgpt_response = steps.chat_1.$return_value;
// Split the response into segments based on commas
let segments = chatgpt_response.split(",");
// Extract values from each segment
let parsedData = segments.map(segment => segment.trim().split(":")[1].trim());
// Make parsedData available for next steps in Pipedream
this.parsedData = parsedData;
please take the code snippet shared above and integrate it into a Pipedream Node.js code step. can you tweak the Node.js code step to use steps.chat_1.$return_value directly?
Sure, here’s the code snippet integrated into a Pipedream Node.js code step: export default defineComponent({ async run({ steps, $ }) { // Access the response from ChatGPT step let chatgpt_response = steps.chat_1.$return_value; // Split the response into segments based on commas let segments = chatgpt_response.split(","); // Extract values from each segment let parsedData = segments.map(segment => segment.trim().split(":")[1].trim()); // Return parsedData for use in the next steps in Pipedream return parsedData; }, }); This code step uses steps.chat_1.$return_value directly and returns the parsedData for use in the next steps in your Pipedream workflow.
TypeError
chatgpt_response.split is not a function DETAILS
at Object.run (file:///tmp/__pdg__/dist/code/0b0a666e605ceb8a4154e156163bd6eae88dcccce76314fbaef962e02a9617c0/component.mjs:7:37)
at null.executeComponent (/var/task/launch_worker.js:229:53)
at MessagePort.messageHandler (/var/task/launch_worker.js:726:28)
It seems like the chatgpt_response is not a string, which is causing the error when trying to use the split() function. To fix this issue, you can check the type of chatgpt_response and convert it to a string if necessary. Here’s the updated code: export default defineComponent({ async run({ steps }) { // Access the response from ChatGPT step let chatgpt_response = steps.chat_1.$return_value; // Check if chatgpt_response is not a string and convert it to a string if necessary if (typeof chatgpt_response !== "string") { chatgpt_response = JSON.stringify(chatgpt_response); } // Split the response into segments based on commas let segments = chatgpt_response.split(","); // Extract values from each segment let parsedData = segments.map(segment => segment.trim().split(":")[1].trim()); // Return parsedData for use in the next steps in Pipedream return parsedData; }, }); This code checks if chatgpt_response is not a string and converts it to a string using JSON.stringify() if necessary. Then it proceeds with the rest of the original code.