interactive_test.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package cmd
  2. import (
  3. "testing"
  4. "github.com/google/go-cmp/cmp"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/ollama/ollama/api"
  7. )
  8. func TestExtractFilenames(t *testing.T) {
  9. // Unix style paths
  10. input := ` some preamble
  11. ./relative\ path/one.png inbetween1 ./not a valid two.jpg inbetween2 ./1.svg
  12. /unescaped space /three.jpeg inbetween3 /valid\ path/dir/four.png "./quoted with spaces/five.JPG`
  13. res := extractFileNames(input)
  14. assert.Len(t, res, 5)
  15. assert.Contains(t, res[0], "one.png")
  16. assert.Contains(t, res[1], "two.jpg")
  17. assert.Contains(t, res[2], "three.jpeg")
  18. assert.Contains(t, res[3], "four.png")
  19. assert.Contains(t, res[4], "five.JPG")
  20. assert.NotContains(t, res[4], '"')
  21. assert.NotContains(t, res, "inbetween1")
  22. assert.NotContains(t, res, "./1.svg")
  23. // Windows style paths
  24. input = ` some preamble
  25. c:/users/jdoe/one.png inbetween1 c:/program files/someplace/two.jpg inbetween2
  26. /absolute/nospace/three.jpeg inbetween3 /absolute/with space/four.png inbetween4
  27. ./relative\ path/five.JPG inbetween5 "./relative with/spaces/six.png inbetween6
  28. d:\path with\spaces\seven.JPEG inbetween7 c:\users\jdoe\eight.png inbetween8
  29. d:\program files\someplace\nine.png inbetween9 "E:\program files\someplace\ten.PNG some ending
  30. `
  31. res = extractFileNames(input)
  32. assert.Len(t, res, 10)
  33. assert.NotContains(t, res, "inbetween2")
  34. assert.Contains(t, res[0], "one.png")
  35. assert.Contains(t, res[0], "c:")
  36. assert.Contains(t, res[1], "two.jpg")
  37. assert.Contains(t, res[1], "c:")
  38. assert.Contains(t, res[2], "three.jpeg")
  39. assert.Contains(t, res[3], "four.png")
  40. assert.Contains(t, res[4], "five.JPG")
  41. assert.Contains(t, res[5], "six.png")
  42. assert.Contains(t, res[6], "seven.JPEG")
  43. assert.Contains(t, res[6], "d:")
  44. assert.Contains(t, res[7], "eight.png")
  45. assert.Contains(t, res[7], "c:")
  46. assert.Contains(t, res[8], "nine.png")
  47. assert.Contains(t, res[8], "d:")
  48. assert.Contains(t, res[9], "ten.PNG")
  49. assert.Contains(t, res[9], "E:")
  50. }
  51. func TestModelfileBuilder(t *testing.T) {
  52. opts := runOptions{
  53. Model: "hork",
  54. System: "You are part horse and part shark, but all hork. Do horklike things",
  55. Messages: []api.Message{
  56. {Role: "user", Content: "Hey there hork!"},
  57. {Role: "assistant", Content: "Yes it is true, I am half horse, half shark."},
  58. },
  59. Options: map[string]any{
  60. "temperature": 0.9,
  61. "seed": 42,
  62. "penalize_newline": false,
  63. "stop": []string{"hi", "there"},
  64. },
  65. }
  66. t.Run("model", func(t *testing.T) {
  67. expect := `FROM hork
  68. SYSTEM You are part horse and part shark, but all hork. Do horklike things
  69. PARAMETER penalize_newline false
  70. PARAMETER seed 42
  71. PARAMETER stop hi
  72. PARAMETER stop there
  73. PARAMETER temperature 0.9
  74. MESSAGE user Hey there hork!
  75. MESSAGE assistant Yes it is true, I am half horse, half shark.
  76. `
  77. actual := buildModelfile(opts)
  78. if diff := cmp.Diff(expect, actual); diff != "" {
  79. t.Errorf("mismatch (-want +got):\n%s", diff)
  80. }
  81. })
  82. t.Run("parent model", func(t *testing.T) {
  83. opts.ParentModel = "horseshark"
  84. expect := `FROM horseshark
  85. SYSTEM You are part horse and part shark, but all hork. Do horklike things
  86. PARAMETER penalize_newline false
  87. PARAMETER seed 42
  88. PARAMETER stop hi
  89. PARAMETER stop there
  90. PARAMETER temperature 0.9
  91. MESSAGE user Hey there hork!
  92. MESSAGE assistant Yes it is true, I am half horse, half shark.
  93. `
  94. actual := buildModelfile(opts)
  95. if diff := cmp.Diff(expect, actual); diff != "" {
  96. t.Errorf("mismatch (-want +got):\n%s", diff)
  97. }
  98. })
  99. }