Lost brackets in OpenAI assistant response

Database & APIs

Hi,

I am using OpenAI API to interact, consequently using the previous response as part of the new. I am facing an issue while capturing the assistant message from the API response.

I get the string but without brackets " " so when I need to include it in my next query, the string is not interpreted as valid JSON. Basically, I get

{role: assistant, content: this is the response}

instead of

{"role": "assistant", "content": "this is the response"}

I try to set a text field value using a predefined "path name" called assistantResponse.

See the attachments for more clarification.

Any suggestion?

Thanks a lot.

What have you tried so far?

I tried to manipulate the string with a custom function without success.
String? handleAPIResponse(dynamic jsonResponse) { // Parse the JSON response var decodedResponse = json.decode(jsonResponse); // Access the entire message object var messageObject = decodedResponse['choices'][0]['message']; // Convert the message object to a JSON string String messageString = json.encode(messageObject); return messageString; }

Did you check FlutterFlow's Documentation for this topic?
No
1
1 reply