waveterm/pkg/aiusechat/google/doc.go
Copilot 0d04b99b46
Add Google AI file summarization package (#2455)
- [x] Create new directory pkg/aiusechat/google
- [x] Implement SummarizeFile function with:
  - Context parameter for timeout
  - File validation (images, PDFs, text files only)
  - Use gemini-2.5-flash-lite model
  - Configurable API URL and prompt as constants
  - Return (string, usage, error)
- [x] Define Google-specific usage struct
- [x] Test the implementation (all tests pass)
- [x] Verify with existing linting and build
- [x] Run CodeQL security check (no issues found)
- [x] Revert unintended tsunami demo dependency changes

## Summary

Successfully implemented a new Google AI package at
`pkg/aiusechat/google` with:

1. **SummarizeFile function** - A simple request-response API (not
streaming, not SSE)
   - Takes context for timeout
   - Validates file types (images, PDFs, text only) 
   - Enforces file size limits matching wshcmd-ai.go
   - Uses gemini-2.5-flash-lite model
   - Returns (summary string, usage stats, error)

2. **GoogleUsage struct** - Tracks token consumption:
   - PromptTokenCount
   - CachedContentTokenCount  
   - CandidatesTokenCount
   - TotalTokenCount

3. **Configurable constants**:
   - GoogleAPIURL (for reference)
   - SummarizePrompt (customizable prompt)
   - SummarizeModel (gemini-2.5-flash-lite)

4. **Comprehensive tests** - 41.7% coverage with all tests passing
5. **Security verified** - No CodeQL alerts
6. **Package documentation** - doc.go with usage examples

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
2025-10-17 17:24:06 -07:00

41 lines
1.4 KiB
Go

// Copyright 2025, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
// Package google provides Google Generative AI integration for WaveTerm.
//
// This package implements file summarization using Google's Gemini models.
// Unlike other AI provider implementations in the aiusechat package, this
// package does NOT implement full SSE streaming. It uses a simple
// request-response API for file summarization.
//
// # Supported File Types
//
// The package supports the same file types as defined in wshcmd-ai.go:
// - Images (PNG, JPEG, etc.): up to 7MB
// - PDFs: up to 5MB
// - Text files: up to 200KB
//
// Binary files are rejected unless they are recognized as images or PDFs.
//
// # Usage
//
// To summarize a file:
//
// ctx := context.Background()
// summary, usage, err := google.SummarizeFile(ctx, "/path/to/file.txt", google.SummarizeOpts{
// APIKey: "YOUR_API_KEY",
// Mode: google.ModeQuickSummary,
// })
// if err != nil {
// log.Fatal(err)
// }
// fmt.Println("Summary:", summary)
// fmt.Printf("Tokens used: %d\n", usage.TotalTokenCount)
//
// # Configuration
//
// The summarization behavior can be customized by modifying the constants:
// - SummarizeModel: The Gemini model to use (default: "gemini-2.5-flash-lite")
// - SummarizePrompt: The prompt sent to the model
// - GoogleAPIURL: The base URL for the API (for reference, not currently used by the SDK)
package google