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

Method doAnthropicRequest

backend/go/cloud-proxy/provider_anthropic.go:340–355  ·  view source on GitHub ↗

doAnthropicRequest is the Anthropic counterpart of doOpenAIRequest. applyAuthHeader sets x-api-key and anthropic-version when provider is anthropic, so this method doesn't need to duplicate that.

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

Source from the content-addressed store, hash-verified

338// applyAuthHeader sets x-api-key and anthropic-version when provider
339// is anthropic, so this method doesn't need to duplicate that.
340func (c *CloudProxy) doAnthropicRequest(ctx context.Context, cfg *proxyConfig, body []byte) (*http.Response, error) {
341 req, err := http.NewRequestWithContext(ctx, http.MethodPost, cfg.upstreamURL, bytes.NewReader(body))
342 if err != nil {
343 return nil, fmt.Errorf("cloud-proxy: build request: %w", err)
344 }
345 req.Header.Set("Content-Type", "application/json")
346 req.Header.Set("Accept", "*/*")
347 if cfg.apiKey != "" {
348 applyAuthHeader(req, cfg.provider, cfg.apiKey)
349 }
350 resp, err := c.client.Do(req)
351 if err != nil {
352 return nil, fmt.Errorf("cloud-proxy: upstream request: %w", err)
353 }
354 return resp, nil
355}
356
357// predictAnthropicRich returns the full Reply: joined text from all
358// text blocks, tool_use blocks mapped to ToolCallDelta, and usage

Callers 2

predictAnthropicRichMethod · 0.95

Calls 2

applyAuthHeaderFunction · 0.85
SetMethod · 0.65

Tested by

no test coverage detected