Files
s01e02/cmd/app/main.go
2026-03-12 02:10:57 +01:00

74 lines
2.1 KiB
Go

package main
import (
"context"
"flag"
"log"
"time"
"github.com/paramah/ai_devs4/s01e02/internal/config"
"github.com/paramah/ai_devs4/s01e02/internal/domain"
"github.com/paramah/ai_devs4/s01e02/internal/infrastructure/api"
"github.com/paramah/ai_devs4/s01e02/internal/infrastructure/json"
"github.com/paramah/ai_devs4/s01e02/internal/infrastructure/llm"
"github.com/paramah/ai_devs4/s01e02/internal/usecase"
)
func main() {
configPath := flag.String("config", "config.json", "Path to configuration file")
flag.Parse()
// Load configuration
cfg, err := config.Load(*configPath)
if err != nil {
log.Fatalf("Failed to load configuration: %v", err)
}
if err := cfg.Validate(); err != nil {
log.Fatalf("Invalid configuration: %v", err)
}
log.Printf("========== AI Agent Person Processor ==========")
log.Printf("Input file: %s", cfg.InputFile)
log.Printf("Output directory: %s", cfg.OutputDir)
log.Printf("LLM Provider: %s", cfg.LLM.Provider)
log.Printf("LLM Model: %s", cfg.LLM.Model)
log.Printf("===============================================\n")
// Create repositories and clients
personRepo := json.NewRepository()
apiClient := api.NewClient(cfg.LocationsAPI, cfg.AccessLevelAPI)
// Create LLM provider
var llmProvider domain.LLMProvider
switch cfg.LLM.Provider {
case "openrouter":
llmProvider = llm.NewOpenRouterProvider(cfg.LLM.APIKey, cfg.LLM.Model)
log.Printf("Using OpenRouter with model: %s", cfg.LLM.Model)
case "lmstudio":
llmProvider = llm.NewLMStudioProvider(cfg.LLM.BaseURL, cfg.LLM.Model)
log.Printf("Using LM Studio at %s with model: %s", cfg.LLM.BaseURL, cfg.LLM.Model)
default:
log.Fatalf("Unknown LLM provider: %s", cfg.LLM.Provider)
}
// Create person agent processor use case
personAgentUC := usecase.NewPersonAgentProcessorUseCase(
personRepo,
apiClient,
llmProvider,
cfg.APIKey,
cfg.OutputDir,
)
// Execute processing
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Minute)
defer cancel()
if err := personAgentUC.Execute(ctx, cfg.InputFile); err != nil {
log.Fatalf("Failed to process persons: %v", err)
}
log.Printf("\n========== All tasks completed successfully! ==========")
}