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
|
package internal
import (
"context"
"flag"
"os"
"os/signal"
"syscall"
"within.website/x/internal"
"within.website/x/web/ollama"
)
var (
dataDir = flag.String("data-dir", "./var", "data directory for the bot")
ollamaModel = flag.String("ollama-model", "llama3.1", "ollama model tag")
ollamaHost = flag.String("ollama-host", "http://xe-inference.flycast:80", "ollama host")
)
func DataDir() string {
os.MkdirAll(*dataDir, 0755)
return *dataDir
}
func OllamaHost() string {
return *ollamaHost
}
func OllamaClient() *ollama.Client {
return ollama.NewClient(*ollamaHost)
}
func OllamaModel() string {
return *ollamaModel
}
func HandleStartup() (context.Context, context.CancelFunc) {
internal.HandleStartup()
ctx, cancel := context.WithCancel(context.Background())
go func() {
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sc
cancel()
}()
os.Setenv("OLLAMA_HOST", *ollamaHost)
return ctx, cancel
}
|