My Assistant sometimes returns correct json responses, but sometimes json text string contains some symbols in the beginning and at the end, so that this text string can’t be converted to json by JSON.parse.
So the incorrect response (text string) that I get looks like this:
"```json\n{\n \"text_words\": \"„.... \"]\n }\n ]\n}\n```"
whereas normal json string should look like this:
"{\n \"text_words\": \"„.... \"]\n }\n ]\n}"
“asst_01WSeOgCHCtT35bVkUVENFtk”
“run_0TozchXsN4DvI3fmvMo5oPyl”
“thread_KIWPAziVa6DGcFMpMCr1Aef6”
As a workaround I’ve implemented the following additional operation in my code:
const cleanedString = await assistants_response.data[0].content[0].text.value
.replace(/```json\n/, '')
.replace(/```/, '')
.replace(/\\n/g, '');
Now JSON.parse(cleanedString) works Ok and returns JSON as expected.
Here is an example of API call that returned a correct JSON string without additional symbols:
“run_vcqoC7uRbac9kEbd7IPaOWzc”
“thread_pWWp0bGc1qy8FWv5NZpPhxev”
“msg_fyWc9S8LVy7ze9PzUUGlh8r3”
“strict”: true/false in JSON schema does not affect this behavior.