basic_test.go 3.3 KB
Newer Older
1
2
3
4
5
6
//go:build integration

package integration

import (
	"context"
Daniel Hiltgen's avatar
Daniel Hiltgen committed
7
8
9
	"log/slog"
	"os"
	"runtime"
10
11
12
	"testing"
	"time"

13
	"github.com/ollama/ollama/api"
14
15
)

16
func TestBlueSky(t *testing.T) {
17
	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
18
19
20
	defer cancel()
	// Set up the test data
	req := api.GenerateRequest{
21
		Model:  smol,
22
23
		Prompt: "why is the sky blue?",
		Stream: &stream,
24
		Options: map[string]any{
25
26
27
28
			"temperature": 0,
			"seed":        123,
		},
	}
Daniel Hiltgen's avatar
Daniel Hiltgen committed
29
	GenerateTestHelper(ctx, t, req, []string{"rayleigh", "scattering"})
30
}
Daniel Hiltgen's avatar
Daniel Hiltgen committed
31

32
func TestUnicode(t *testing.T) {
33
	skipUnderMinVRAM(t, 6)
34
	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
35
36
37
38
	defer cancel()
	// Set up the test data
	req := api.GenerateRequest{
		// DeepSeek has a Unicode tokenizer regex, making it a unicode torture test
39
40
		Model:  "deepseek-coder-v2:16b-lite-instruct-q2_K", // TODO is there an ollama-engine model we can switch to and keep the coverage?
		Prompt: "天空为什么是蓝色的?",                               // Why is the sky blue?
41
		Stream: &stream,
42
		Options: map[string]any{
43
44
			"temperature": 0,
			"seed":        123,
45
46
47
			// Workaround deepseek context shifting bug
			"num_ctx":     8192,
			"num_predict": 2048,
48
49
		},
	}
50
51
	client, _, cleanup := InitServerConnection(ctx, t)
	defer cleanup()
52
53
54
55
56
57
58
59
60
61
62
63
64
65
	if err := PullIfMissing(ctx, client, req.Model); err != nil {
		t.Fatal(err)
	}
	slog.Info("loading", "model", req.Model)
	err := client.Generate(ctx, &api.GenerateRequest{Model: req.Model}, func(response api.GenerateResponse) error { return nil })
	if err != nil {
		t.Fatalf("failed to load model %s: %s", req.Model, err)
	}
	skipIfNotGPULoaded(ctx, t, client, req.Model, 100)

	DoGenerate(ctx, t, client, req, []string{
		"散射", // scattering
		"频率", // frequency
	}, 120*time.Second, 120*time.Second)
66
67
68
}

func TestExtendedUnicodeOutput(t *testing.T) {
69
70
71
72
73
74
75
	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
	defer cancel()
	// Set up the test data
	req := api.GenerateRequest{
		Model:  "gemma2:2b",
		Prompt: "Output some smily face emoji",
		Stream: &stream,
76
		Options: map[string]any{
77
78
79
80
			"temperature": 0,
			"seed":        123,
		},
	}
81
82
	client, _, cleanup := InitServerConnection(ctx, t)
	defer cleanup()
83
84
85
	if err := PullIfMissing(ctx, client, req.Model); err != nil {
		t.Fatal(err)
	}
86
	DoGenerate(ctx, t, client, req, []string{"😀", "😊", "😁", "😂", "😄", "😃"}, 120*time.Second, 120*time.Second)
87
88
}

Daniel Hiltgen's avatar
Daniel Hiltgen committed
89
90
91
92
93
94
95
96
97
98
99
func TestUnicodeModelDir(t *testing.T) {
	// This is only useful for Windows with utf-16 characters, so skip this test for other platforms
	if runtime.GOOS != "windows" {
		t.Skip("Unicode test only applicable to windows")
	}
	// Only works for local testing
	if os.Getenv("OLLAMA_TEST_EXISTING") != "" {
		t.Skip("TestUnicodeModelDir only works for local testing, skipping")
	}

	modelDir, err := os.MkdirTemp("", "ollama_埃")
100
101
102
	if err != nil {
		t.Fatal(err)
	}
Daniel Hiltgen's avatar
Daniel Hiltgen committed
103
104
105
	defer os.RemoveAll(modelDir)
	slog.Info("unicode", "OLLAMA_MODELS", modelDir)

Michael Yang's avatar
int  
Michael Yang committed
106
	t.Setenv("OLLAMA_MODELS", modelDir)
Daniel Hiltgen's avatar
Daniel Hiltgen committed
107
108
109
110
111

	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
	defer cancel()

	req := api.GenerateRequest{
112
		Model:  smol,
Daniel Hiltgen's avatar
Daniel Hiltgen committed
113
114
		Prompt: "why is the sky blue?",
		Stream: &stream,
115
		Options: map[string]any{
Daniel Hiltgen's avatar
Daniel Hiltgen committed
116
117
118
119
120
121
			"temperature": 0,
			"seed":        123,
		},
	}
	GenerateTestHelper(ctx, t, req, []string{"rayleigh", "scattering"})
}