Skip to content

Commit

Permalink
Fix question answering
Browse files Browse the repository at this point in the history
  • Loading branch information
hupe1980 committed Jun 26, 2023
1 parent e68b990 commit c8796d8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion _examples/question_answering/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ func main() {
log.Fatal(err)
}

fmt.Println(res[0].Answer)
fmt.Println("Answer:", res.Answer)
fmt.Println("Score:", res.Score)
fmt.Println("Start:", res.Start)
fmt.Println("End:", res.End)
}
4 changes: 2 additions & 2 deletions huggingface.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (ic *InferenceClient) ZeroShotClassification(ctx context.Context, req *Zero
// QuestionAnswering performs question answering using the specified model.
// It sends a POST request to the Hugging Face inference endpoint with the provided question and context inputs.
// The response contains the answer or an error if the request fails.
func (ic *InferenceClient) QuestionAnswering(ctx context.Context, req *QuestionAnsweringRequest) (QuestionAnsweringResponse, error) {
func (ic *InferenceClient) QuestionAnswering(ctx context.Context, req *QuestionAnsweringRequest) (*QuestionAnsweringResponse, error) {
if req.Inputs.Question == "" {
return nil, errors.New("question is required")
}
Expand All @@ -168,7 +168,7 @@ func (ic *InferenceClient) QuestionAnswering(ctx context.Context, req *QuestionA
return nil, err
}

return questionAnsweringResponse, nil
return &questionAnsweringResponse, nil
}

// TableQuestionAnswering performs table-based question answering using the specified model.
Expand Down
2 changes: 1 addition & 1 deletion question_answering.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type QuestionAnsweringRequest struct {
}

// Response structure for question answering model
type QuestionAnsweringResponse []struct {
type QuestionAnsweringResponse struct {
// A string that’s the answer within the Context text.
Answer string `json:"answer,omitempty"`

Expand Down

0 comments on commit c8796d8

Please sign in to comment.