basic_test.go 2.83 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"
Daniel Hiltgen's avatar
Daniel Hiltgen committed
14
	"github.com/stretchr/testify/require"
15
16
)

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

33
func TestUnicode(t *testing.T) {
34
	skipUnderMinVRAM(t, 6)
35
	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
36
37
38
39
40
41
42
	defer cancel()
	// Set up the test data
	req := api.GenerateRequest{
		// DeepSeek has a Unicode tokenizer regex, making it a unicode torture test
		Model:  "deepseek-coder-v2:16b-lite-instruct-q2_K",
		Prompt: "天空为什么是蓝色的?",
		Stream: &stream,
43
		Options: map[string]any{
44
45
			"temperature": 0,
			"seed":        123,
46
47
48
			// Workaround deepseek context shifting bug
			"num_ctx":     8192,
			"num_predict": 2048,
49
50
		},
	}
51
52
53
54
	client, _, cleanup := InitServerConnection(ctx, t)
	defer cleanup()
	require.NoError(t, PullIfMissing(ctx, client, req.Model))
	DoGenerate(ctx, t, client, req, []string{"散射", "频率"}, 120*time.Second, 120*time.Second)
55
56
57
}

func TestExtendedUnicodeOutput(t *testing.T) {
58
59
60
61
62
63
64
	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,
65
		Options: map[string]any{
66
67
68
69
			"temperature": 0,
			"seed":        123,
		},
	}
70
71
72
73
	client, _, cleanup := InitServerConnection(ctx, t)
	defer cleanup()
	require.NoError(t, PullIfMissing(ctx, client, req.Model))
	DoGenerate(ctx, t, client, req, []string{"😀", "😊", "😁", "😂", "😄", "😃"}, 120*time.Second, 120*time.Second)
74
75
}

Daniel Hiltgen's avatar
Daniel Hiltgen committed
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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_埃")
	require.NoError(t, err)
	defer os.RemoveAll(modelDir)
	slog.Info("unicode", "OLLAMA_MODELS", modelDir)

Michael Yang's avatar
int  
Michael Yang committed
91
	t.Setenv("OLLAMA_MODELS", modelDir)
Daniel Hiltgen's avatar
Daniel Hiltgen committed
92
93
94
95
96

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

	req := api.GenerateRequest{
97
		Model:  smol,
Daniel Hiltgen's avatar
Daniel Hiltgen committed
98
99
		Prompt: "why is the sky blue?",
		Stream: &stream,
100
		Options: map[string]any{
Daniel Hiltgen's avatar
Daniel Hiltgen committed
101
102
103
104
105
106
			"temperature": 0,
			"seed":        123,
		},
	}
	GenerateTestHelper(ctx, t, req, []string{"rayleigh", "scattering"})
}