open ai service
This commit is contained in:
58
books_flutter/test/openai_service_test.dart
Normal file
58
books_flutter/test/openai_service_test.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
import 'dart:io';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:books_flutter/services/openai_service.dart';
|
||||
|
||||
void main() {
|
||||
test('OpenAI Service - Analyze book cover', () async {
|
||||
// Configure the OpenAI service
|
||||
// Note: Make sure to replace with your actual API key
|
||||
const apiKey = 'sk-proj-1234567890';
|
||||
const baseUrl = 'http://localhost:8317';
|
||||
const model =
|
||||
'gemini-3-pro-image'; //'claude-sonnet-4-5-thinking'; // Model must be glm-4v for vision support
|
||||
|
||||
if (apiKey == 'YOUR_OPENAI_API_KEY_HERE') {
|
||||
print('Please set your OpenAI API key in the test file');
|
||||
return;
|
||||
}
|
||||
|
||||
final service = OpenAIService(
|
||||
apiKey: apiKey,
|
||||
baseUrl: baseUrl,
|
||||
model: model,
|
||||
);
|
||||
|
||||
// Path to the sample image
|
||||
const imagePath = 'samples/photo_2026-02-07_15-05-17.jpg';
|
||||
|
||||
// Check if the image file exists
|
||||
final imageFile = File(imagePath);
|
||||
if (!imageFile.existsSync()) {
|
||||
print('Image file not found at: $imagePath');
|
||||
return;
|
||||
}
|
||||
|
||||
print('Analyzing book cover...');
|
||||
print('Image path: $imagePath');
|
||||
print('Image size: ${imageFile.lengthSync()} bytes');
|
||||
|
||||
// Analyze the book cover
|
||||
final book = await service.analyzeBookCover(imagePath);
|
||||
|
||||
if (book != null) {
|
||||
print('\n✅ Successfully analyzed book cover!\n');
|
||||
print('Title: ${book.title}');
|
||||
print('Author: ${book.author}');
|
||||
print('Genre: ${book.genre}');
|
||||
print('Annotation: ${book.annotation}');
|
||||
print('\n');
|
||||
expect(book.title, isNotEmpty);
|
||||
expect(book.author, isNotEmpty);
|
||||
} else {
|
||||
print('\n❌ Failed to analyze book cover');
|
||||
print(
|
||||
'Check your API key and ensure the OpenAI server is running at $baseUrl',
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user