Files
photoprism/internal/ai/vision/caption_test.go
Michael Mayer e5dc335bcf AI: Include NSFW flag & score when generating labels with Ollama #5232
Related issues: #5233 (reset command), #5234 (schedule for models)

Signed-off-by: Michael Mayer <michael@photoprism.app>
2025-10-05 04:23:36 +02:00

44 lines
1.1 KiB
Go

package vision
import (
"net"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/photoprism/photoprism/pkg/media"
)
func TestGenerateCaption(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
} else if _, err := net.DialTimeout("tcp", "photoprism-vision:5000", 10*time.Second); err != nil {
t.Skip("skipping test because photoprism-vision is not running.")
}
t.Run("Success", func(t *testing.T) {
expectedText := "An image of sound waves"
result, model, err := GenerateCaption(Files{"https://dl.photoprism.app/img/artwork/colorwaves-400.jpg"}, media.SrcRemote)
assert.NoError(t, err)
assert.NotNil(t, model)
assert.IsType(t, CaptionResult{}, result)
assert.LessOrEqual(t, float32(0.0), result.Confidence)
t.Logf("caption: %#v", result)
assert.Equal(t, expectedText, result.Text)
})
t.Run("Invalid", func(t *testing.T) {
result, model, err := GenerateCaption(nil, media.SrcLocal)
assert.Error(t, err)
assert.Nil(t, model)
assert.IsType(t, CaptionResult{}, result)
assert.Equal(t, "", result.Text)
assert.Equal(t, float32(0.0), result.Confidence)
})
}