Spracherkennung via Gemini-API

mit gemini-flash, funktion gibt "yes" oder "no" zurück --> ist der text beleidigend
This commit is contained in:
Jonas Braus
2024-11-25 20:57:59 +01:00
parent 67bd8c98bb
commit 64cf38268a
+34
View File
@@ -0,0 +1,34 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
class SpeechDetect {
Future<String> 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;
}
}