-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
111 lines (94 loc) · 2.84 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"context"
"net/http"
"net/url"
"os"
"os/signal"
"syscall"
"time"
"github.com/fatih/color"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/ollama/ollama/api"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
_ "github.com/joho/godotenv/autoload"
)
const (
minioApi = "minio-api.connorskees.com"
minioBucket = "youtube"
)
type Model struct {
Name string
ParamCount string
Storage string
}
var (
ollamaApi, _ = url.Parse("https://ollama-api.connorskees.com")
models = []*Model{
{Name: "codellama:7b", ParamCount: "7B", Storage: "3.8GB"},
{Name: "llama2-uncensored:7b", ParamCount: "7B", Storage: "3.8GB"},
{Name: "llama3:latest", ParamCount: "8B", Storage: "4.7GB"},
{Name: "tinyllama:latest", ParamCount: "1.1B", Storage: "640MB"},
}
questions = []string{
"What is the capital of France?",
"Who is the CEO of Apple?",
"What is the meaning of life?",
"What is the best way to get to work?",
"How do I make a cup of coffee?",
"What is the capital of Australia?",
"Can you tell me about a famous painting by Leonardo da Vinci?",
"Who is the CEO of Tesla?",
"Can you give me a recipe for a delicious vegetarian dish?",
"What is the capital of Canada?",
"How do I properly format my phone number for international calls?",
"What is the best way to stay healthy during the pandemic?",
}
)
func init() {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.Kitchen})
}
func main() {
// Initialize minio client object.
minioClient, err := minio.New(minioApi, &minio.Options{
Creds: credentials.NewStaticV4(
os.Getenv("MINIO_KEY_ID"), os.Getenv("MINIO_SECRET_KEY"), "",
),
Secure: true,
})
must(err)
var (
ollama = api.NewClient(ollamaApi, http.DefaultClient)
c = New(ollama)
runs = make(Runs, len(models))
done, shutdown = make(chan interface{}), make(chan os.Signal, 1)
)
log.Info().Timestamp().Msg("Start")
signal.Notify(shutdown, os.Interrupt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT)
go func() {
<-shutdown
log.Info().Timestamp().Msg("End")
var filename = "run" + time.Now().Format(time.RFC3339) + ".csv"
_, err = minioClient.PutObject(context.Background(), minioBucket, filename, runs.ToCSV(), -1, minio.PutObjectOptions{})
must(err)
log.Info().Str("filename", filename).Msg("Uploaded to Minio")
done <- nil
}()
color.New(color.BgBlack).Add(color.FgWhite).Println("--- Round 1 ---")
for i, model := range models {
run := c.TestModel(model)
run.PrintResult()
runs[i] = run
}
color.New(color.BgBlack).Add(color.FgWhite).Println("--- Round 2 ---")
for i, model := range models {
run := c.TestModel(model)
run.PrintResult()
// Average the two runs together
runs[i].JoinAndAverage(run)
}
shutdown <- nil
<-done
}