33 lines
872 B
Dart
33 lines
872 B
Dart
import 'dart:convert';
|
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
class SpeechDetect {
|
|
static Future<bool> 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"];
|
|
|
|
return answer.toString().toLowerCase().contains("yes") ? true : false;
|
|
}
|
|
}
|