basic_test.go 2.45 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 TestOrcaMiniBlueSky(t *testing.T) {
18
	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
19
20
21
22
23
24
25
26
27
28
29
	defer cancel()
	// Set up the test data
	req := api.GenerateRequest{
		Model:  "orca-mini",
		Prompt: "why is the sky blue?",
		Stream: &stream,
		Options: map[string]interface{}{
			"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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
func TestUnicode(t *testing.T) {
	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
	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,
		Options: map[string]interface{}{
			"temperature": 0,
			"seed":        123,
		},
	}
	GenerateTestHelper(ctx, t, req, []string{"散射", "频率"})
}

func TestExtendedUnicodeOutput(t *testing.T) {
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
	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,
		Options: map[string]interface{}{
			"temperature": 0,
			"seed":        123,
		},
	}
	GenerateTestHelper(ctx, t, req, []string{"😀", "😊", "😁", "😂", "😄", "😃"})
}

Daniel Hiltgen's avatar
Daniel Hiltgen committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
81
	t.Setenv("OLLAMA_MODELS", modelDir)
Daniel Hiltgen's avatar
Daniel Hiltgen committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

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

	req := api.GenerateRequest{
		Model:  "orca-mini",
		Prompt: "why is the sky blue?",
		Stream: &stream,
		Options: map[string]interface{}{
			"temperature": 0,
			"seed":        123,
		},
	}
	GenerateTestHelper(ctx, t, req, []string{"rayleigh", "scattering"})
}