feat: embed a Flutter G4F client with Cronet, cookie jar, and origin WebView

Port the Oracle off the Python g4f container onto on-device providers: Chromium HTTP via Cronet, a shared cookie session, IterList retry, hosted OpenAI-compat aggregators, and same-origin WebView fallbacks instead of CORS fetch.
This commit is contained in:
Alma Alexyz
2026-09-01 22:05:38 +05:00
parent f3e7412cf9
commit fbf04d90db
49 changed files with 4856 additions and 92 deletions
+37
View File
@@ -0,0 +1,37 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:words999/g4f/g4f.dart';
void main() {
const messages = [
Message(role: Role.system, content: 'Отвечай одним словом.'),
Message(role: Role.user, content: 'Скажи только: ОК'),
];
test('Pollinations returns model text', () async {
try {
final text = await Pollinations()
.createAsyncGenerator('openai-fast', messages, stream: false)
.join();
expect(text.trim().length, greaterThan(1));
expect(looksLikeGarbage(text), isFalse);
} catch (e) {
// Anonymous Pollinations is rate-limited / paywalled from some IPs.
expect(e.toString().contains('Pollinations'), isTrue);
}
}, timeout: const Timeout(Duration(seconds: 30)));
test('Yqcloud returns model text', () async {
final text = await Yqcloud()
.createAsyncGenerator(G4FModels.gpt4, messages, stream: false)
.join();
expect(text.trim().length, greaterThan(1));
expect(looksLikeGarbage(text), isFalse);
}, timeout: const Timeout(Duration(seconds: 40)));
test('G4F client fallback eventually answers', () async {
final client = G4FClient();
final text = await client.chat.completions.create(messages: messages);
expect(text.trim().length, greaterThan(1));
expect(looksLikeGarbage(text), isFalse);
}, timeout: const Timeout(Duration(seconds: 90)));
}