83 lines
2.8 KiB
Python
83 lines
2.8 KiB
Python
"""
|
|
Simple test to verify image processing works correctly.
|
|
"""
|
|
|
|
import asyncio
|
|
import sys
|
|
import os
|
|
import base64
|
|
import logging
|
|
|
|
# Add the gateway module to the path
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'modules'))
|
|
|
|
from modules.datamodels.datamodelAi import AiCallOptions, OperationType
|
|
from modules.services.serviceAi.mainServiceAi import AiService
|
|
|
|
# Set up logging
|
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
logger = logging.getLogger(__name__)
|
|
|
|
async def test_image_processing():
|
|
"""Test image processing with a simple base64 image."""
|
|
print("🧪 Testing image processing...")
|
|
logger.info("🧪 Testing image processing...")
|
|
|
|
try:
|
|
print("🔧 Initializing AI service...")
|
|
logger.info("🔧 Initializing AI service...")
|
|
|
|
# Initialize AI service
|
|
ai_service = await AiService.create()
|
|
print("✅ AI service initialized successfully")
|
|
logger.info("✅ AI service initialized successfully")
|
|
|
|
# Create a simple test image (1x1 pixel PNG in base64)
|
|
test_image_base64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=="
|
|
print(f"📸 Test image base64 length: {len(test_image_base64)}")
|
|
logger.info(f"📸 Test image base64 length: {len(test_image_base64)}")
|
|
|
|
# Test the readImage method directly
|
|
print("📸 Testing readImage method...")
|
|
logger.info("📸 Testing readImage method...")
|
|
|
|
result = await ai_service.readImage(
|
|
prompt="What do you see in this image?",
|
|
imageData=test_image_base64,
|
|
mimeType="image/png"
|
|
)
|
|
|
|
print(f"✅ Image processing result: {result}")
|
|
logger.info(f"✅ Image processing result: {result}")
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"❌ Image processing test failed: {str(e)}")
|
|
logger.error(f"❌ Image processing test failed: {str(e)}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
logger.error(f"Traceback: {traceback.format_exc()}")
|
|
return False
|
|
|
|
async def main():
|
|
"""Main function to run the image processing test."""
|
|
print("🎯 Starting Image Processing Test")
|
|
print("=" * 60)
|
|
logger.info("🎯 Starting Image Processing Test")
|
|
logger.info("=" * 60)
|
|
|
|
success = await test_image_processing()
|
|
|
|
if success:
|
|
print("🎉 Image processing test completed successfully!")
|
|
logger.info("🎉 Image processing test completed successfully!")
|
|
else:
|
|
print("❌ Image processing test failed!")
|
|
logger.error("❌ Image processing test failed!")
|
|
|
|
print("=" * 60)
|
|
logger.info("=" * 60)
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|