google

package
v0.12.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

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)

Index

Constants

View Source
const (
	// GoogleAPIURL is the base URL for the Google Generative AI API
	GoogleAPIURL = "https://generativelanguage.googleapis.com"

	// SummarizeModel is the model used for file summarization
	SummarizeModel = "gemini-2.5-flash-lite"

	// Mode constants
	ModeQuickSummary = "quick"
	ModeUseful       = "useful"
	ModePublicCode   = "publiccode"
	ModeHTMLContent  = "htmlcontent"
	ModeHTMLFull     = "htmlfull"

	// SummarizePrompt is the default prompt used for file summarization
	SummarizePrompt = "Please provide a concise summary of this file. Include the main topics, key points, and any notable information."

	// QuickSummaryPrompt is the prompt for quick file summaries
	QuickSummaryPrompt = `` /* 705-byte string literal not displayed */

	// UsefulSummaryPrompt is the prompt for useful file summaries with more detail
	UsefulSummaryPrompt = `` /* 1147-byte string literal not displayed */

	// PublicCodeSummaryPrompt is the prompt for public API summaries
	PublicCodeSummaryPrompt = `` /* 1762-byte string literal not displayed */

	// HTMLContentPrompt is the prompt for converting HTML to content-focused Markdown
	HTMLContentPrompt = `` /* 1157-byte string literal not displayed */

	// HTMLFullPrompt is the prompt for converting HTML to navigation-focused Markdown
	HTMLFullPrompt = `` /* 937-byte string literal not displayed */

)

Variables

This section is empty.

Functions

This section is empty.

Types

type GoogleUsage

type GoogleUsage struct {
	PromptTokenCount        int32 `json:"prompt_token_count"`
	CachedContentTokenCount int32 `json:"cached_content_token_count"`
	CandidatesTokenCount    int32 `json:"candidates_token_count"`
	TotalTokenCount         int32 `json:"total_token_count"`
}

GoogleUsage represents token usage information from Google's Generative AI API

func SummarizeFile

func SummarizeFile(ctx context.Context, filename string, opts SummarizeOpts) (string, *GoogleUsage, error)

SummarizeFile reads a file and generates a summary using Google's Generative AI. It supports images, PDFs, and text files based on the limits defined in wshcmd-ai.go. Returns the summary text, usage information, and any error encountered.

type SummarizeOpts

type SummarizeOpts struct {
	APIKey string
	Mode   string
}

SummarizeOpts contains options for file summarization

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL