72 lines
1.3 KiB
Go
72 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Details struct {
|
|
Parent_model string `json:"parent_model"`
|
|
Format string `json:"format"`
|
|
Family string `json:"family"`
|
|
Families []string `json:"families"`
|
|
Parameter_size string `json:"parameter_size"`
|
|
Quantization_level string `json:"quantization_level"`
|
|
}
|
|
|
|
type Model struct {
|
|
Name string `json:"name"`
|
|
Model string `json:"model"`
|
|
Modified_at string `json:"modified_at"`
|
|
Size int `json:"size"`
|
|
Details Details `json:"details"`
|
|
Ip string `json:"ip"`
|
|
Port string `json:"port"`
|
|
}
|
|
|
|
type Models struct {
|
|
Models []Model `json:"models"`
|
|
}
|
|
|
|
func get_ollama_tags() Models {
|
|
resp, err := http.Get("http://192.168.1.30:11434/api/tags")
|
|
|
|
if err != nil {
|
|
fmt.Print(err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
body, err := io.ReadAll(resp.Body)
|
|
|
|
print(string(body))
|
|
|
|
if err != nil {
|
|
fmt.Print(err.Error())
|
|
os.Exit(1)
|
|
}
|
|
|
|
retval := Models{}
|
|
json.Unmarshal(body, &retval)
|
|
|
|
return retval
|
|
}
|
|
|
|
func main() {
|
|
// get_ollama_tags()
|
|
models := get_ollama_tags()
|
|
fmt.Print(models)
|
|
|
|
r := gin.Default()
|
|
r.GET("/api/tags", func(c *gin.Context) {
|
|
c.JSON(200, models)
|
|
})
|
|
|
|
r.Run(":4000")
|
|
}
|