-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into tokenization
- Loading branch information
Showing
25 changed files
with
575 additions
and
88 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
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
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,44 @@ | ||
package backend | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/mudler/LocalAI/core/config" | ||
"github.com/mudler/LocalAI/pkg/grpc/proto" | ||
model "github.com/mudler/LocalAI/pkg/model" | ||
) | ||
|
||
func TokenMetrics( | ||
backend, | ||
modelFile string, | ||
loader *model.ModelLoader, | ||
appConfig *config.ApplicationConfig, | ||
backendConfig config.BackendConfig) (*proto.MetricsResponse, error) { | ||
bb := backend | ||
if bb == "" { | ||
return nil, fmt.Errorf("backend is required") | ||
} | ||
|
||
grpcOpts := GRPCModelOpts(backendConfig) | ||
|
||
opts := modelOpts(config.BackendConfig{}, appConfig, []model.Option{ | ||
model.WithBackendString(bb), | ||
model.WithModel(modelFile), | ||
model.WithContext(appConfig.Context), | ||
model.WithAssetDir(appConfig.AssetsDestination), | ||
model.WithLoadGRPCLoadModelOpts(grpcOpts), | ||
}) | ||
model, err := loader.BackendLoader(opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if model == nil { | ||
return nil, fmt.Errorf("could not loadmodel model") | ||
} | ||
|
||
res, err := model.GetTokenMetrics(context.Background(), &proto.MetricsRequest{}) | ||
|
||
return res, err | ||
} |
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
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,35 @@ | ||
package config | ||
|
||
import "regexp" | ||
|
||
type BackendConfigFilterFn func(string, *BackendConfig) bool | ||
|
||
func NoFilterFn(_ string, _ *BackendConfig) bool { return true } | ||
|
||
func BuildNameFilterFn(filter string) (BackendConfigFilterFn, error) { | ||
if filter == "" { | ||
return NoFilterFn, nil | ||
} | ||
rxp, err := regexp.Compile(filter) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return func(name string, config *BackendConfig) bool { | ||
if config != nil { | ||
return rxp.MatchString(config.Name) | ||
} | ||
return rxp.MatchString(name) | ||
}, nil | ||
} | ||
|
||
func BuildUsecaseFilterFn(usecases BackendConfigUsecases) BackendConfigFilterFn { | ||
if usecases == FLAG_ANY { | ||
return NoFilterFn | ||
} | ||
return func(name string, config *BackendConfig) bool { | ||
if config == nil { | ||
return false // TODO: Potentially make this a param, for now, no known usecase to include | ||
} | ||
return config.HasUsecases(usecases) | ||
} | ||
} |
Oops, something went wrong.