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

Method doOpenAIRequest

backend/go/cloud-proxy/provider_openai.go:182–197  ·  view source on GitHub ↗

doOpenAIRequest builds + sends the upstream request. Returns the raw response on success; caller handles status / body.

(ctx context.Context, cfg *proxyConfig, body []byte)

Source from the content-addressed store, hash-verified

180// doOpenAIRequest builds + sends the upstream request. Returns the
181// raw response on success; caller handles status / body.
182func (c *CloudProxy) doOpenAIRequest(ctx context.Context, cfg *proxyConfig, body []byte) (*http.Response, error) {
183 req, err := http.NewRequestWithContext(ctx, http.MethodPost, cfg.upstreamURL, bytes.NewReader(body))
184 if err != nil {
185 return nil, fmt.Errorf("cloud-proxy: build request: %w", err)
186 }
187 req.Header.Set("Content-Type", "application/json")
188 req.Header.Set("Accept", "*/*")
189 if cfg.apiKey != "" {
190 applyAuthHeader(req, cfg.provider, cfg.apiKey)
191 }
192 resp, err := c.client.Do(req)
193 if err != nil {
194 return nil, fmt.Errorf("cloud-proxy: upstream request: %w", err)
195 }
196 return resp, nil
197}
198
199// predictOpenAIRich is the non-streaming translate path. Returns a
200// fully-populated *pb.Reply with assistant content, tool calls, and

Callers 2

predictOpenAIRichMethod · 0.95

Calls 2

applyAuthHeaderFunction · 0.85
SetMethod · 0.65

Tested by

no test coverage detected