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

Function RequestJSON

core/services/messaging/client.go:295–309  ·  view source on GitHub ↗

RequestJSON sends a JSON request-reply via NATS, marshaling the request and unmarshaling the reply. This eliminates the repeated marshal/request/unmarshal boilerplate across all NATS request-reply call sites.

(c MessagingClient, subject string, req Req, timeout time.Duration)

Source from the content-addressed store, hash-verified

293// unmarshaling the reply. This eliminates the repeated marshal/request/unmarshal
294// boilerplate across all NATS request-reply call sites.
295func RequestJSON[Req, Reply any](c MessagingClient, subject string, req Req, timeout time.Duration) (*Reply, error) {
296 data, err := json.Marshal(req)
297 if err != nil {
298 return nil, fmt.Errorf("marshaling request: %w", err)
299 }
300 replyData, err := c.Request(subject, data, timeout)
301 if err != nil {
302 return nil, fmt.Errorf("NATS request to %s: %w", subject, err)
303 }
304 var reply Reply
305 if err := json.Unmarshal(replyData, &reply); err != nil {
306 return nil, fmt.Errorf("unmarshaling reply from %s: %w", subject, err)
307 }
308 return &reply, nil
309}
310
311// Conn returns the underlying NATS connection for advanced usage.
312//

Callers 12

EnsureRemoteMethod · 0.92
fetchRemoteWithKeyMethod · 0.92
AllocRemoteTempMethod · 0.92
ListRemoteDirMethod · 0.92
StageRemoteToStoreMethod · 0.92
InstallBackendMethod · 0.92
UpgradeBackendMethod · 0.92
ListBackendsMethod · 0.92
DeleteBackendMethod · 0.92
UnloadModelOnNodeMethod · 0.92
DeleteModelFilesMethod · 0.92

Calls 1

RequestMethod · 0.65

Tested by

no test coverage detected