diff --git a/lib/data/services/deapsound_ai_service.dart b/lib/data/services/deapsound_ai_service.dart index 6b121af4f..5036923b9 100644 --- a/lib/data/services/deapsound_ai_service.dart +++ b/lib/data/services/deapsound_ai_service.dart @@ -22,14 +22,25 @@ class DeapsoundAIService implements AiService { final client = http.Client(); final url = Uri.parse('https://www.deapsound.com/ai/funcchat'); + List contextsList = []; + String msg = ''; + for (var i = 0; i < messages.length; i++) { + Map item = messages[i]; + if (i < messages.length - 1) { + if (item['role'] == 'user') { + contextsList.add(item['content']); + } + } else { + msg = item['content']; + } + } + final headers = { 'Content-Type': 'application/json', 'Authorization': apiKey, }; - final requestBody = { - "msg": messages.last['content'], - }; + final requestBody = {"contexts": contextsList, "msg": msg}; try { final request = http.Request('POST', url)