From 31d2aba9158e3d2866ef2c05ca75b509be9e04da Mon Sep 17 00:00:00 2001 From: matteo-grella Date: Wed, 8 Nov 2023 14:21:25 +1100 Subject: [PATCH] Rename `Answer` to `ExtractAnswer` --- examples/questionanswering/main.go | 2 +- pkg/client/client_questionanswering.go | 4 ++-- .../questionanswering/v1/questionanswering.proto | 2 +- .../questionanswering/v1/questionanswering.pb.go | 10 +++++----- .../v1/questionanswering.pb.gw.go | 6 +++--- .../v1/questionanswering_grpc.pb.go | 14 +++++++------- pkg/server/server_questionanswering.go | 6 +++--- .../questionanswering/bert/questionanswering.go | 4 ++-- pkg/tasks/questionanswering/questionanswering.go | 2 +- 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/examples/questionanswering/main.go b/examples/questionanswering/main.go index 6f86fbd..cf60399 100644 --- a/examples/questionanswering/main.go +++ b/examples/questionanswering/main.go @@ -37,7 +37,7 @@ func main() { fn := func(text string) error { start := time.Now() - result, err := m.Answer(context.Background(), text, content, opts) + result, err := m.ExtractAnswer(context.Background(), text, content, opts) if err != nil { return err } diff --git a/pkg/client/client_questionanswering.go b/pkg/client/client_questionanswering.go index ec58c2f..d75e449 100644 --- a/pkg/client/client_questionanswering.go +++ b/pkg/client/client_questionanswering.go @@ -32,8 +32,8 @@ func NewClientForQuestionAnswering(target string, opts Options) questionanswerin } } -// Answer answers the given question. -func (c *clientForQuestionAnswering) Answer(ctx context.Context, question, passage string, opts *questionanswering.Options) (questionanswering.Response, error) { +// ExtractAnswer answers the given question. +func (c *clientForQuestionAnswering) ExtractAnswer(ctx context.Context, question, passage string, opts *questionanswering.Options) (questionanswering.Response, error) { if opts == nil { opts = &questionanswering.Options{} } diff --git a/pkg/server/apis/questionanswering/v1/questionanswering.proto b/pkg/server/apis/questionanswering/v1/questionanswering.proto index 2c26de2..acc016c 100644 --- a/pkg/server/apis/questionanswering/v1/questionanswering.proto +++ b/pkg/server/apis/questionanswering/v1/questionanswering.proto @@ -7,7 +7,7 @@ import "google/api/annotations.proto"; option go_package = "github.com/nlpodyssey/cybertron/pkg/server/apis/questionanswering/v1;questionansweringv1"; service QuestionAnsweringService { - rpc Answer(AnswerRequest) returns (AnswerResponse) { + rpc ExtractAnswer(AnswerRequest) returns (AnswerResponse) { option (google.api.http) = { post: "/v1/answer" body: "*" diff --git a/pkg/server/gen/proto/go/questionanswering/v1/questionanswering.pb.go b/pkg/server/gen/proto/go/questionanswering/v1/questionanswering.pb.go index 06467a4..8b5abad 100644 --- a/pkg/server/gen/proto/go/questionanswering/v1/questionanswering.pb.go +++ b/pkg/server/gen/proto/go/questionanswering/v1/questionanswering.pb.go @@ -240,7 +240,7 @@ func (x *Answer) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use Answer.ProtoReflect.Descriptor instead. +// Deprecated: Use ExtractAnswer.ProtoReflect.Descriptor instead. func (*Answer) Descriptor() ([]byte, []int) { return file_questionanswering_v1_questionanswering_proto_rawDescGZIP(), []int{3} } @@ -353,13 +353,13 @@ var file_questionanswering_v1_questionanswering_proto_goTypes = []interface{}{ (*AnswerRequest)(nil), // 0: questionanswering.v1.AnswerRequest (*QuestionAnsweringOptions)(nil), // 1: questionanswering.v1.QuestionAnsweringOptions (*AnswerResponse)(nil), // 2: questionanswering.v1.AnswerResponse - (*Answer)(nil), // 3: questionanswering.v1.Answer + (*Answer)(nil), // 3: questionanswering.v1.ExtractAnswer } var file_questionanswering_v1_questionanswering_proto_depIdxs = []int32{ 1, // 0: questionanswering.v1.AnswerRequest.options:type_name -> questionanswering.v1.QuestionAnsweringOptions - 3, // 1: questionanswering.v1.AnswerResponse.answers:type_name -> questionanswering.v1.Answer - 0, // 2: questionanswering.v1.QuestionAnsweringService.Answer:input_type -> questionanswering.v1.AnswerRequest - 2, // 3: questionanswering.v1.QuestionAnsweringService.Answer:output_type -> questionanswering.v1.AnswerResponse + 3, // 1: questionanswering.v1.AnswerResponse.answers:type_name -> questionanswering.v1.ExtractAnswer + 0, // 2: questionanswering.v1.QuestionAnsweringService.ExtractAnswer:input_type -> questionanswering.v1.AnswerRequest + 2, // 3: questionanswering.v1.QuestionAnsweringService.ExtractAnswer:output_type -> questionanswering.v1.AnswerResponse 3, // [3:4] is the sub-list for method output_type 2, // [2:3] is the sub-list for method input_type 2, // [2:2] is the sub-list for extension type_name diff --git a/pkg/server/gen/proto/go/questionanswering/v1/questionanswering.pb.gw.go b/pkg/server/gen/proto/go/questionanswering/v1/questionanswering.pb.gw.go index 45ebcdf..bcf728c 100644 --- a/pkg/server/gen/proto/go/questionanswering/v1/questionanswering.pb.gw.go +++ b/pkg/server/gen/proto/go/questionanswering/v1/questionanswering.pb.gw.go @@ -60,7 +60,7 @@ func local_request_QuestionAnsweringService_Answer_0(ctx context.Context, marsha return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) } - msg, err := server.Answer(ctx, &protoReq) + msg, err := server.ExtractAnswer(ctx, &protoReq) return msg, metadata, err } @@ -79,7 +79,7 @@ func RegisterQuestionAnsweringServiceHandlerServer(ctx context.Context, mux *run inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) var err error var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/questionanswering.v1.QuestionAnsweringService/Answer", runtime.WithHTTPPathPattern("/v1/answer")) + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/questionanswering.v1.QuestionAnsweringService/ExtractAnswer", runtime.WithHTTPPathPattern("/v1/answer")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return @@ -143,7 +143,7 @@ func RegisterQuestionAnsweringServiceHandlerClient(ctx context.Context, mux *run inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) var err error var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/questionanswering.v1.QuestionAnsweringService/Answer", runtime.WithHTTPPathPattern("/v1/answer")) + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/questionanswering.v1.QuestionAnsweringService/ExtractAnswer", runtime.WithHTTPPathPattern("/v1/answer")) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return diff --git a/pkg/server/gen/proto/go/questionanswering/v1/questionanswering_grpc.pb.go b/pkg/server/gen/proto/go/questionanswering/v1/questionanswering_grpc.pb.go index 7229625..39d67c8 100644 --- a/pkg/server/gen/proto/go/questionanswering/v1/questionanswering_grpc.pb.go +++ b/pkg/server/gen/proto/go/questionanswering/v1/questionanswering_grpc.pb.go @@ -19,7 +19,7 @@ import ( const _ = grpc.SupportPackageIsVersion7 const ( - QuestionAnsweringService_Answer_FullMethodName = "/questionanswering.v1.QuestionAnsweringService/Answer" + QuestionAnsweringService_Answer_FullMethodName = "/questionanswering.v1.QuestionAnsweringService/ExtractAnswer" ) // QuestionAnsweringServiceClient is the client API for QuestionAnsweringService service. @@ -50,7 +50,7 @@ func (c *questionAnsweringServiceClient) Answer(ctx context.Context, in *AnswerR // All implementations must embed UnimplementedQuestionAnsweringServiceServer // for forward compatibility type QuestionAnsweringServiceServer interface { - Answer(context.Context, *AnswerRequest) (*AnswerResponse, error) + ExtractAnswer(context.Context, *AnswerRequest) (*AnswerResponse, error) mustEmbedUnimplementedQuestionAnsweringServiceServer() } @@ -58,8 +58,8 @@ type QuestionAnsweringServiceServer interface { type UnimplementedQuestionAnsweringServiceServer struct { } -func (UnimplementedQuestionAnsweringServiceServer) Answer(context.Context, *AnswerRequest) (*AnswerResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Answer not implemented") +func (UnimplementedQuestionAnsweringServiceServer) ExtractAnswer(context.Context, *AnswerRequest) (*AnswerResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ExtractAnswer not implemented") } func (UnimplementedQuestionAnsweringServiceServer) mustEmbedUnimplementedQuestionAnsweringServiceServer() { } @@ -81,14 +81,14 @@ func _QuestionAnsweringService_Answer_Handler(srv interface{}, ctx context.Conte return nil, err } if interceptor == nil { - return srv.(QuestionAnsweringServiceServer).Answer(ctx, in) + return srv.(QuestionAnsweringServiceServer).ExtractAnswer(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, FullMethod: QuestionAnsweringService_Answer_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QuestionAnsweringServiceServer).Answer(ctx, req.(*AnswerRequest)) + return srv.(QuestionAnsweringServiceServer).ExtractAnswer(ctx, req.(*AnswerRequest)) } return interceptor(ctx, in, info, handler) } @@ -101,7 +101,7 @@ var QuestionAnsweringService_ServiceDesc = grpc.ServiceDesc{ HandlerType: (*QuestionAnsweringServiceServer)(nil), Methods: []grpc.MethodDesc{ { - MethodName: "Answer", + MethodName: "ExtractAnswer", Handler: _QuestionAnsweringService_Answer_Handler, }, }, diff --git a/pkg/server/server_questionanswering.go b/pkg/server/server_questionanswering.go index 9722bd3..627e6a1 100644 --- a/pkg/server/server_questionanswering.go +++ b/pkg/server/server_questionanswering.go @@ -32,8 +32,8 @@ func (s *serverForQuestionAnswering) RegisterHandlerServer(ctx context.Context, return questionansweringv1.RegisterQuestionAnsweringServiceHandlerServer(ctx, mux, s) } -// Answer handles the Answer request. -func (s *serverForQuestionAnswering) Answer(ctx context.Context, req *questionansweringv1.AnswerRequest) (*questionansweringv1.AnswerResponse, error) { +// ExtractAnswer handles the Answer request. +func (s *serverForQuestionAnswering) ExtractAnswer(ctx context.Context, req *questionansweringv1.AnswerRequest) (*questionansweringv1.AnswerResponse, error) { params := req.GetOptions() opts := &questionanswering.Options{ MaxAnswers: int(params.GetMaxAnswers()), @@ -42,7 +42,7 @@ func (s *serverForQuestionAnswering) Answer(ctx context.Context, req *questionan MaxCandidates: int(params.GetMaxCandidates()), } - result, err := s.engine.Answer(ctx, req.GetQuestion(), req.GetPassage(), opts) + result, err := s.engine.ExtractAnswer(ctx, req.GetQuestion(), req.GetPassage(), opts) if err != nil { return nil, err } diff --git a/pkg/tasks/questionanswering/bert/questionanswering.go b/pkg/tasks/questionanswering/bert/questionanswering.go index 14a5237..6434d92 100644 --- a/pkg/tasks/questionanswering/bert/questionanswering.go +++ b/pkg/tasks/questionanswering/bert/questionanswering.go @@ -57,9 +57,9 @@ func LoadQuestionAnswering(modelPath string) (*QuestionAnswering, error) { }, nil } -// Answer returns the answers for the given question and passage. +// ExtractAnswer returns the answers for the given question and passage. // The options may assume default values if those are not set. -func (qa *QuestionAnswering) Answer(_ context.Context, question string, passage string, opts *questionanswering.Options) (questionanswering.Response, error) { +func (qa *QuestionAnswering) ExtractAnswer(_ context.Context, question string, passage string, opts *questionanswering.Options) (questionanswering.Response, error) { checkOptions(opts) qt, pt := qa.tokenize(question, passage) diff --git a/pkg/tasks/questionanswering/questionanswering.go b/pkg/tasks/questionanswering/questionanswering.go index 1cfcfea..214b829 100644 --- a/pkg/tasks/questionanswering/questionanswering.go +++ b/pkg/tasks/questionanswering/questionanswering.go @@ -25,7 +25,7 @@ var ErrInputSequenceTooLong = errors.New("input sequence too long") // Interface defines the main functions for question-answering task. type Interface interface { - Answer(ctx context.Context, question string, passage string, opts *Options) (Response, error) + ExtractAnswer(ctx context.Context, question string, passage string, opts *Options) (Response, error) } // Options defines the options for question-answering task.