|
- package location
-
- import (
- "context"
- "crypto/tls"
- "net/http"
-
- "github.com/AFASystems/presence/internal/pkg/apiclient"
- "github.com/AFASystems/presence/internal/pkg/config"
- "github.com/AFASystems/presence/internal/pkg/model"
- )
-
- // Inferencer returns inferred positions (e.g. from an AI/ML service).
- type Inferencer interface {
- Infer(ctx context.Context, cfg *config.Config) (model.PositionResponse, error)
- }
-
- // DefaultInferencer uses apiclient to get token and call the inference API.
- type DefaultInferencer struct {
- Client *http.Client
- }
-
- // NewDefaultInferencer creates an inferencer with optional TLS skip verify (e.g. from config.TLSInsecureSkipVerify).
- func NewDefaultInferencer(skipTLSVerify bool) *DefaultInferencer {
- tr := &http.Transport{}
- if skipTLSVerify {
- tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
- }
- return &DefaultInferencer{
- Client: &http.Client{Transport: tr},
- }
- }
-
- // Infer gets a token and calls the inference API.
- func (d *DefaultInferencer) Infer(ctx context.Context, cfg *config.Config) (model.PositionResponse, error) {
- token, err := apiclient.GetToken(ctx, cfg, d.Client)
- if err != nil {
- return model.PositionResponse{}, err
- }
- return apiclient.InferPosition(token, d.Client, cfg)
- }
|