api/tags
This commit is contained in:
parent
7003ff7ae6
commit
00f93cfb5a
2 changed files with 53 additions and 7 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
GPT-backend
|
59
main.go
59
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")
|
||||
|
|
Loading…
Add table
Reference in a new issue