| 
									
										
										
										
											2024-03-23 21:24:18 +08:00
										 |  |  | //go:build integration
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package integration | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2024-04-17 04:42:52 +08:00
										 |  |  | 	"log/slog" | 
					
						
							|  |  |  | 	"os" | 
					
						
							|  |  |  | 	"runtime" | 
					
						
							| 
									
										
										
										
											2024-03-23 21:24:18 +08:00
										 |  |  | 	"testing" | 
					
						
							|  |  |  | 	"time" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-27 04:04:17 +08:00
										 |  |  | 	"github.com/ollama/ollama/api" | 
					
						
							| 
									
										
										
										
											2024-03-23 21:24:18 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-17 05:25:55 +08:00
										 |  |  | func TestBlueSky(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2024-03-25 07:22:38 +08:00
										 |  |  | 	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) | 
					
						
							| 
									
										
										
										
											2024-03-23 21:24:18 +08:00
										 |  |  | 	defer cancel() | 
					
						
							|  |  |  | 	// Set up the test data
 | 
					
						
							|  |  |  | 	req := api.GenerateRequest{ | 
					
						
							| 
									
										
										
										
											2025-04-17 05:25:55 +08:00
										 |  |  | 		Model:  smol, | 
					
						
							| 
									
										
										
										
											2024-03-23 21:24:18 +08:00
										 |  |  | 		Prompt: "why is the sky blue?", | 
					
						
							|  |  |  | 		Stream: &stream, | 
					
						
							| 
									
										
										
										
											2025-04-03 00:44:27 +08:00
										 |  |  | 		Options: map[string]any{ | 
					
						
							| 
									
										
										
										
											2024-03-23 21:24:18 +08:00
										 |  |  | 			"temperature": 0, | 
					
						
							|  |  |  | 			"seed":        123, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-03-31 00:50:05 +08:00
										 |  |  | 	GenerateTestHelper(ctx, t, req, []string{"rayleigh", "scattering"}) | 
					
						
							| 
									
										
										
										
											2024-03-23 21:24:18 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2024-04-17 04:42:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-24 06:28:30 +08:00
										 |  |  | func TestUnicode(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2025-04-17 05:25:55 +08:00
										 |  |  | 	skipUnderMinVRAM(t, 6) | 
					
						
							| 
									
										
										
										
											2024-11-01 04:35:31 +08:00
										 |  |  | 	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) | 
					
						
							| 
									
										
										
										
											2024-10-24 06:28:30 +08:00
										 |  |  | 	defer cancel() | 
					
						
							|  |  |  | 	// Set up the test data
 | 
					
						
							|  |  |  | 	req := api.GenerateRequest{ | 
					
						
							|  |  |  | 		// DeepSeek has a Unicode tokenizer regex, making it a unicode torture test
 | 
					
						
							| 
									
										
										
										
											2025-08-30 05:20:28 +08:00
										 |  |  | 		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?
 | 
					
						
							| 
									
										
										
										
											2024-10-24 06:28:30 +08:00
										 |  |  | 		Stream: &stream, | 
					
						
							| 
									
										
										
										
											2025-04-03 00:44:27 +08:00
										 |  |  | 		Options: map[string]any{ | 
					
						
							| 
									
										
										
										
											2024-10-24 06:28:30 +08:00
										 |  |  | 			"temperature": 0, | 
					
						
							|  |  |  | 			"seed":        123, | 
					
						
							| 
									
										
										
										
											2024-11-01 04:35:31 +08:00
										 |  |  | 			// Workaround deepseek context shifting bug
 | 
					
						
							|  |  |  | 			"num_ctx":     8192, | 
					
						
							|  |  |  | 			"num_predict": 2048, | 
					
						
							| 
									
										
										
										
											2024-10-24 06:28:30 +08:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-11-01 04:35:31 +08:00
										 |  |  | 	client, _, cleanup := InitServerConnection(ctx, t) | 
					
						
							|  |  |  | 	defer cleanup() | 
					
						
							| 
									
										
										
										
											2025-08-30 05:20:28 +08:00
										 |  |  | 	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) | 
					
						
							| 
									
										
										
										
											2024-10-24 06:28:30 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestExtendedUnicodeOutput(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2024-10-22 02:07:19 +08:00
										 |  |  | 	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, | 
					
						
							| 
									
										
										
										
											2025-04-03 00:44:27 +08:00
										 |  |  | 		Options: map[string]any{ | 
					
						
							| 
									
										
										
										
											2024-10-22 02:07:19 +08:00
										 |  |  | 			"temperature": 0, | 
					
						
							|  |  |  | 			"seed":        123, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-11-01 04:35:31 +08:00
										 |  |  | 	client, _, cleanup := InitServerConnection(ctx, t) | 
					
						
							|  |  |  | 	defer cleanup() | 
					
						
							| 
									
										
										
										
											2025-08-30 05:20:28 +08:00
										 |  |  | 	if err := PullIfMissing(ctx, client, req.Model); err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-11-01 04:35:31 +08:00
										 |  |  | 	DoGenerate(ctx, t, client, req, []string{"😀", "😊", "😁", "😂", "😄", "😃"}, 120*time.Second, 120*time.Second) | 
					
						
							| 
									
										
										
										
											2024-10-22 02:07:19 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-17 04:42:52 +08:00
										 |  |  | 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_埃") | 
					
						
							| 
									
										
										
										
											2025-08-30 05:20:28 +08:00
										 |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		t.Fatal(err) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2024-04-17 04:42:52 +08:00
										 |  |  | 	defer os.RemoveAll(modelDir) | 
					
						
							|  |  |  | 	slog.Info("unicode", "OLLAMA_MODELS", modelDir) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-04 10:41:17 +08:00
										 |  |  | 	t.Setenv("OLLAMA_MODELS", modelDir) | 
					
						
							| 
									
										
										
										
											2024-04-17 04:42:52 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) | 
					
						
							|  |  |  | 	defer cancel() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	req := api.GenerateRequest{ | 
					
						
							| 
									
										
										
										
											2025-04-17 05:25:55 +08:00
										 |  |  | 		Model:  smol, | 
					
						
							| 
									
										
										
										
											2024-04-17 04:42:52 +08:00
										 |  |  | 		Prompt: "why is the sky blue?", | 
					
						
							|  |  |  | 		Stream: &stream, | 
					
						
							| 
									
										
										
										
											2025-04-03 00:44:27 +08:00
										 |  |  | 		Options: map[string]any{ | 
					
						
							| 
									
										
										
										
											2024-04-17 04:42:52 +08:00
										 |  |  | 			"temperature": 0, | 
					
						
							|  |  |  | 			"seed":        123, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	GenerateTestHelper(ctx, t, req, []string{"rayleigh", "scattering"}) | 
					
						
							|  |  |  | } |