Files
bookshelf/books_flutter/TESTING_GUIDE.md
2026-02-08 12:05:05 +06:00

2.5 KiB

Testing OpenAI Service

This guide explains how to test the OpenAI service with the sample book cover image.

Use the standalone test script for quick testing:

Step 1: Set Your API Key

Edit test_openai_service.dart and replace the placeholder:

const apiKey = 'YOUR_OPENAI_API_KEY_HERE';

Replace YOUR_OPENAI_API_KEY_HERE with your actual OpenAI API key.

Step 2: Run the Test

From the project root directory, run:

dart run test_openai_service.dart

Expected Output

If successful, you'll see:

========================================
📖 Testing OpenAI Book Cover Analysis
========================================

Image path: samples/photo_2026-02-07_15-05-17.jpg
Image size: XXXXXX bytes
API endpoint: http://localhost:8317/v1/chat/completions

Analyzing book cover... (this may take a few seconds)

========================================
✅ Successfully analyzed book cover!
========================================

📚 Book Details:
   Title: [Book Title]
   Author: [Author Name]
   Genre: [Genre]
   Annotation: [Book description]
   Language: Russian
   Published Year: 2026
   Rating: 5.0

========================================

Troubleshooting

Error: "Please set your OpenAI API key"

You need to edit test_openai_service.dart and add your actual API key.

Error: "Image file not found"

Make sure you're running the test from the project root directory where the samples/ folder is located.

Error: "Failed to analyze book cover"

Check the following:

  1. Server Running: Ensure your OpenAI server is running at http://localhost:8317
  2. API Key: Verify your API key is correct
  3. Server Logs: Check your OpenAI server logs for errors
  4. Model Support: Ensure your server supports the glm-4 model
  5. Network: Check network connectivity

Testing on Different Environments

If you're testing from a different environment (not the same machine running the server), update the baseUrl:

const baseUrl = 'http://YOUR_SERVER_IP:8317'; // For remote server
// or
const baseUrl = 'http://10.0.2.2:8317'; // For Android emulator

Running Formal Flutter Tests

If you prefer to run the formal Flutter test:

flutter test test/openai_service_test.dart

Make sure to update the API key in test/openai_service_test.dart before running.

Sample Image

The test uses the sample image at: samples/photo_2026-02-07_15-05-17.jpg

You can replace this with any book cover image you want to test.