Javascript & ChatGPT API Return Issue | XM Community
Skip to main content

Hi,

I have a web service API call from ChatGPT that returns a string set to a variable. I have prompted ChatGPT to return something like this: (Story ! Question ! Choice1 ! Choice2 ! Choice3)

The issue comes in that next I have javascript that modifies this api return variable in the next block. About 30% of the time this works fine, and the other 70% it does not, because ChatGPT responds with a line break of some kind between the story and question:

This gives me an unexpected token error when I set the javascript variable to the API return variable and shuts the whole code down, which has prevented me from error proofing the code.

I wondered if I could do something in javascript to prevent this, but so far no luck. 

I have also been throwing a bunch of different prompts at ChatGPT to try to prevent this with no luck. (no formatting, no HTML formatting, single line of plain text, no newline characters, no page breaks, entire response in 1 paragraph).

 

Let me know what’s possible, I appreciate any help

Rework on your prompt, try to put example output in your prompt so that GPT always return the output in that pattern only.


Rework on your prompt, try to put example output in your prompt so that GPT always return the output in that pattern only.

What more should I add to the prompt to give an example in addition to the: “(Story ! Question ! Choice1 ! Choice2 ! Choice3)”?


Leave a Reply