basic_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //go:build integration
  2. package integration
  3. import (
  4. "context"
  5. "log/slog"
  6. "os"
  7. "runtime"
  8. "testing"
  9. "time"
  10. "github.com/ollama/ollama/api"
  11. "github.com/stretchr/testify/require"
  12. )
  13. func TestOrcaMiniBlueSky(t *testing.T) {
  14. ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
  15. defer cancel()
  16. // Set up the test data
  17. req := api.GenerateRequest{
  18. Model: "orca-mini",
  19. Prompt: "why is the sky blue?",
  20. Stream: &stream,
  21. Options: map[string]interface{}{
  22. "temperature": 0,
  23. "seed": 123,
  24. },
  25. }
  26. GenerateTestHelper(ctx, t, req, []string{"rayleigh", "scattering"})
  27. }
  28. func TestUnicode(t *testing.T) {
  29. ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
  30. defer cancel()
  31. // Set up the test data
  32. req := api.GenerateRequest{
  33. // DeepSeek has a Unicode tokenizer regex, making it a unicode torture test
  34. Model: "deepseek-coder-v2:16b-lite-instruct-q2_K",
  35. Prompt: "天空为什么是蓝色的?",
  36. Stream: &stream,
  37. Options: map[string]interface{}{
  38. "temperature": 0,
  39. "seed": 123,
  40. // Workaround deepseek context shifting bug
  41. "num_ctx": 8192,
  42. "num_predict": 2048,
  43. },
  44. }
  45. client, _, cleanup := InitServerConnection(ctx, t)
  46. defer cleanup()
  47. require.NoError(t, PullIfMissing(ctx, client, req.Model))
  48. DoGenerate(ctx, t, client, req, []string{"散射", "频率"}, 120*time.Second, 120*time.Second)
  49. }
  50. func TestExtendedUnicodeOutput(t *testing.T) {
  51. ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
  52. defer cancel()
  53. // Set up the test data
  54. req := api.GenerateRequest{
  55. Model: "gemma2:2b",
  56. Prompt: "Output some smily face emoji",
  57. Stream: &stream,
  58. Options: map[string]interface{}{
  59. "temperature": 0,
  60. "seed": 123,
  61. },
  62. }
  63. client, _, cleanup := InitServerConnection(ctx, t)
  64. defer cleanup()
  65. require.NoError(t, PullIfMissing(ctx, client, req.Model))
  66. DoGenerate(ctx, t, client, req, []string{"😀", "😊", "😁", "😂", "😄", "😃"}, 120*time.Second, 120*time.Second)
  67. }
  68. func TestUnicodeModelDir(t *testing.T) {
  69. // This is only useful for Windows with utf-16 characters, so skip this test for other platforms
  70. if runtime.GOOS != "windows" {
  71. t.Skip("Unicode test only applicable to windows")
  72. }
  73. // Only works for local testing
  74. if os.Getenv("OLLAMA_TEST_EXISTING") != "" {
  75. t.Skip("TestUnicodeModelDir only works for local testing, skipping")
  76. }
  77. modelDir, err := os.MkdirTemp("", "ollama_埃")
  78. require.NoError(t, err)
  79. defer os.RemoveAll(modelDir)
  80. slog.Info("unicode", "OLLAMA_MODELS", modelDir)
  81. t.Setenv("OLLAMA_MODELS", modelDir)
  82. ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
  83. defer cancel()
  84. req := api.GenerateRequest{
  85. Model: "orca-mini",
  86. Prompt: "why is the sky blue?",
  87. Stream: &stream,
  88. Options: map[string]interface{}{
  89. "temperature": 0,
  90. "seed": 123,
  91. },
  92. }
  93. GenerateTestHelper(ctx, t, req, []string{"rayleigh", "scattering"})
  94. }