2024-04-24 22:19:02 +00:00
|
|
|
package backend
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2024-06-23 08:24:36 +00:00
|
|
|
"github.com/mudler/LocalAI/core/config"
|
|
|
|
"github.com/mudler/LocalAI/pkg/grpc/proto"
|
|
|
|
model "github.com/mudler/LocalAI/pkg/model"
|
2024-04-24 22:19:02 +00:00
|
|
|
)
|
|
|
|
|
2024-10-02 06:55:58 +00:00
|
|
|
func Rerank(modelFile string, request *proto.RerankRequest, loader *model.ModelLoader, appConfig *config.ApplicationConfig, backendConfig config.BackendConfig) (*proto.RerankResult, error) {
|
2024-04-24 22:19:02 +00:00
|
|
|
|
2024-10-02 06:55:58 +00:00
|
|
|
opts := ModelOptions(backendConfig, appConfig, []model.Option{model.WithModel(modelFile)})
|
2024-04-24 22:19:02 +00:00
|
|
|
rerankModel, err := loader.BackendLoader(opts...)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if rerankModel == nil {
|
|
|
|
return nil, fmt.Errorf("could not load rerank model")
|
|
|
|
}
|
|
|
|
|
|
|
|
res, err := rerankModel.Rerank(context.Background(), request)
|
|
|
|
|
|
|
|
return res, err
|
|
|
|
}
|