basic_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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(), 2*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. },
  41. }
  42. GenerateTestHelper(ctx, t, req, []string{"散射", "频率"})
  43. }
  44. func TestExtendedUnicodeOutput(t *testing.T) {
  45. ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
  46. defer cancel()
  47. // Set up the test data
  48. req := api.GenerateRequest{
  49. Model: "gemma2:2b",
  50. Prompt: "Output some smily face emoji",
  51. Stream: &stream,
  52. Options: map[string]interface{}{
  53. "temperature": 0,
  54. "seed": 123,
  55. },
  56. }
  57. GenerateTestHelper(ctx, t, req, []string{"😀", "😊", "😁", "😂", "😄", "😃"})
  58. }
  59. func TestUnicodeModelDir(t *testing.T) {
  60. // This is only useful for Windows with utf-16 characters, so skip this test for other platforms
  61. if runtime.GOOS != "windows" {
  62. t.Skip("Unicode test only applicable to windows")
  63. }
  64. // Only works for local testing
  65. if os.Getenv("OLLAMA_TEST_EXISTING") != "" {
  66. t.Skip("TestUnicodeModelDir only works for local testing, skipping")
  67. }
  68. modelDir, err := os.MkdirTemp("", "ollama_埃")
  69. require.NoError(t, err)
  70. defer os.RemoveAll(modelDir)
  71. slog.Info("unicode", "OLLAMA_MODELS", modelDir)
  72. t.Setenv("OLLAMA_MODELS", modelDir)
  73. ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
  74. defer cancel()
  75. req := api.GenerateRequest{
  76. Model: "orca-mini",
  77. Prompt: "why is the sky blue?",
  78. Stream: &stream,
  79. Options: map[string]interface{}{
  80. "temperature": 0,
  81. "seed": 123,
  82. },
  83. }
  84. GenerateTestHelper(ctx, t, req, []string{"rayleigh", "scattering"})
  85. }