Files
bookshelf/books_flutter/test_openai_service.dart
2026-02-08 12:05:05 +06:00

65 lines
2.3 KiB
Dart

import 'dart:io';
import 'lib/services/openai_service.dart';
void main() async {
// Configure the OpenAI service
// Note: Replace with your actual API key
const apiKey = 'YOUR_OPENAI_API_KEY_HERE';
const baseUrl = 'http://localhost:8317';
if (apiKey == 'YOUR_OPENAI_API_KEY_HERE') {
print('❌ Please set your OpenAI API key in this file');
return;
}
final service = OpenAIService(apiKey: apiKey, baseUrl: baseUrl);
// 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');
print('Current working directory: ${Directory.current.path}');
return;
}
print('========================================');
print('📖 Testing OpenAI Book Cover Analysis');
print('========================================\n');
print('Image path: $imagePath');
print('Image size: ${imageFile.lengthSync()} bytes');
print('API endpoint: $baseUrl/v1/chat/completions\n');
print('Analyzing book cover... (this may take a few seconds)\n');
// Analyze the book cover
final book = await service.analyzeBookCover(imagePath);
if (book != null) {
print('========================================');
print('✅ Successfully analyzed book cover!');
print('========================================\n');
print('📚 Book Details:');
print(' Title: ${book.title}');
print(' Author: ${book.author}');
print(' Genre: ${book.genre}');
print(' Annotation: ${book.annotation}');
print(' Language: ${book.language}');
print(' Published Year: ${book.publishedYear}');
print(' Rating: ${book.rating}');
print('\n');
print('========================================');
} else {
print('========================================');
print('❌ Failed to analyze book cover');
print('========================================\n');
print('Troubleshooting tips:');
print('1. Check your API key is correct');
print('2. Ensure the OpenAI server is running at $baseUrl');
print('3. Check the server logs for errors');
print('4. Verify the server supports vision models (gpt-4o)');
print('5. Check network connectivity\n');
}
}