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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
type Details struct {
|
||||||
args := os.Args[1:]
|
Parent_model string `json:"parent_model"`
|
||||||
if len(args) == 0 {
|
Format string `json:"format"`
|
||||||
return
|
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 := gin.Default()
|
||||||
r.GET("/", func(c *gin.Context) {
|
r.GET("/api/tags", func(c *gin.Context) {
|
||||||
c.JSON(200, "hello")
|
c.JSON(200, models)
|
||||||
})
|
})
|
||||||
|
|
||||||
r.Run(":4000")
|
r.Run(":4000")
|
||||||
|
|
Loading…
Add table
Reference in a new issue