Hi,
I’m using the OpenAI output as JSON, however it being wrapped in comments that are not recognised by the parser.
Is there any way to avoid this without too many loops with trimming the text?
This is not a JSON format… how did you get it? What kind of script?.. You can clean it by replacing the first characters… anything before the first curly bracket must go away…
if(p1){
let inputString = p1;
let indexOfFirstCurlyBracket = inputString.indexOf('{');
if (indexOfFirstCurlyBracket !== -1) {
let resultString = inputString.substring(indexOfFirstCurlyBracket);
return (JSON.parse(resultString).json.Title);
} else {
return "Curly bracket not found in the string."
}
}
return
Thank you for suggestion. I tried this code, but it did not work in the JS column. However it gave me an idea to construct a different code which did work at the end without adding interim columns
This is a very old thread. Can you please explain more about your use case?
Please show the data you have, how you get it, and your desired end ressult.
From the AI response we will get json like below
“Here is the sample response{“productId”: 123, “productCode”:“code1”} end”
Need to remove prefix text “Here is the sample response” as well as suffix text at end after last } which is “end”
Yes but sometimes the prompt return invalid text at start and end if promptInput is not proper
The prompt input is unstructured like “123 code1” then it returns output in json
{“productId”: 123, “productCode”:“code1”}