MCPcopy
hub / github.com/mudler/LocalAI / postModelApplyRequest

Function postModelApplyRequest

core/http/app_test.go:95–138  ·  view source on GitHub ↗
(url string, request modelApplyRequest)

Source from the content-addressed store, hash-verified

93}
94
95func postModelApplyRequest(url string, request modelApplyRequest) (response map[string]any) {
96
97 //url := "http://localhost:AI/models/apply"
98
99 // Create the request payload
100
101 payload, err := json.Marshal(request)
102 if err != nil {
103 fmt.Println("Error marshaling JSON:", err)
104 return
105 }
106
107 // Create the HTTP request
108 req, err := http.NewRequest("POST", url, bytes.NewBuffer(payload))
109 if err != nil {
110 fmt.Println("Error creating request:", err)
111 return
112 }
113 req.Header.Set("Content-Type", "application/json")
114 req.Header.Set("Authorization", bearerKey)
115
116 // Make the request
117 client := &http.Client{}
118 resp, err := client.Do(req)
119 if err != nil {
120 fmt.Println("Error making request:", err)
121 return
122 }
123 defer resp.Body.Close()
124
125 body, err := io.ReadAll(resp.Body)
126 if err != nil {
127 fmt.Println("Error reading response body:", err)
128 return
129 }
130
131 // Unmarshal the response into a map[string]interface{}
132 err = json.Unmarshal(body, &response)
133 if err != nil {
134 fmt.Println("Error unmarshaling JSON response:", err)
135 return
136 }
137 return
138}
139
140func postRequestJSON[B any](url string, bodyJson *B) error {
141 payload, err := json.Marshal(bodyJson)

Callers 1

app_test.goFile · 0.85

Calls 2

SetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected