68b170126d
- Updated `InitAISummarizerClient` to accept `mongoManager` for tracking translation success. - Introduced new `Statistics` endpoint in the dashboard to fetch scraping and translation statistics. - Enhanced `TranslationWorker` to utilize the new success counter for tracking successful translations. - Added necessary data structures and query forms for statistics reporting. This refactor improves the tracking of AI translation success and provides new insights through the dashboard statistics.
82 lines
2.7 KiB
Go
82 lines
2.7 KiB
Go
package ai_summarizer
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// Config holds the configuration for the AI Summarizer service.
|
|
// It contains settings for both the HTTP API and the MinIO storage integration.
|
|
type Config struct {
|
|
// HTTP API settings
|
|
APIBaseURL string // Base URL of the AI service, e.g. "http://ai-host:8000"
|
|
APITimeout time.Duration // Timeout for HTTP requests to the AI API
|
|
APIRetryCount int // Number of retry attempts for failed API requests
|
|
APIRetryDelay time.Duration // Delay between retry attempts
|
|
|
|
// OnSuccessfulTranslation is called after a successful POST /ai/translate request.
|
|
// source identifies the caller (daily_job or manual_trigger).
|
|
OnSuccessfulTranslation func(ctx context.Context, source string) error
|
|
|
|
// MinIO storage settings
|
|
MinioEndpoint string // MinIO endpoint, e.g. "ai-host:9000"
|
|
MinioAccessKey string // MinIO access key ID
|
|
MinioSecretKey string // MinIO secret access key
|
|
MinioUseSSL bool // Whether to use SSL for MinIO connection
|
|
MinioRegion string // MinIO region
|
|
MinioBucket string // MinIO bucket name (default: "opplens-documents")
|
|
MinioTimeout time.Duration // Timeout for MinIO operations
|
|
}
|
|
|
|
// DefaultConfig returns a Config with sensible defaults.
|
|
func DefaultConfig() *Config {
|
|
return &Config{
|
|
APITimeout: 120 * time.Second,
|
|
APIRetryCount: 2,
|
|
APIRetryDelay: 3 * time.Second,
|
|
|
|
MinioBucket: "opplens-documents",
|
|
MinioRegion: "us-east-1",
|
|
MinioUseSSL: false,
|
|
MinioTimeout: 30 * time.Second,
|
|
}
|
|
}
|
|
|
|
// Validate checks that all required configuration fields are present.
|
|
// Use this when both HTTP API and MinIO storage are needed.
|
|
func (c *Config) Validate() error {
|
|
if c.APIBaseURL == "" {
|
|
return errors.New("ai_summarizer: APIBaseURL is required")
|
|
}
|
|
return c.ValidateStorage()
|
|
}
|
|
|
|
// ValidateStorage checks only the MinIO storage-related configuration fields.
|
|
// Use this when only the storage client is needed (no HTTP API).
|
|
func (c *Config) ValidateStorage() error {
|
|
if c.MinioEndpoint == "" {
|
|
return errors.New("ai_summarizer: MinioEndpoint is required")
|
|
}
|
|
if c.MinioAccessKey == "" {
|
|
return errors.New("ai_summarizer: MinioAccessKey is required")
|
|
}
|
|
if c.MinioSecretKey == "" {
|
|
return errors.New("ai_summarizer: MinioSecretKey is required")
|
|
}
|
|
if c.MinioBucket == "" {
|
|
return fmt.Errorf("ai_summarizer: MinioBucket is required")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// ValidateAPI checks only the HTTP API-related configuration fields.
|
|
// Use this when only the HTTP client is needed (no MinIO storage).
|
|
func (c *Config) ValidateAPI() error {
|
|
if c.APIBaseURL == "" {
|
|
return errors.New("ai_summarizer: APIBaseURL is required")
|
|
}
|
|
return nil
|
|
}
|