From e580fb57a29ec3c3f3e180b20cfa6ec28687689b Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 20 Jul 2025 22:18:57 +0300 Subject: Refactor main.go into focused packages - Reduced main.go from 961 lines to 89 lines (91% reduction) - Created new packages for better separation of concerns: - cli: Command-line interface setup and configuration - processor: Core word processing logic and orchestration - batch: Batch file processing functionality - translation: Bulgarian to English translation services - models: OpenAI model listing functionality - phonetic: Phonetic information fetching - Each package has clear documentation in doc.go files - Improved testability and maintainability - All existing functionality preserved - All tests passing and build successful --- internal/models/doc.go | 4 ++ internal/models/lister.go | 100 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 internal/models/doc.go create mode 100644 internal/models/lister.go (limited to 'internal/models') diff --git a/internal/models/doc.go b/internal/models/doc.go new file mode 100644 index 0000000..116a04a --- /dev/null +++ b/internal/models/doc.go @@ -0,0 +1,4 @@ +// Package models provides functionality for listing and categorizing +// available OpenAI models. It helps users discover which TTS, image +// generation, and chat models are available with their API key. +package models diff --git a/internal/models/lister.go b/internal/models/lister.go new file mode 100644 index 0000000..bb383bc --- /dev/null +++ b/internal/models/lister.go @@ -0,0 +1,100 @@ +package models + +import ( + "context" + "fmt" + "sort" + "strings" + + "github.com/sashabaranov/go-openai" +) + +// Lister handles listing available OpenAI models +type Lister struct { + apiKey string + client *openai.Client +} + +// NewLister creates a new model lister +func NewLister(apiKey string) *Lister { + return &Lister{ + apiKey: apiKey, + client: openai.NewClient(apiKey), + } +} + +// ListAvailableModels lists all available OpenAI models categorized by type +func (l *Lister) ListAvailableModels() error { + if l.apiKey == "" { + return fmt.Errorf("OpenAI API key not found. Set OPENAI_API_KEY environment variable or configure in .totalrecall.yaml") + } + + // List models + ctx := context.Background() + models, err := l.client.ListModels(ctx) + if err != nil { + return fmt.Errorf("failed to list models: %w", err) + } + + // Categorize models + ttsModels := []string{} + imageModels := []string{} + chatModels := []string{} + + for _, model := range models.Models { + modelID := model.ID + if strings.Contains(modelID, "tts") || strings.Contains(modelID, "audio") { + ttsModels = append(ttsModels, modelID) + } else if strings.Contains(modelID, "dall-e") { + imageModels = append(imageModels, modelID) + } else if strings.Contains(modelID, "gpt") || strings.Contains(modelID, "chat") { + chatModels = append(chatModels, modelID) + } + } + + // Sort models + sort.Strings(ttsModels) + sort.Strings(imageModels) + sort.Strings(chatModels) + + // Print models + fmt.Println("Available OpenAI Models:") + fmt.Println("\nText-to-Speech (TTS) Models:") + if len(ttsModels) == 0 { + fmt.Println(" No TTS models found") + } else { + for _, model := range ttsModels { + fmt.Printf(" %s\n", model) + } + } + + fmt.Println("\nImage Generation Models:") + if len(imageModels) == 0 { + fmt.Println(" No image models found") + } else { + for _, model := range imageModels { + fmt.Printf(" %s\n", model) + } + } + + fmt.Println("\nChat/Translation Models (for Bulgarian translation):") + if len(chatModels) > 10 { + // Show only relevant models + relevantModels := []string{} + for _, model := range chatModels { + if strings.Contains(model, "gpt-4") || strings.Contains(model, "gpt-3.5") { + relevantModels = append(relevantModels, model) + } + } + for _, model := range relevantModels { + fmt.Printf(" %s\n", model) + } + fmt.Printf(" ... and %d more models\n", len(chatModels)-len(relevantModels)) + } else { + for _, model := range chatModels { + fmt.Printf(" %s\n", model) + } + } + + return nil +} -- cgit v1.2.3