123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- package cmd
- import (
- "bytes"
- "os"
- "path/filepath"
- "testing"
- "github.com/google/go-cmp/cmp"
- "github.com/ollama/ollama/api"
- )
- func TestShowInfo(t *testing.T) {
- t.Run("bare details", func(t *testing.T) {
- var b bytes.Buffer
- if err := showInfo(&api.ShowResponse{
- Details: api.ModelDetails{
- Family: "test",
- ParameterSize: "7B",
- QuantizationLevel: "FP16",
- },
- }, &b); err != nil {
- t.Fatal(err)
- }
- expect := ` Model
- architecture test
- parameters 7B
- quantization FP16
- `
- if diff := cmp.Diff(expect, b.String()); diff != "" {
- t.Errorf("unexpected output (-want +got):\n%s", diff)
- }
- })
- t.Run("bare model info", func(t *testing.T) {
- var b bytes.Buffer
- if err := showInfo(&api.ShowResponse{
- ModelInfo: map[string]any{
- "general.architecture": "test",
- "general.parameter_count": float64(7_000_000_000),
- "test.context_length": float64(0),
- "test.embedding_length": float64(0),
- },
- Details: api.ModelDetails{
- Family: "test",
- ParameterSize: "7B",
- QuantizationLevel: "FP16",
- },
- }, &b); err != nil {
- t.Fatal(err)
- }
- expect := ` Model
- architecture test
- parameters 7B
- context length 0
- embedding length 0
- quantization FP16
- `
- if diff := cmp.Diff(expect, b.String()); diff != "" {
- t.Errorf("unexpected output (-want +got):\n%s", diff)
- }
- })
- t.Run("parameters", func(t *testing.T) {
- var b bytes.Buffer
- if err := showInfo(&api.ShowResponse{
- Details: api.ModelDetails{
- Family: "test",
- ParameterSize: "7B",
- QuantizationLevel: "FP16",
- },
- Parameters: `
- stop never
- stop gonna
- stop give
- stop you
- stop up
- temperature 99`,
- }, &b); err != nil {
- t.Fatal(err)
- }
- expect := ` Model
- architecture test
- parameters 7B
- quantization FP16
- Parameters
- stop never
- stop gonna
- stop give
- stop you
- stop up
- temperature 99
- `
- if diff := cmp.Diff(expect, b.String()); diff != "" {
- t.Errorf("unexpected output (-want +got):\n%s", diff)
- }
- })
- t.Run("project info", func(t *testing.T) {
- var b bytes.Buffer
- if err := showInfo(&api.ShowResponse{
- Details: api.ModelDetails{
- Family: "test",
- ParameterSize: "7B",
- QuantizationLevel: "FP16",
- },
- ProjectorInfo: map[string]any{
- "general.architecture": "clip",
- "general.parameter_count": float64(133_700_000),
- "clip.vision.embedding_length": float64(0),
- "clip.vision.projection_dim": float64(0),
- },
- }, &b); err != nil {
- t.Fatal(err)
- }
- expect := ` Model
- architecture test
- parameters 7B
- quantization FP16
- Projector
- architecture clip
- parameters 133.70M
- embedding length 0
- dimensions 0
- `
- if diff := cmp.Diff(expect, b.String()); diff != "" {
- t.Errorf("unexpected output (-want +got):\n%s", diff)
- }
- })
- t.Run("system", func(t *testing.T) {
- var b bytes.Buffer
- if err := showInfo(&api.ShowResponse{
- Details: api.ModelDetails{
- Family: "test",
- ParameterSize: "7B",
- QuantizationLevel: "FP16",
- },
- System: `You are a pirate!
- Ahoy, matey!
- Weigh anchor!
- `,
- }, &b); err != nil {
- t.Fatal(err)
- }
- expect := ` Model
- architecture test
- parameters 7B
- quantization FP16
- System
- You are a pirate!
- Ahoy, matey!
- `
- if diff := cmp.Diff(expect, b.String()); diff != "" {
- t.Errorf("unexpected output (-want +got):\n%s", diff)
- }
- })
- t.Run("license", func(t *testing.T) {
- var b bytes.Buffer
- license, err := os.ReadFile(filepath.Join("..", "LICENSE"))
- if err != nil {
- t.Fatal(err)
- }
- if err := showInfo(&api.ShowResponse{
- Details: api.ModelDetails{
- Family: "test",
- ParameterSize: "7B",
- QuantizationLevel: "FP16",
- },
- License: string(license),
- }, &b); err != nil {
- t.Fatal(err)
- }
- expect := ` Model
- architecture test
- parameters 7B
- quantization FP16
- License
- MIT License
- Copyright (c) Ollama
- `
- if diff := cmp.Diff(expect, b.String()); diff != "" {
- t.Errorf("unexpected output (-want +got):\n%s", diff)
- }
- })
- }
|