From f3e7412cf9b6c56a36fd14639b0a2cb486394293 Mon Sep 17 00:00:00 2001 From: Alma Alexyz Date: Mon, 31 Aug 2026 15:55:44 +0500 Subject: [PATCH] feat: configure AiOracleService to rotate over verified live models from wordparcer g4f container --- lib/services/ai_oracle_service.dart | 53 ++++++++++++++--------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/lib/services/ai_oracle_service.dart b/lib/services/ai_oracle_service.dart index 9f11953..4b55597 100644 --- a/lib/services/ai_oracle_service.dart +++ b/lib/services/ai_oracle_service.dart @@ -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,45 +63,43 @@ ${newlyAddedWord != null ? "Дополнительный знак: #${newlyAdded } Future _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) { - try { - if (urlStr.startsWith('http://127.0.0.1') || urlStr.startsWith('http://localhost')) { + 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 { 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(' 15) { + return content.trim(); } } - } - } catch (_) {} + } catch (_) {} + } } return null; }