mirror of
https://github.com/mudler/LocalAI.git
synced 2026-04-02 14:16:02 -04:00
* feat: split remaining backends and drop embedded backends - Drop silero-vad, huggingface, and stores backend from embedded binaries - Refactor Makefile and Dockerfile to avoid building grpc backends - Drop golang code that was used to embed backends - Simplify building by using goreleaser Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * chore(gallery): be specific with llama-cpp backend templates Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * chore(docs): update Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * chore(ci): minor fixes Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * chore: drop all ffmpeg references Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix: run protogen-go Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Always enable p2p mode Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Update gorelease file Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(stores): do not always load Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Fix linting issues Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Simplify Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * Mac OS fixup Signed-off-by: Ettore Di Giacinto <mudler@localai.io> --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
package main
|
|
|
|
// This is a wrapper to statisfy the GRPC service interface
|
|
// It is meant to be used by the main executable that is the server for the specific backend type (falcon, gpt3, etc)
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/mudler/LocalAI/pkg/grpc/base"
|
|
pb "github.com/mudler/LocalAI/pkg/grpc/proto"
|
|
"github.com/mudler/LocalAI/pkg/langchain"
|
|
)
|
|
|
|
type LLM struct {
|
|
base.Base
|
|
|
|
langchain *langchain.HuggingFace
|
|
model string
|
|
}
|
|
|
|
func (llm *LLM) Load(opts *pb.ModelOptions) error {
|
|
var err error
|
|
hfToken := os.Getenv("HUGGINGFACEHUB_API_TOKEN")
|
|
if hfToken == "" {
|
|
return fmt.Errorf("no huggingface token provided")
|
|
}
|
|
llm.langchain, err = langchain.NewHuggingFace(opts.Model, hfToken)
|
|
llm.model = opts.Model
|
|
return err
|
|
}
|
|
|
|
func (llm *LLM) Predict(opts *pb.PredictOptions) (string, error) {
|
|
o := []langchain.PredictOption{
|
|
langchain.SetModel(llm.model),
|
|
langchain.SetMaxTokens(int(opts.Tokens)),
|
|
langchain.SetTemperature(float64(opts.Temperature)),
|
|
langchain.SetStopWords(opts.StopPrompts),
|
|
}
|
|
pred, err := llm.langchain.PredictHuggingFace(opts.Prompt, o...)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return pred.Completion, nil
|
|
}
|
|
|
|
func (llm *LLM) PredictStream(opts *pb.PredictOptions, results chan string) error {
|
|
o := []langchain.PredictOption{
|
|
langchain.SetModel(llm.model),
|
|
langchain.SetMaxTokens(int(opts.Tokens)),
|
|
langchain.SetTemperature(float64(opts.Temperature)),
|
|
langchain.SetStopWords(opts.StopPrompts),
|
|
}
|
|
go func() {
|
|
res, err := llm.langchain.PredictHuggingFace(opts.Prompt, o...)
|
|
|
|
if err != nil {
|
|
fmt.Println("err: ", err)
|
|
}
|
|
results <- res.Completion
|
|
close(results)
|
|
}()
|
|
|
|
return nil
|
|
}
|