Skip to content

Commit

Permalink
Refactor HuggingFaceInjectionDetector
Browse files Browse the repository at this point in the history
  • Loading branch information
hupe1980 committed Sep 15, 2023
1 parent ed5f0f0 commit c98f171
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 1 addition & 5 deletions examples/hugging_face_injection_detector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"log"
"os"

huggingface "github.com/hupe1980/go-huggingface"

"github.com/hupe1980/golc"
"github.com/hupe1980/golc/agent"
"github.com/hupe1980/golc/model/chatmodel"
Expand All @@ -23,10 +21,8 @@ func main() {
log.Fatal(err)
}

client := huggingface.NewInferenceClient(os.Getenv("HUGGINGFACEHUB_API_TOKEN"))

agent, err := agent.NewOpenAIFunctions(openai, []schema.Tool{
tool.NewHuggingFaceInjectionDetector(client),
tool.NewHuggingFaceInjectionDetector(os.Getenv("HUGGINGFACEHUB_API_TOKEN")),
})
if err != nil {
log.Fatal(err)
Expand Down
8 changes: 7 additions & 1 deletion tool/hugging_face_injection_detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ type HuggingFaceInjectionDetector struct {
}

// NewHuggingFaceInjectionDetector creates a new instance of the HuggingFaceInjectionDetector tool.
func NewHuggingFaceInjectionDetector(client HuggingFaceInjectionDetectorClient, optFns ...func(o *HuggingFaceInjectionDetectorOptions)) *HuggingFaceInjectionDetector {
func NewHuggingFaceInjectionDetector(token string, optFns ...func(o *HuggingFaceInjectionDetectorOptions)) *HuggingFaceInjectionDetector {
client := huggingface.NewInferenceClient(token)
return NewHuggingFaceInjectionDetectorFromClient(client, optFns...)
}

// NewHuggingFaceInjectionDetectorFromClient creates a new instance of the HuggingFaceInjectionDetector tool.
func NewHuggingFaceInjectionDetectorFromClient(client HuggingFaceInjectionDetectorClient, optFns ...func(o *HuggingFaceInjectionDetectorOptions)) *HuggingFaceInjectionDetector {
opts := HuggingFaceInjectionDetectorOptions{
Model: "deepset/deberta-v3-base-injection",
Threshold: 0.8,
Expand Down

0 comments on commit c98f171

Please sign in to comment.