Skip to content

Conversation

@jcrabapple
Copy link

AI Article Summarization - Implementation Summary

Overview

Successfully implemented AI-powered article summarization feature for ReadYou Android app using OpenAI-compatible APIs.

Files Created (10 files)

Data Layer (4 files)

  1. AiBaseUrlPreference.kt - Stores OpenAI-compatible API base URL
  2. AiApiKeyPreference.kt - Stores API key (display masked as •••••••••••)
  3. AiModelPreference.kt - Stores selected LLM model
  4. AiSummarizationPromptPreference.kt - Stores custom summarization prompt

API Layer (4 files)

  1. OpenAiModels.kt - Data classes for OpenAI API requests/responses
  2. OpenAiApiService.kt - Retrofit service with Bearer token authentication
  3. AiSummaryRepository.kt - Repository for API operations (fetch models, summarize)
  4. OpenAiModule.kt - Hilt dependency injection module

UI Layer (2 files)

  1. AiSettingsPage.kt - Full settings page with configuration UI
  2. AiSettingsViewModel.kt - ViewModel for settings operations
  3. AiSummaryOverlay.kt - Full-screen summary display overlay

Files Modified (11 files)

DataStore/Preferences

  • DataStoreExt.kt - Added 4 new DataStore keys
  • Settings.kt - Added 4 AI settings properties
  • SettingsProvider.kt - Added 4 composition local providers
  • Preference.kt - Added AI preferences to toSettings() converter

Navigation

  • NavKey.kt - Added AiSettings route
  • RouteName.kt - Added AI_SETTINGS constant
  • AppEntry.kt - Added navigation handler for AI settings

Settings UI

  • SettingsPage.kt - Added AI settings menu item with Psychology icon

Reading Page UI

  • TopBar.kt - Added AI Summary button (brain icon) before Style/Share buttons
  • ReadingPage.kt - Added overlay state and button handler

ViewModel

  • ArticleListReaderViewModel.kt - Added summarizeCurrentArticle() method

Resources

  • strings.xml - Added 13 new string resources

Features Implemented

1. AI Settings Page

  • Location: Settings → AI (new menu item with Psychology icon)
  • Configuration Options:
    • Base URL: OpenAI-compatible API endpoint (default: https://api.openai.com/v1)
    • API Key: Secure input with password masking in display
    • LLM Model: Dropdown populated from API when URL/key are configured
    • Summarization Prompt: Multi-line text with default template

2. AI Summary Button

  • Location: Reading page toolbar (between nav buttons and Style/Share)
  • Icon: Psychology (brain) icon
  • Behavior:
    • Validates configuration before making API call
    • Shows loading indicator during generation
    • Displays error if configuration missing or API fails

3. AI Summary Overlay

  • Display: Full-screen modal dialog
  • Features:
    • Scrollable text for long summaries
    • Loading indicator with spinner
    • Error display in Material Design surface
    • Close button (X) with haptic feedback
    • Android back button/gesture support
    • Dimmed background (80% opacity)

4. API Integration

  • Authentication: Bearer token in Authorization header
  • Endpoints:
    • GET /models - Fetch available LLM models
    • POST /chat/completions - Generate article summary
  • Error Handling: Business errors, Network errors, Unknown errors
  • Timeouts: 30 seconds connect/read/write
  • Max Tokens: 2000 tokens for summaries
  • Temperature: 0.7 for balanced creativity

Default Values

Setting Default Value
Base URL https://api.openai.com/v1
API Key Empty string
Model gpt-3.5-turbo
Prompt "Please provide a concise summary of the following article in 3-5 bullet points:\n\n"

User Flow

  1. Configuration:

    • Navigate to Settings → AI
    • Enter OpenAI-compatible base URL
    • Enter API key
    • Select model from fetched list
    • Customize summarization prompt (optional)
  2. Generate Summary:

    • Open any article in reading view
    • Tap Psychology (brain) icon in top toolbar
    • Wait for summary generation
    • Read summary in full-screen overlay
    • Close via X button or back gesture

Technical Details

Dependencies Used

  • OkHttp 5.0.0-alpha.12 - HTTP client with interceptors
  • Retrofit 2.11.0 - REST API with Gson converter
  • Jetpack Compose - UI framework
  • Hilt - Dependency injection
  • DataStore - Persistent settings storage

Architecture Pattern

  • MVVM with Repository pattern
  • Unidirectional data flow
  • StateFlow for reactive UI
  • Coroutines for async operations

Security

  • API key stored securely in DataStore
  • API key masked in UI display (•••••••••••)
  • HTTPS-only API calls
  • No logging of sensitive data

Future Enhancements

Possible improvements:

  • Cache summaries locally
  • Regenerate summary button
  • Save summary for offline viewing
  • Support for streaming responses
  • Progress indicator for long articles
  • Support for multiple AI providers
  • Custom token limit in settings
  • Summary history per article

This feature adds the ability to summarize articles using an OpenAI-compatible API.

Key changes:
- Added AI settings screen for configuring API URL, Key, Model, and Prompt.
- Added 'AI Summary' button to the article reading toolbar.
- Implemented a summary overlay with loading and error states.
- Integrated networking layer with Retrofit/OkHttp for OpenAI chat completions.
- Persisted AI configuration using DataStore.

Implementation details are documented in AI_IMPLEMENTATION_SUMMARY.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant