//go:build integration

package integration

import (
	"context"
	"encoding/base64"
	"testing"
	"time"

	"github.com/ollama/ollama/api"
	"github.com/stretchr/testify/require"
)

func TestIntegrationMultimodal(t *testing.T) {
	image, err := base64.StdEncoding.DecodeString(imageEncoding)
	require.NoError(t, err)
	req := api.GenerateRequest{
		Model:  "llava:7b",
		Prompt: "what does the text in this image say?",
		Stream: &stream,
		Options: map[string]interface{}{
			"seed":        42,
			"temperature": 0.0,
		},
		Images: []api.ImageData{
			image,
		},
	}

	// Note: sometimes it returns "the ollamas" sometimes "the ollams"
	resp := "the ollam"
	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
	defer cancel()
	client, _, cleanup := InitServerConnection(ctx, t)
	defer cleanup()
	require.NoError(t, PullIfMissing(ctx, client, req.Model))
	// llava models on CPU can be quite slow to start,
	DoGenerate(ctx, t, client, req, []string{resp}, 120*time.Second, 30*time.Second)
}

const imageEncoding = `iVBORw0KGgoAAAANSUhEUgAAANIAAAB4CAYAAACHHqzKAAAAAXNSR0IArs4c6QAAAIRlWElmTU0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUAAAABAAAASgEb
[encoded data, 59774 characters]
voQTefWxZ9CMIP9/0Wj1ClQSO/4AAAAASUVORK5CYII=`
