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:
@@ -0,0 +1,83 @@
|
||||
import 'models.dart';
|
||||
import 'providers/aggregators.dart';
|
||||
import 'providers/aichatos.dart';
|
||||
import 'providers/base_provider.dart';
|
||||
import 'providers/blackbox.dart';
|
||||
import 'providers/chatgpt_oss.dart';
|
||||
import 'providers/cloudflare.dart';
|
||||
import 'providers/cohere_space.dart';
|
||||
import 'providers/copilot_app.dart';
|
||||
import 'providers/deep_ai.dart';
|
||||
import 'providers/duckduckgo.dart';
|
||||
import 'providers/free2gpt.dart';
|
||||
import 'providers/glm.dart';
|
||||
import 'providers/hugging_chat.dart';
|
||||
import 'providers/liaobots.dart';
|
||||
import 'providers/opera_aria.dart';
|
||||
import 'providers/phind_ai.dart';
|
||||
import 'providers/pollinations.dart';
|
||||
import 'providers/qwen.dart';
|
||||
import 'providers/quillbot.dart';
|
||||
import 'providers/teach_anything.dart';
|
||||
import 'providers/webview/deepinfra_webview.dart';
|
||||
import 'providers/you_chat.dart';
|
||||
import 'providers/yqcloud.dart';
|
||||
import 'retry.dart';
|
||||
|
||||
class G4FChatCompletions {
|
||||
/// REST-live first, then Python-hosted OpenAI-compat, then WAF/WebView.
|
||||
final List<BaseProvider> _providers = [
|
||||
Yqcloud(),
|
||||
DeepAi(),
|
||||
Quillbot(),
|
||||
KiloCode(),
|
||||
OpenCode(),
|
||||
G4FSpace(),
|
||||
Pollinations(),
|
||||
PhindAi(),
|
||||
TeachAnything(),
|
||||
CopilotApp(),
|
||||
ChatGptOss(),
|
||||
AiChatOs(),
|
||||
OperaAria(),
|
||||
Liaobots(),
|
||||
YouChat(),
|
||||
Free2Gpt(),
|
||||
CohereSpace(),
|
||||
GlmZai(),
|
||||
DuckDuckGo(),
|
||||
Blackbox(),
|
||||
HuggingChat(),
|
||||
QwenChat(),
|
||||
CloudflareAi(),
|
||||
DeepInfraWebView(),
|
||||
];
|
||||
|
||||
List<BaseProvider> get providers => List.unmodifiable(_providers);
|
||||
|
||||
late final IterListProvider _retry = IterListProvider(_providers);
|
||||
|
||||
/// Full completion via g4f IterListProvider (try next on failure).
|
||||
Future<String> create({
|
||||
required List<Message> messages,
|
||||
String? model,
|
||||
}) {
|
||||
return _retry.create(messages: messages, model: model ?? G4FModels.gpt4o);
|
||||
}
|
||||
|
||||
Stream<String> createStream({
|
||||
required List<Message> messages,
|
||||
String? model,
|
||||
}) async* {
|
||||
yield await create(messages: messages, model: model);
|
||||
}
|
||||
}
|
||||
|
||||
class G4FChat {
|
||||
final completions = G4FChatCompletions();
|
||||
}
|
||||
|
||||
/// Mirrors `g4f.client.Client`.
|
||||
class G4FClient {
|
||||
final chat = G4FChat();
|
||||
}
|
||||
Reference in New Issue
Block a user