MCPcopy Create free account
hub / github.com/InferCore/InferCore / Health

Method Health

internal/adapters/gemini/gemini.go:344–374  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

342}
343
344func (a *Adapter) Health(ctx context.Context) error {
345 path := strings.TrimSpace(a.cfg.HealthPath)
346 if path == "" {
347 if a.vertex {
348 proj := strings.TrimSpace(a.cfg.VertexProject)
349 loc := strings.TrimSpace(a.cfg.VertexLocation)
350 path = fmt.Sprintf("/v1/projects/%s/locations/%s", proj, loc)
351 } else {
352 path = "/v1beta/models"
353 }
354 }
355 if !strings.HasPrefix(path, "/") {
356 path = "/" + path
357 }
358 url := a.baseURL + path
359 httpReq, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
360 if err != nil {
361 return err
362 }
363 a.applyAPIKey(httpReq)
364 a.applyExtraHeaders(httpReq)
365 resp, err := a.httpClient.Do(httpReq)
366 if err != nil {
367 return upstream.New(upstream.KindBackendUnhealthy, err.Error())
368 }
369 defer resp.Body.Close()
370 if resp.StatusCode < 200 || resp.StatusCode >= 300 {
371 return upstream.New(upstream.KindBackendUnhealthy, fmt.Sprintf("gemini health failed status=%d path=%s", resp.StatusCode, path))
372 }
373 return nil
374}
375
376func (a *Adapter) applyAPIKey(req *http.Request) {
377 if k := a.apiKey(); k != "" {

Callers

nothing calls this directly

Calls 5

applyAPIKeyMethod · 0.95
applyExtraHeadersMethod · 0.95
NewFunction · 0.92
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected