modifyMessage method
Future<GptAssistantMessage>
modifyMessage({
- required String apiKey,
- required String organizationId,
- required String threadId,
- required String messageId,
- required CreateGptMessageRequest request,
Modifies a message.
Implementation
Future<GptAssistantMessage> modifyMessage({
required String apiKey,
required String organizationId,
required String threadId,
required String messageId,
required CreateGptMessageRequest request,
}) async {
Map<String, String> headers = {
"Authorization": "Bearer $apiKey",
"OpenAI-Organization": organizationId,
'Content-Type': 'application/json',
"Access-Control-Allow-Origin": "*", // Required for CORS support to work
"OpenAI-Beta": "assistants=v1"
};
Uri endpoint;
if(secure) {
endpoint = Uri.https(
baseUrl, "/v1/threads/$threadId/messages/$messageId");
}
else {
endpoint = Uri.http(
baseUrl, "/v1/threads/$threadId/messages/$messageId");
}
var response = await
http.post(endpoint, headers: headers, body:jsonEncode(request.toJson()));
if (response.statusCode == 200 || response.statusCode == 201) {
return GptAssistantMessage.fromJson(jsonDecode(const Utf8Decoder().convert(response.bodyBytes)));
}
else {
var error = ServerError.fromJson(jsonDecode(response.body));
throw MessagesException(statusCode: response.statusCode, message: error.message);
}
}