github.com/weaviate/weaviate@v1.24.6/modules/qna-transformers/additional/answer/answer.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package answer
    13  
    14  import (
    15  	"context"
    16  	"errors"
    17  
    18  	"github.com/tailor-inc/graphql"
    19  	"github.com/tailor-inc/graphql/language/ast"
    20  	"github.com/weaviate/weaviate/entities/moduletools"
    21  	"github.com/weaviate/weaviate/entities/search"
    22  	"github.com/weaviate/weaviate/modules/qna-transformers/ent"
    23  )
    24  
    25  type Params struct{}
    26  
    27  type qnaClient interface {
    28  	Answer(ctx context.Context,
    29  		text, question string) (*ent.AnswerResult, error)
    30  }
    31  
    32  type paramsHelper interface {
    33  	GetQuestion(params interface{}) string
    34  	GetProperties(params interface{}) []string
    35  	GetCertainty(params interface{}) float64
    36  	GetDistance(params interface{}) float64
    37  	GetRerank(params interface{}) bool
    38  }
    39  
    40  type AnswerProvider struct {
    41  	qna qnaClient
    42  	paramsHelper
    43  }
    44  
    45  func New(qna qnaClient, paramsHelper paramsHelper) *AnswerProvider {
    46  	return &AnswerProvider{qna, paramsHelper}
    47  }
    48  
    49  func (p *AnswerProvider) AdditionalPropertyDefaultValue() interface{} {
    50  	return &Params{}
    51  }
    52  
    53  func (p *AnswerProvider) ExtractAdditionalFn(param []*ast.Argument) interface{} {
    54  	return &Params{}
    55  }
    56  
    57  func (p *AnswerProvider) AdditionalFieldFn(classname string) *graphql.Field {
    58  	return p.additionalAnswerField(classname)
    59  }
    60  
    61  func (p *AnswerProvider) AdditionalPropertyFn(ctx context.Context,
    62  	in []search.Result, params interface{}, limit *int,
    63  	argumentModuleParams map[string]interface{}, cfg moduletools.ClassConfig,
    64  ) ([]search.Result, error) {
    65  	if parameters, ok := params.(*Params); ok {
    66  		return p.findAnswer(ctx, in, parameters, limit, argumentModuleParams)
    67  	}
    68  	return nil, errors.New("wrong parameters")
    69  }