open ai service
This commit is contained in:
64
books_flutter/test_openai_service.dart
Normal file
64
books_flutter/test_openai_service.dart
Normal file
@@ -0,0 +1,64 @@
|
||||
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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user