Use-chatgpt-to-write-long-blog-posts-on-wordpress-1500-words Model: doesn't work

Hello,
I tested the tutorial in this article Use ChatGPT to automate writing long blog posts on WordPress (1,500+ words) - Activepieces, but it does not work.

The Code module gives an error:

SyntaxError: Unexpected token O in JSON at position 0
at JSON.parse ()
at Object.code (/root/codes/step_4/index.js:5:22)
at Object. (webpack://activepieces/engine/src/lib/executors/code-executer.ts:9:32)
at Generator.next ()
at fulfilled (webpack://activepieces/node_modules/tslib/tslib.es6.mjs:118:41)

Unfortunately, as a new user I cannot attach screenshots.

Can you help me, please?

any help with this, I’m getting this error as well:
Unexpected token ` in JSON at position 0 I have made no changes to the flow as it was downloaded

Actually i am getting the same error while trying to use the template. Can anyone please help

Make sure the ‘Ask ChatGPT’ step doesn’t give invalid JSON format. If it does, fix the ‘question field’ by adding new prompts or editing existing ones to ensure the response is valid.

The issue clearly seems to be with Invalid JSON.

Sometimes OpenAI returns the data in JSON format, sometimes it returns the data in JSON but contains markdown code block i…e it starts with “```” (3 backticks)

Step #1: Make sure you include the text “Return response in JSON format” in your prompt - This doesn’t always return the data in JSON but it is required

Step #2: Make sure the variable name you’re using is chatgpt and it contains the entire response sent by OpenAI

Step #3: Replace your entire code block with this

export const code = async (inputs) => {
  let jsonString = inputs.chatgpt.trim();
  if (jsonString.toLowerCase().startsWith('```json') && jsonString.endsWith('```')) {
    jsonString = jsonString.substring(7, jsonString.length - 3);
  }
  const responseObject = JSON.parse(jsonString);
  return responseObject;
};

Hope this helps, If not please try to export and share your flow for further debugging.

1 Like

This solved it for me. Thanks @IOBLR .

@valentinomea I added for this line of the chatgpt code Return strictly only a JSON object
I added:
(and does not contain markdown code “”")

1 Like