-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
huggingface "github.com/hupe1980/go-huggingface" | ||
) | ||
|
||
func main() { | ||
ic := huggingface.NewInferenceClient(os.Getenv("HUGGINGFACEHUB_API_TOKEN")) | ||
|
||
res, err := ic.TableQuestionAnswering(context.Background(), &huggingface.TableQuestionAnsweringRequest{ | ||
Inputs: huggingface.TableQuestionAnsweringInputs{ | ||
Query: "How many stars does the transformers repository have?", | ||
Table: map[string][]string{ | ||
"Repository": {"Transformers", "Datasets", "Tokenizers"}, | ||
"Stars": {"36542", "4512", "3934"}, | ||
"Contributors": {"651", "77", "34"}, | ||
}, | ||
}, | ||
}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
fmt.Println("Answer:", res.Answer) | ||
fmt.Println("Coordinates:", res.Coordinates) | ||
fmt.Println("Cells:", res.Cells) | ||
fmt.Println("Aggregator:", res.Aggregator) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package gohuggingface | ||
|
||
// Request structure for table question answering model | ||
type TableQuestionAnsweringRequest struct { | ||
Inputs TableQuestionAnsweringInputs `json:"inputs"` | ||
Options Options `json:"options,omitempty"` | ||
Model string `json:"-"` | ||
} | ||
|
||
type TableQuestionAnsweringInputs struct { | ||
// (Required) The query in plain text that you want to ask the table | ||
Query string `json:"query"` | ||
|
||
// (Required) A table of data represented as a dict of list where entries | ||
// are headers and the lists are all the values, all lists must | ||
// have the same size. | ||
Table map[string][]string `json:"table"` | ||
} | ||
|
||
// Response structure for table question answering model | ||
type TableQuestionAnsweringResponse struct { | ||
// The plaintext answer | ||
Answer string `json:"answer,omitempty"` | ||
|
||
// A list of coordinates of the cells references in the answer | ||
Coordinates [][]int `json:"coordinates,omitempty"` | ||
|
||
// A list of coordinates of the cells contents | ||
Cells []string `json:"cells,omitempty"` | ||
|
||
// The aggregator used to get the answer | ||
Aggregator string `json:"aggregator,omitempty"` | ||
} |