I'm using OpenAI's API to convert Movie Titles to emojis. I'm using Flutter and Dart. I'm getting the response from API but Emojis are not rendered! The "movieController" is basically the user input and the "setState" prints the Emoji on Screen. This is the response I get from the API. It works perfectly fine on OpenAI's website The Code
TextButton(
style: TextButton.styleFrom(backgroundColor: Colors.black),
onPressed: () async {
var response = await http.post(
url,
body: convert.jsonEncode({
"model": "text-davinci-002",
"prompt":
"\n\n${movieController.text}:",
"temperature": 0.8,
"max_tokens": 60,
"top_p": 1.0,
"frequency_penalty": 0.0,
"presence_penalty": 0.0,
"stop": ["\n"]
}),
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": "Bearer $ApiKey"
},
);
if (response.statusCode == 200) {
var jsonResponse = convert.jsonDecode(response.body);
jsonR = jsonResponse.toString();
data = (jsonResponse["choices"][0]["text"]);
//Extracting the Emoji from the JSON response
print(data);
if (data == "") {
print("Error");
}
print(jsonResponse);
} else {
print(
'Request failed with status: ${response.statusCode}');
}
setState(() {
outPutString = data; //Displays the emojis
});
},
child: Text("Submit"),
)
The Response from the API in the Console Window The text should be the Emojis
I/flutter ( 5209): âï¸âï¸âï¸âï¸âï¸
I/flutter ( 5209): {id: cmpl-60S6mJXeiBVrSMoRNf3lBHUeqMWLp, object: text_completion, created: 1665566068, model: text-davinci-002, choices: [{text: âï¸âï¸âï¸âï¸âï¸, index: 0, logprobs: null, finish_reason: stop}], usage: {prompt_tokens: 12, completion_tokens: 20, total_tokens: 32}}