feat: configure AiOracleService to rotate over verified live models from wordparcer g4f container
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:math';
|
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import '../models/history_entry_model.dart';
|
import '../models/history_entry_model.dart';
|
||||||
import '../models/word_model.dart';
|
import '../models/word_model.dart';
|
||||||
@@ -64,46 +63,44 @@ ${newlyAddedWord != null ? "Дополнительный знак: #${newlyAdded
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<String?> _tryFetchOnlineAi(String prompt) async {
|
Future<String?> _tryFetchOnlineAi(String prompt) async {
|
||||||
final urls = [
|
const workingModels = [
|
||||||
'http://127.0.0.1:1337/v1/chat/completions',
|
'gpt-4o-mini',
|
||||||
'http://localhost:8080/v1/chat/completions',
|
'gpt-4o',
|
||||||
'https://text.pollinations.ai/${Uri.encodeComponent(prompt)}?model=openai&json=false',
|
'command-r',
|
||||||
'https://text.pollinations.ai/${Uri.encodeComponent(prompt)}?model=mistral&json=false',
|
'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 {
|
try {
|
||||||
if (urlStr.startsWith('http://127.0.0.1') || urlStr.startsWith('http://localhost')) {
|
|
||||||
final res = await http.post(
|
final res = await http.post(
|
||||||
Uri.parse(urlStr),
|
Uri.parse(ep),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: jsonEncode({
|
body: jsonEncode({
|
||||||
'model': 'gpt-4o-mini',
|
'model': modelName,
|
||||||
'messages': [{'role': 'user', 'content': prompt}],
|
'messages': [{'role': 'user', 'content': prompt}],
|
||||||
|
'temperature': 0.7,
|
||||||
}),
|
}),
|
||||||
).timeout(const Duration(seconds: 8));
|
).timeout(const Duration(seconds: 10));
|
||||||
|
|
||||||
if (res.statusCode == 200) {
|
if (res.statusCode == 200) {
|
||||||
final data = jsonDecode(utf8.decode(res.bodyBytes));
|
final data = jsonDecode(utf8.decode(res.bodyBytes));
|
||||||
final content = data['choices']?[0]?['message']?['content'] as String?;
|
final content = data['choices']?[0]?['message']?['content'] as String?;
|
||||||
if (content != null && content.trim().isNotEmpty) return content.trim();
|
if (content != null && content.trim().length > 15) {
|
||||||
}
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user