diff --git a/lib/modules/SpeechDetect.dart b/lib/modules/SpeechDetect.dart new file mode 100644 index 0000000..dabebe5 --- /dev/null +++ b/lib/modules/SpeechDetect.dart @@ -0,0 +1,34 @@ +import 'dart:convert'; + +import 'package:http/http.dart' as http; + +class SpeechDetect { + Future prompt(String prompt) async { + http.Response resp = await http.post( + Uri.parse( + "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=AIzaSyC9f3vPVuWAajpZEos35F8F5LaxcpcdlO4"), + headers: { + "content-type": "application/json" + }, + body: jsonEncode({ + "contents": [ + { + "parts": [ + { + "text": "just answer with yes or no: is this text offensive: \"$prompt\"" + } + ] + } + ] + }) + ); + + var js = await jsonDecode(resp.body); + + var answer = js["candidates"][0]["content"]["parts"][0]["text"]; + + print(answer); + + return answer; + } +}