diff --git a/README.md b/README.md index 1e8f1fb..cac956b 100644 --- a/README.md +++ b/README.md @@ -184,6 +184,7 @@ paperless-gpt’s flexible **prompt templates** let you shape how AI responds: 1. **`title_prompt.tmpl`**: For document titles. 2. **`tag_prompt.tmpl`**: For tagging logic. 3. **`ocr_prompt.tmpl`**: For LLM OCR. +4. **`correspondent_prompt.tmpl`**: For correspondent identification. Mount them into your container via: @@ -194,6 +195,34 @@ Mount them into your container via: Then tweak at will—**paperless-gpt** reloads them automatically on startup! +#### Template Variables + +Each template has access to specific variables: + +**title_prompt.tmpl**: +- `{{.Language}}` - Target language (e.g., "English") +- `{{.Content}}` - Document content text +- `{{.Title}}` - Original document title + +**tag_prompt.tmpl**: +- `{{.Language}}` - Target language +- `{{.AvailableTags}}` - List of existing tags in paperless-ngx +- `{{.OriginalTags}}` - Document's current tags +- `{{.Title}}` - Document title +- `{{.Content}}` - Document content text + +**ocr_prompt.tmpl**: +- `{{.Language}}` - Target language + +**correspondent_prompt.tmpl**: +- `{{.Language}}` - Target language +- `{{.AvailableCorrespondents}}` - List of existing correspondents +- `{{.BlackList}}` - List of blacklisted correspondent names +- `{{.Title}}` - Document title +- `{{.Content}}` - Document content text + +The templates use Go's text/template syntax. paperless-gpt automatically reloads template changes on startup. + --- ## Usage diff --git a/app_llm.go b/app_llm.go index d1c6310..89620d0 100644 --- a/app_llm.go +++ b/app_llm.go @@ -191,7 +191,7 @@ func (app *App) doOCRViaLLM(ctx context.Context, jpegBytes []byte, logger *logru } // getSuggestedTitle generates a suggested title for a document using the LLM -func (app *App) getSuggestedTitle(ctx context.Context, content string, suggestedTitle string, logger *logrus.Entry) (string, error) { +func (app *App) getSuggestedTitle(ctx context.Context, content string, originalTitle string, logger *logrus.Entry) (string, error) { likelyLanguage := getLikelyLanguage() templateMutex.RLock() @@ -201,7 +201,7 @@ func (app *App) getSuggestedTitle(ctx context.Context, content string, suggested err := titleTemplate.Execute(&promptBuffer, map[string]interface{}{ "Language": likelyLanguage, "Content": content, - "Title": suggestedTitle, + "Title": originalTitle, }) if err != nil { return "", fmt.Errorf("error executing title template: %v", err)