Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions cmd/testsummarize/main-testsummarize.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright 2025, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0

package main

import (
"context"
"flag"
"fmt"
"os"
"time"

"github.com/wavetermdev/waveterm/pkg/aiusechat/google"
)

func printUsage() {
fmt.Println("Usage: go run main-testsummarize.go [--help] [--mode MODE] <filename>")
fmt.Println("Examples:")
fmt.Println(" go run main-testsummarize.go README.md")
fmt.Println(" go run main-testsummarize.go --mode useful /path/to/image.png")
fmt.Println(" go run main-testsummarize.go -m publiccode document.pdf")
fmt.Println("")
fmt.Println("Supported file types:")
fmt.Println(" - Text files (up to 200KB)")
fmt.Println(" - Images (up to 7MB)")
fmt.Println(" - PDFs (up to 5MB)")
fmt.Println("")
fmt.Println("Flags:")
fmt.Println(" --mode, -m Summarization mode (default: quick)")
fmt.Println(" Options: quick, useful, publiccode, htmlcontent, htmlfull")
fmt.Println("")
fmt.Println("Environment variables:")
fmt.Println(" GOOGLE_APIKEY (required)")
}

func main() {
var showHelp bool
var mode string
flag.BoolVar(&showHelp, "help", false, "Show usage information")
flag.StringVar(&mode, "mode", "quick", "Summarization mode")
flag.StringVar(&mode, "m", "quick", "Summarization mode (shorthand)")
flag.Parse()

if showHelp {
printUsage()
os.Exit(0)
}

apiKey := os.Getenv("GOOGLE_APIKEY")
if apiKey == "" {
fmt.Println("Error: GOOGLE_APIKEY environment variable not set")
printUsage()
os.Exit(1)
}

args := flag.Args()
if len(args) == 0 {
fmt.Println("Error: filename required")
printUsage()
os.Exit(1)
}

filename := args[0]

// Check if file exists
if _, err := os.Stat(filename); os.IsNotExist(err) {
fmt.Printf("Error: file '%s' does not exist\n", filename)
os.Exit(1)
}

ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
defer cancel()

fmt.Printf("Summarizing file: %s\n", filename)
fmt.Printf("Model: %s\n", google.SummarizeModel)
fmt.Printf("Mode: %s\n", mode)

startTime := time.Now()
summary, usage, err := google.SummarizeFile(ctx, filename, google.SummarizeOpts{
APIKey: apiKey,
Mode: mode,
})
latency := time.Since(startTime)

fmt.Printf("Latency: %d ms\n", latency.Milliseconds())
fmt.Println("===")
if err != nil {
fmt.Printf("Error: %v\n", err)
os.Exit(1)
}

fmt.Println("\nSummary:")
fmt.Println("---")
fmt.Println(summary)
fmt.Println("---")

if usage != nil {
fmt.Println("\nUsage Statistics:")
fmt.Printf(" Prompt tokens: %d\n", usage.PromptTokenCount)
fmt.Printf(" Cached tokens: %d\n", usage.CachedContentTokenCount)
fmt.Printf(" Response tokens: %d\n", usage.CandidatesTokenCount)
fmt.Printf(" Total tokens: %d\n", usage.TotalTokenCount)
}
}
41 changes: 41 additions & 0 deletions pkg/aiusechat/google/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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
Loading
Loading