[PR #7] refactor: Implement modular architecture with Gemini 2.5 Flash upgrade #7

Closed
opened 2026-03-01 14:51:12 +03:00 by kerem · 0 comments
Owner

Original Pull Request: https://github.com/atiilla/GeoIntel/pull/7

State: closed
Merged: No


Overview

Comprehensive refactoring of GeoIntel codebase to improve code maintainability, error handling, and robustness. Includes upgrade to Gemini 2.5 Flash model for improved geolocation accuracy.

Model Upgrade

  • Previous Model: gemini-2.0-flash-lite-001
  • New Model: gemini-2.5-flash
  • Benefits: Better image understanding, superior vision capabilities, larger token context, improved reasoning for geolocation predictions
  • Performance: Same fast response times with better accuracy
  • Backward Compatibility: Drop-in replacement, no breaking changes

Changes

This PR introduces a modular architecture with the following new modules:

  • config.py: Centralized API configuration management (updated with Gemini 2.5 Flash)
  • api_client.py: Dedicated Gemini API communication with timeout handling and error management
  • image_utils.py: Image encoding with MIME type detection and inference
  • prompt_builder.py: Geolocation prompt generation
  • response_parser.py: Response parsing with comprehensive validation
  • cli_args.py: CLI argument parsing
  • cli_formatter.py: Output formatting and banner display

Verification Comments Implemented

  1. CLI import fix: Changed absolute import to relative import
  2. API timeout handling: Added 20-second timeout to POST requests with proper exception handling
  3. Response validation: Comprehensive validation for API response structure (candidates, content, parts, text)
  4. MIME type inference: Dynamic MIME type detection from URLs (Content-Type header) and local files (file extension)
  5. Error standardization: Consistent error dictionaries with 'error', 'details', and 'exception' fields
  6. Code fence stripping: Generalized regex-based fence removal supporting all code block variants
  7. Model upgrade: Updated to Gemini 2.5 Flash with optimized generation parameters (temperature: 0.3, topK: 40, topP: 0.95)

Benefits

  • Improved code organization and maintainability
  • Better error handling and user-friendly error messages
  • Robust API communication with timeout protection
  • Accurate image MIME type handling preventing API issues
  • Enhanced geolocation accuracy with Gemini 2.5 Flash model
  • 100% backward compatibility maintained
  • Significantly reduced complexity in core modules

Configuration Updates

Generation parameters optimized for geolocation accuracy:

  • Temperature: 0.3 (lower for consistent predictions)
  • topK: 40 (improved diversity)
  • topP: 0.95 (refined nucleus sampling)
  • maxOutputTokens: 2048

Summary by CodeRabbit

  • Refactor

    • Code reorganized into focused components for more reliable image handling, prompt building, API calls, and response parsing while preserving the public API and CLI behavior.
  • New Features

    • Improved image support (local files and URLs) with timeout and clearer error messages.
    • CLI shows a banner and produces consistently formatted results, including clickable map links and colored output.
  • Bug Fixes

    • More robust parsing of API responses and normalized location output for consistent downstream use.
**Original Pull Request:** https://github.com/atiilla/GeoIntel/pull/7 **State:** closed **Merged:** No --- ## Overview Comprehensive refactoring of GeoIntel codebase to improve code maintainability, error handling, and robustness. Includes upgrade to Gemini 2.5 Flash model for improved geolocation accuracy. ## Model Upgrade - **Previous Model**: gemini-2.0-flash-lite-001 - **New Model**: gemini-2.5-flash ✨ - **Benefits**: Better image understanding, superior vision capabilities, larger token context, improved reasoning for geolocation predictions - **Performance**: Same fast response times with better accuracy - **Backward Compatibility**: Drop-in replacement, no breaking changes ## Changes This PR introduces a modular architecture with the following new modules: - **config.py**: Centralized API configuration management (updated with Gemini 2.5 Flash) - **api_client.py**: Dedicated Gemini API communication with timeout handling and error management - **image_utils.py**: Image encoding with MIME type detection and inference - **prompt_builder.py**: Geolocation prompt generation - **response_parser.py**: Response parsing with comprehensive validation - **cli_args.py**: CLI argument parsing - **cli_formatter.py**: Output formatting and banner display ## Verification Comments Implemented 1. ✅ **CLI import fix**: Changed absolute import to relative import 2. ✅ **API timeout handling**: Added 20-second timeout to POST requests with proper exception handling 3. ✅ **Response validation**: Comprehensive validation for API response structure (candidates, content, parts, text) 4. ✅ **MIME type inference**: Dynamic MIME type detection from URLs (Content-Type header) and local files (file extension) 5. ✅ **Error standardization**: Consistent error dictionaries with 'error', 'details', and 'exception' fields 6. ✅ **Code fence stripping**: Generalized regex-based fence removal supporting all code block variants 7. ✅ **Model upgrade**: Updated to Gemini 2.5 Flash with optimized generation parameters (temperature: 0.3, topK: 40, topP: 0.95) ## Benefits - Improved code organization and maintainability - Better error handling and user-friendly error messages - Robust API communication with timeout protection - Accurate image MIME type handling preventing API issues - **Enhanced geolocation accuracy with Gemini 2.5 Flash model** - 100% backward compatibility maintained - Significantly reduced complexity in core modules ## Configuration Updates Generation parameters optimized for geolocation accuracy: - Temperature: 0.3 (lower for consistent predictions) - topK: 40 (improved diversity) - topP: 0.95 (refined nucleus sampling) - maxOutputTokens: 2048 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Code reorganized into focused components for more reliable image handling, prompt building, API calls, and response parsing while preserving the public API and CLI behavior. * **New Features** * Improved image support (local files and URLs) with timeout and clearer error messages. * CLI shows a banner and produces consistently formatted results, including clickable map links and colored output. * **Bug Fixes** * More robust parsing of API responses and normalized location output for consistent downstream use. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
kerem 2026-03-01 14:51:12 +03:00
kerem changed title from [PR #7] [CLOSED] refactor: Implement modular architecture with Gemini 2.5 Flash upgrade to [PR #7] refactor: Implement modular architecture with Gemini 2.5 Flash upgrade 2026-03-15 11:26:19 +03:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/GeoIntel#7
No description provided.