64 lines
2.1 KiB
Dart
64 lines
2.1 KiB
Dart
import 'dart:io';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:kouyu_english/core/ai_service.dart';
|
|
import 'package:kouyu_english/core/models.dart';
|
|
|
|
class RealHttpOverrides extends HttpOverrides {
|
|
@override
|
|
HttpClient createHttpClient(SecurityContext? context) {
|
|
return super.createHttpClient(context);
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
HttpOverrides.global = RealHttpOverrides();
|
|
const testKey = '***REMOVED***';
|
|
AiService.instance.setFallbackApiKey(testKey);
|
|
|
|
test('Live test: /v1/responses endpoint testConnection', () async {
|
|
try {
|
|
final resResponses = await AiService.instance.testConnection(
|
|
provider: AiProviderType.compatible,
|
|
endpoint: 'https://codex.slcydia.fun/v1/responses',
|
|
model: 'gemini-3.7-flash-high',
|
|
explicitApiKey: testKey,
|
|
);
|
|
print('Responses API result: ok=${resResponses.ok}, msg=${resResponses.message}');
|
|
} catch (e) {
|
|
print('Network test skipped: $e');
|
|
}
|
|
});
|
|
|
|
test('Live test: /v1 (Chat Completions) endpoint testConnection', () async {
|
|
try {
|
|
final resChat = await AiService.instance.testConnection(
|
|
provider: AiProviderType.compatible,
|
|
endpoint: 'https://codex.slcydia.fun/v1',
|
|
model: 'gemini-3.7-flash-high',
|
|
explicitApiKey: testKey,
|
|
);
|
|
print('Chat Completions API result: ok=${resChat.ok}, msg=${resChat.message}');
|
|
} catch (e) {
|
|
print('Network test skipped: $e');
|
|
}
|
|
});
|
|
|
|
test('Live test: /v1/responses dialogueReply', () async {
|
|
try {
|
|
final reply = await AiService.instance.dialogueReply(
|
|
provider: AiProviderType.compatible,
|
|
endpoint: 'https://codex.slcydia.fun/v1/responses',
|
|
model: 'gemini-3.7-flash-high',
|
|
history: [
|
|
{'role': 'user', 'content': 'Hello, my name is Alex.'}
|
|
],
|
|
requiredTask: 'Greet learner and ask what is their name',
|
|
);
|
|
print('Dialogue reply from /v1/responses: reply="${reply?.reply}", slots=${reply?.slots}, suggestsComplete=${reply?.suggestsComplete}');
|
|
} catch (e) {
|
|
print('Network test skipped: $e');
|
|
}
|
|
});
|
|
}
|