+log
This commit is contained in:
parent
2b7d77ac25
commit
4814e89145
3 changed files with 21 additions and 18 deletions
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
|
@ -32,20 +33,20 @@ func (c *Containers) Adds(ctrs Containers) {
|
||||||
c.Containers = append(c.Containers, ctrs.Containers...)
|
c.Containers = append(c.Containers, ctrs.Containers...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func get_ollama_containers(host Host, all bool) Containers {
|
func get_containers_list(host Host, all bool) Containers {
|
||||||
|
|
||||||
ctr_list := Containers{}
|
ctr_list := Containers{}
|
||||||
|
|
||||||
cli, err := client.NewClientWithOpts(client.WithHost(fmt.Sprintf("tcp://%s:%s", host.IP, host.Port)))
|
cli, err := client.NewClientWithOpts(client.WithHost(fmt.Sprintf("tcp://%s:%s", host.IP, host.Port)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
log.Println(err)
|
||||||
return ctr_list
|
return ctr_list
|
||||||
}
|
}
|
||||||
defer cli.Close()
|
defer cli.Close()
|
||||||
|
|
||||||
containers, err := cli.ContainerList(context.Background(), container.ListOptions{All: all})
|
containers, err := cli.ContainerList(context.Background(), container.ListOptions{All: all})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
log.Println(err)
|
||||||
return ctr_list
|
return ctr_list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
host.go
13
host.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -72,13 +73,13 @@ type Details struct {
|
||||||
Quantization_level string `json:"quantization_level"`
|
Quantization_level string `json:"quantization_level"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func get_ollama_tags(hosts Hosts) (Models, error) {
|
func get_models_list(hosts Hosts) (Models, error) {
|
||||||
|
|
||||||
var ctr Containers
|
var ctr Containers
|
||||||
|
|
||||||
for _, host := range hosts.Hosts {
|
for _, host := range hosts.Hosts {
|
||||||
fmt.Printf("get ollama containers: %s -> %s\n", host.IP, host.Port)
|
log.Printf("get llm server containers: %s -> %s\n", host.IP, host.Port)
|
||||||
ctr.Adds(get_ollama_containers(host, false))
|
ctr.Adds(get_containers_list(host, false))
|
||||||
}
|
}
|
||||||
|
|
||||||
retval := []Model{}
|
retval := []Model{}
|
||||||
|
@ -112,7 +113,7 @@ func get_ollama_tags(hosts Hosts) (Models, error) {
|
||||||
mods.Models[n].State = "running"
|
mods.Models[n].State = "running"
|
||||||
mods.Models[n].Container = engine.Name
|
mods.Models[n].Container = engine.Name
|
||||||
mods.Models[n].Engine = "ollama"
|
mods.Models[n].Engine = "ollama"
|
||||||
fmt.Printf("mod: %s - %s:%d\n", mods.Models[n].Name, mods.Models[n].Ip, mods.Models[n].Port)
|
log.Printf("mod: %s - %s:%d\n", mods.Models[n].Name, mods.Models[n].Ip, mods.Models[n].Port)
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = append(retval, mods.Models...)
|
retval = append(retval, mods.Models...)
|
||||||
|
@ -149,7 +150,7 @@ func get_ollama_tags(hosts Hosts) (Models, error) {
|
||||||
mods.Models[n].State = "running"
|
mods.Models[n].State = "running"
|
||||||
mods.Models[n].Container = engine.Name
|
mods.Models[n].Container = engine.Name
|
||||||
mods.Models[n].Engine = "vllm"
|
mods.Models[n].Engine = "vllm"
|
||||||
fmt.Printf("mod: %s - %s:%d\n", mods.Models[n].Name, mods.Models[n].Ip, mods.Models[n].Port)
|
log.Printf("mod: %s - %s:%d\n", mods.Models[n].Name, mods.Models[n].Ip, mods.Models[n].Port)
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = append(retval, mods.Models...)
|
retval = append(retval, mods.Models...)
|
||||||
|
@ -168,7 +169,7 @@ func (h *Hosts) Add(s string) {
|
||||||
func (h *Hosts) Init(server string) error {
|
func (h *Hosts) Init(server string) error {
|
||||||
|
|
||||||
if debug {
|
if debug {
|
||||||
fmt.Printf("server: %s\n", server)
|
log.Printf("server: %s\n", server)
|
||||||
}
|
}
|
||||||
|
|
||||||
servers := strings.Split(server, ",")
|
servers := strings.Split(server, ",")
|
||||||
|
|
19
main.go
19
main.go
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -41,7 +40,7 @@ func read_config() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
if debug {
|
if debug {
|
||||||
fmt.Printf("config: '%s'\n", server_list)
|
log.Printf("config: '%s'\n", server_list)
|
||||||
}
|
}
|
||||||
|
|
||||||
return server_list
|
return server_list
|
||||||
|
@ -51,16 +50,18 @@ func main() {
|
||||||
|
|
||||||
var server_list string
|
var server_list string
|
||||||
|
|
||||||
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||||
|
|
||||||
flag.Usage = usage
|
flag.Usage = usage
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if version {
|
if version {
|
||||||
fmt.Printf("%s: %s\n", os.Args[0], _Version)
|
log.Printf("%s: %s\n", os.Args[0], _Version)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
if servers == "" && config == "" {
|
if servers == "" && config == "" {
|
||||||
fmt.Println("no servers specified")
|
log.Println("no servers specified")
|
||||||
usage()
|
usage()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,15 +75,15 @@ func main() {
|
||||||
error := hosts.Init(server_list)
|
error := hosts.Init(server_list)
|
||||||
|
|
||||||
if error != nil {
|
if error != nil {
|
||||||
panic(error)
|
log.Fatalln(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
r.Use(cors.Default())
|
r.Use(cors.Default())
|
||||||
r.GET("/api/tags", func(c *gin.Context) {
|
r.GET("/api/tags", func(c *gin.Context) {
|
||||||
models, err := get_ollama_tags(hosts)
|
models, err := get_models_list(hosts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
c.JSON(200, models)
|
c.JSON(200, models)
|
||||||
})
|
})
|
||||||
|
@ -98,8 +99,8 @@ func main() {
|
||||||
|
|
||||||
r.ForwardedByClientIP = true
|
r.ForwardedByClientIP = true
|
||||||
|
|
||||||
fmt.Println("Starting server on port " + port)
|
log.Println("Starting server on port " + port)
|
||||||
r.Run(":" + port)
|
r.Run(":" + port)
|
||||||
|
|
||||||
fmt.Print("END")
|
log.Print("END")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue