feat: configure AiOracleService to rotate over verified live models from wordparcer g4f container

This commit is contained in:
Alma Alexyz
2026-08-31 15:55:44 +05:00
parent bd494ae633
commit f3e7412cf9
+23 -26
View File
@@ -1,5 +1,4 @@
import 'dart:convert';
import 'dart:math';
import 'package:http/http.dart' as http;
import '../models/history_entry_model.dart';
import '../models/word_model.dart';
@@ -64,46 +63,44 @@ ${newlyAddedWord != null ? "Дополнительный знак: #${newlyAdded
}
Future<String?> _tryFetchOnlineAi(String prompt) async {
final urls = [
'http://127.0.0.1:1337/v1/chat/completions',
'http://localhost:8080/v1/chat/completions',
'https://text.pollinations.ai/${Uri.encodeComponent(prompt)}?model=openai&json=false',
'https://text.pollinations.ai/${Uri.encodeComponent(prompt)}?model=mistral&json=false',
const workingModels = [
'gpt-4o-mini',
'gpt-4o',
'command-r',
'command-r7b',
'Yqcloud',
'HuggingSpace',
'WeWordle',
];
for (final urlStr in urls) {
final endpoints = [
'http://localhost:8080/v1/chat/completions',
'http://127.0.0.1:8080/v1/chat/completions',
];
for (final ep in endpoints) {
for (final modelName in workingModels) {
try {
if (urlStr.startsWith('http://127.0.0.1') || urlStr.startsWith('http://localhost')) {
final res = await http.post(
Uri.parse(urlStr),
Uri.parse(ep),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({
'model': 'gpt-4o-mini',
'model': modelName,
'messages': [{'role': 'user', 'content': prompt}],
'temperature': 0.7,
}),
).timeout(const Duration(seconds: 8));
).timeout(const Duration(seconds: 10));
if (res.statusCode == 200) {
final data = jsonDecode(utf8.decode(res.bodyBytes));
final content = data['choices']?[0]?['message']?['content'] as String?;
if (content != null && content.trim().isNotEmpty) return content.trim();
}
} else {
final res = await http.get(
Uri.parse(urlStr),
headers: {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
'Accept': 'text/plain, */*',
},
).timeout(const Duration(seconds: 4));
if (res.statusCode == 200) {
final body = utf8.decode(res.bodyBytes).trim();
if (body.isNotEmpty && !body.startsWith('<!DOCTYPE') && !body.contains('Payment Required')) {
return body;
}
if (content != null && content.trim().length > 15) {
return content.trim();
}
}
} catch (_) {}
}
}
return null;
}