github.com/weaviate/weaviate@v1.24.6/modules/qna-openai/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-openai/ent" 23 ) 24 25 type Params struct{} 26 27 type qnaClient interface { 28 Answer(ctx context.Context, text, question string, cfg moduletools.ClassConfig) (*ent.AnswerResult, error) 29 } 30 31 type paramsHelper interface { 32 GetQuestion(params interface{}) string 33 GetProperties(params interface{}) []string 34 } 35 36 type AnswerProvider struct { 37 qna qnaClient 38 paramsHelper 39 } 40 41 func New(qna qnaClient, paramsHelper paramsHelper) *AnswerProvider { 42 return &AnswerProvider{qna, paramsHelper} 43 } 44 45 func (p *AnswerProvider) AdditionalPropertyDefaultValue() interface{} { 46 return &Params{} 47 } 48 49 func (p *AnswerProvider) ExtractAdditionalFn(param []*ast.Argument) interface{} { 50 return &Params{} 51 } 52 53 func (p *AnswerProvider) AdditionalFieldFn(classname string) *graphql.Field { 54 return p.additionalAnswerField(classname) 55 } 56 57 func (p *AnswerProvider) AdditionalPropertyFn(ctx context.Context, 58 in []search.Result, params interface{}, limit *int, 59 argumentModuleParams map[string]interface{}, cfg moduletools.ClassConfig, 60 ) ([]search.Result, error) { 61 if parameters, ok := params.(*Params); ok { 62 return p.findAnswer(ctx, in, parameters, limit, argumentModuleParams, cfg) 63 } 64 return nil, errors.New("wrong parameters") 65 }