interactive_test.go 3.3 KB

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