File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ package main
4
4
// It is meant to be used by the main executable that is the server for the specific backend type (falcon, gpt3, etc)
5
5
import (
6
6
"fmt"
7
+ "os"
7
8
8
9
"github.com/go-skynet/LocalAI/pkg/grpc/base"
9
10
pb "github.com/go-skynet/LocalAI/pkg/grpc/proto"
@@ -18,9 +19,14 @@ type LLM struct {
18
19
}
19
20
20
21
func (llm * LLM ) Load (opts * pb.ModelOptions ) error {
21
- llm .langchain , _ = langchain .NewHuggingFace (opts .Model )
22
+ var err error
23
+ hfToken := os .Getenv ("HUGGINGFACEHUB_API_TOKEN" )
24
+ if hfToken == "" {
25
+ return fmt .Errorf ("no huggingface token provided" )
26
+ }
27
+ llm .langchain , err = langchain .NewHuggingFace (opts .Model , hfToken )
22
28
llm .model = opts .Model
23
- return nil
29
+ return err
24
30
}
25
31
26
32
func (llm * LLM ) Predict (opts * pb.PredictOptions ) (string , error ) {
Original file line number Diff line number Diff line change @@ -2,26 +2,32 @@ package langchain
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
5
6
6
7
"github.com/tmc/langchaingo/llms"
7
8
"github.com/tmc/langchaingo/llms/huggingface"
8
9
)
9
10
10
11
type HuggingFace struct {
11
12
modelPath string
13
+ token string
12
14
}
13
15
14
- func NewHuggingFace (repoId string ) (* HuggingFace , error ) {
16
+ func NewHuggingFace (repoId , token string ) (* HuggingFace , error ) {
17
+ if token == "" {
18
+ return nil , fmt .Errorf ("no huggingface token provided" )
19
+ }
15
20
return & HuggingFace {
16
21
modelPath : repoId ,
22
+ token : token ,
17
23
}, nil
18
24
}
19
25
20
26
func (s * HuggingFace ) PredictHuggingFace (text string , opts ... PredictOption ) (* Predict , error ) {
21
27
po := NewPredictOptions (opts ... )
22
28
23
29
// Init client
24
- llm , err := huggingface .New ()
30
+ llm , err := huggingface .New (huggingface . WithToken ( s . token ) )
25
31
if err != nil {
26
32
return nil , err
27
33
}
You can’t perform that action at this time.
0 commit comments