cmd_test.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. package cmd
  2. import (
  3. "bytes"
  4. "os"
  5. "path/filepath"
  6. "testing"
  7. "github.com/google/go-cmp/cmp"
  8. "github.com/ollama/ollama/api"
  9. )
  10. func TestShowInfo(t *testing.T) {
  11. t.Run("bare details", func(t *testing.T) {
  12. var b bytes.Buffer
  13. if err := showInfo(&api.ShowResponse{
  14. Details: api.ModelDetails{
  15. Family: "test",
  16. ParameterSize: "7B",
  17. QuantizationLevel: "FP16",
  18. },
  19. }, &b); err != nil {
  20. t.Fatal(err)
  21. }
  22. expect := ` Model
  23. architecture test
  24. parameters 7B
  25. quantization FP16
  26. `
  27. if diff := cmp.Diff(expect, b.String()); diff != "" {
  28. t.Errorf("unexpected output (-want +got):\n%s", diff)
  29. }
  30. })
  31. t.Run("bare model info", func(t *testing.T) {
  32. var b bytes.Buffer
  33. if err := showInfo(&api.ShowResponse{
  34. ModelInfo: map[string]any{
  35. "general.architecture": "test",
  36. "general.parameter_count": float64(7_000_000_000),
  37. "test.context_length": float64(0),
  38. "test.embedding_length": float64(0),
  39. },
  40. Details: api.ModelDetails{
  41. Family: "test",
  42. ParameterSize: "7B",
  43. QuantizationLevel: "FP16",
  44. },
  45. }, &b); err != nil {
  46. t.Fatal(err)
  47. }
  48. expect := ` Model
  49. architecture test
  50. parameters 7B
  51. context length 0
  52. embedding length 0
  53. quantization FP16
  54. `
  55. if diff := cmp.Diff(expect, b.String()); diff != "" {
  56. t.Errorf("unexpected output (-want +got):\n%s", diff)
  57. }
  58. })
  59. t.Run("parameters", func(t *testing.T) {
  60. var b bytes.Buffer
  61. if err := showInfo(&api.ShowResponse{
  62. Details: api.ModelDetails{
  63. Family: "test",
  64. ParameterSize: "7B",
  65. QuantizationLevel: "FP16",
  66. },
  67. Parameters: `
  68. stop never
  69. stop gonna
  70. stop give
  71. stop you
  72. stop up
  73. temperature 99`,
  74. }, &b); err != nil {
  75. t.Fatal(err)
  76. }
  77. expect := ` Model
  78. architecture test
  79. parameters 7B
  80. quantization FP16
  81. Parameters
  82. stop never
  83. stop gonna
  84. stop give
  85. stop you
  86. stop up
  87. temperature 99
  88. `
  89. if diff := cmp.Diff(expect, b.String()); diff != "" {
  90. t.Errorf("unexpected output (-want +got):\n%s", diff)
  91. }
  92. })
  93. t.Run("project info", func(t *testing.T) {
  94. var b bytes.Buffer
  95. if err := showInfo(&api.ShowResponse{
  96. Details: api.ModelDetails{
  97. Family: "test",
  98. ParameterSize: "7B",
  99. QuantizationLevel: "FP16",
  100. },
  101. ProjectorInfo: map[string]any{
  102. "general.architecture": "clip",
  103. "general.parameter_count": float64(133_700_000),
  104. "clip.vision.embedding_length": float64(0),
  105. "clip.vision.projection_dim": float64(0),
  106. },
  107. }, &b); err != nil {
  108. t.Fatal(err)
  109. }
  110. expect := ` Model
  111. architecture test
  112. parameters 7B
  113. quantization FP16
  114. Projector
  115. architecture clip
  116. parameters 133.70M
  117. embedding length 0
  118. dimensions 0
  119. `
  120. if diff := cmp.Diff(expect, b.String()); diff != "" {
  121. t.Errorf("unexpected output (-want +got):\n%s", diff)
  122. }
  123. })
  124. t.Run("system", func(t *testing.T) {
  125. var b bytes.Buffer
  126. if err := showInfo(&api.ShowResponse{
  127. Details: api.ModelDetails{
  128. Family: "test",
  129. ParameterSize: "7B",
  130. QuantizationLevel: "FP16",
  131. },
  132. System: `You are a pirate!
  133. Ahoy, matey!
  134. Weigh anchor!
  135. `,
  136. }, &b); err != nil {
  137. t.Fatal(err)
  138. }
  139. expect := ` Model
  140. architecture test
  141. parameters 7B
  142. quantization FP16
  143. System
  144. You are a pirate!
  145. Ahoy, matey!
  146. `
  147. if diff := cmp.Diff(expect, b.String()); diff != "" {
  148. t.Errorf("unexpected output (-want +got):\n%s", diff)
  149. }
  150. })
  151. t.Run("license", func(t *testing.T) {
  152. var b bytes.Buffer
  153. license, err := os.ReadFile(filepath.Join("..", "LICENSE"))
  154. if err != nil {
  155. t.Fatal(err)
  156. }
  157. if err := showInfo(&api.ShowResponse{
  158. Details: api.ModelDetails{
  159. Family: "test",
  160. ParameterSize: "7B",
  161. QuantizationLevel: "FP16",
  162. },
  163. License: string(license),
  164. }, &b); err != nil {
  165. t.Fatal(err)
  166. }
  167. expect := ` Model
  168. architecture test
  169. parameters 7B
  170. quantization FP16
  171. License
  172. MIT License
  173. Copyright (c) Ollama
  174. `
  175. if diff := cmp.Diff(expect, b.String()); diff != "" {
  176. t.Errorf("unexpected output (-want +got):\n%s", diff)
  177. }
  178. })
  179. }