service

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Embedder

type Embedder interface {
	Embed(ctx context.Context, text string) ([]float32, error)
}

Embedder generates vector embeddings from text.

type HybridMatch

type HybridMatch struct {
	ID        uuid.UUID       `json:"id"`
	YouTubeID string          `json:"youtube_id"`
	Title     string          `json:"title"`
	Channel   string          `json:"channel"`
	Summary   string          `json:"summary"`
	Metadata  json.RawMessage `json:"metadata"`
	Score     float64         `json:"score"`
	MatchType string          `json:"match_type"`
	CreatedAt time.Time       `json:"created_at"`
}

HybridMatch is a search result from hybrid (keyword + semantic) search.

type ImportResult

type ImportResult struct {
	Total    int `json:"total"`
	Imported int `json:"imported"`
	Skipped  int `json:"skipped"`
}

ImportResult holds the result of a Karakeep import.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service contains all business logic for vimmary.

func New

func New(
	db *storage.DB,
	summarizers map[string]summary.Summarizer,
	defaultProvider string,
	registry *models.Registry,
	yt *youtube.Client,
	karakeepBaseURL string,
	externalURL string,
	embedder Embedder,
	transcriber Transcriber,
	searchCfg config.SearchConfig,
	summaryCfg config.SummaryConfig,
	log *slog.Logger,
) *Service

New creates a new Service.

func (*Service) AvailableProviders

func (s *Service) AvailableProviders() []string

AvailableProviders returns the names of all configured summarizer providers.

func (*Service) BackfillMetadata

func (s *Service) BackfillMetadata(ctx context.Context, userID int) (int, error)

BackfillMetadata fetches and saves metadata for videos that have an empty title.

func (*Service) DefaultProvider

func (s *Service) DefaultProvider() string

DefaultProvider returns the name of the default summarizer provider.

func (*Service) DeleteByBookmarkID

func (s *Service) DeleteByBookmarkID(ctx context.Context, userID int, bookmarkID string) error

DeleteByBookmarkID removes a video by its Karakeep bookmark ID.

func (*Service) DeleteVideo

func (s *Service) DeleteVideo(ctx context.Context, userID int, id uuid.UUID) error

DeleteVideo removes a video from the database.

func (*Service) GetFeedInfo added in v1.1.0

func (s *Service) GetFeedInfo(ctx context.Context, userID int) (string, error)

GetFeedInfo returns the feed token for a user, generating one if needed.

func (*Service) GetModelPreference

func (s *Service) GetModelPreference(ctx context.Context, userID int) (provider, model string, err error)

GetModelPreference returns the user's preferred summary model.

func (*Service) GetSummaryPrompts

func (s *Service) GetSummaryPrompts(ctx context.Context, userID int) (*SummaryPromptsInfo, error)

GetSummaryPrompts returns the user's current and default prompts.

func (*Service) GetVideo

func (s *Service) GetVideo(ctx context.Context, userID int, id uuid.UUID) (*storage.Video, error)

GetVideo returns a single video by ID.

func (*Service) GetWebhookInfo

func (s *Service) GetWebhookInfo(ctx context.Context, userID int) (token string, err error)

GetWebhookInfo returns the webhook URL and token for a user.

func (*Service) HasKarakeepAPIKey

func (s *Service) HasKarakeepAPIKey(ctx context.Context, userID int) (bool, error)

HasKarakeepAPIKey returns whether a user has a Karakeep API key set.

func (*Service) ImportKarakeepBookmarks

func (s *Service) ImportKarakeepBookmarks(ctx context.Context, userID int) (*ImportResult, error)

ImportKarakeepBookmarks imports all YouTube bookmarks from a user's Karakeep account.

func (*Service) KarakeepBaseURL

func (s *Service) KarakeepBaseURL() string

KarakeepBaseURL returns the configured Karakeep base URL.

func (*Service) ListAllModels

func (s *Service) ListAllModels(ctx context.Context) []models.Model

ListAllModels returns available models from all configured providers.

func (*Service) ListRecent

func (s *Service) ListRecent(ctx context.Context, userID int, filters storage.ListFilters, limit, offset int) ([]storage.Video, int, error)

ListRecent returns recent completed videos with optional filters.

func (*Service) ProcessVideo

func (s *Service) ProcessVideo(ctx context.Context, userID int, youtubeID, bookmarkID string, forceVoxtral ...bool) error

ProcessVideo fetches transcript, generates summary, creates embedding, stores in DB, and writes back to Karakeep. If forceVoxtral is true, it skips InnerTube captions and goes straight to audio extraction + Voxtral transcription.

func (*Service) ProcessVideoAsync

func (s *Service) ProcessVideoAsync(userID int, youtubeID, bookmarkID string)

ProcessVideoAsync enqueues a video for background processing. All jobs go through a single rate-limited worker to avoid YouTube 429s.

func (*Service) Resummarize

func (s *Service) Resummarize(ctx context.Context, userID int, videoID uuid.UUID, level, language, provider string) error

Resummarize regenerates the summary for a video with a new detail level.

func (*Service) ResummarizeAsync

func (s *Service) ResummarizeAsync(userID int, videoID uuid.UUID, level, language, provider string) error

ResummarizeAsync starts resummarization in a background goroutine.

func (*Service) RetryAllFailed

func (s *Service) RetryAllFailed(ctx context.Context, userID int) (int, error)

RetryAllFailed resets all failed videos for a user and re-enqueues them.

func (*Service) RetryVideo

func (s *Service) RetryVideo(ctx context.Context, userID int, id uuid.UUID) error

RetryVideo resets a failed video and re-processes it.

func (*Service) Search

func (s *Service) Search(ctx context.Context, userID int, query string, limit int) ([]HybridMatch, []string, error)

Search runs hybrid (keyword + semantic) search with RRF merging.

func (*Service) SetKarakeepAPIKey

func (s *Service) SetKarakeepAPIKey(ctx context.Context, userID int, apiKey string) error

SetKarakeepAPIKey stores a Karakeep API key for a user.

func (*Service) SetModelPreference

func (s *Service) SetModelPreference(ctx context.Context, userID int, provider, model string) error

SetModelPreference sets the user's preferred summary model.

func (*Service) SetSummaryPrompt

func (s *Service) SetSummaryPrompt(ctx context.Context, userID int, level, prompt string) error

SetSummaryPrompt sets a custom prompt for the given level. Empty string resets to default.

func (*Service) Stats

func (s *Service) Stats(ctx context.Context, userID int) (*storage.VideoStats, error)

Stats returns aggregate statistics.

func (*Service) TranscribeAllNoCaptions

func (s *Service) TranscribeAllNoCaptions(ctx context.Context, userID int) (int, error)

TranscribeAllNoCaptions queues all no_captions videos for Voxtral audio transcription.

func (*Service) TranscribeVideo

func (s *Service) TranscribeVideo(ctx context.Context, userID int, id uuid.UUID) error

TranscribeVideo queues a no_captions video for Voxtral audio transcription.

type SummaryPromptsInfo

type SummaryPromptsInfo struct {
	Medium        string `json:"medium"`
	Deep          string `json:"deep"`
	DefaultMedium string `json:"default_medium"`
	DefaultDeep   string `json:"default_deep"`
}

SummaryPromptsInfo holds the current and default prompts for the API.

type Transcriber

type Transcriber interface {
	Transcribe(ctx context.Context, audioPath string) (string, error)
}

Transcriber transcribes audio files to text.

Jump to

Keyboard shortcuts

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