diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d1111bc --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +GPT-backend \ No newline at end of file diff --git a/main.go b/main.go index 556ebef..4636c91 100644 --- a/main.go +++ b/main.go @@ -1,22 +1,67 @@ package main import ( + "encoding/json" "fmt" + "io" + "net/http" "os" "github.com/gin-gonic/gin" ) -func main() { - args := os.Args[1:] - if len(args) == 0 { - return +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 string `json:"size"` + Details Details `json:"details"` +} + +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) } - fmt.Printf(args[0]) + + defer resp.Body.Close() + + body, err := io.ReadAll(resp.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("/", func(c *gin.Context) { - c.JSON(200, "hello") + r.GET("/api/tags", func(c *gin.Context) { + c.JSON(200, models) }) r.Run(":4000")