From 28db83e17b83c55ce9b82c4ba931c707996bce34 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Sat, 19 Aug 2023 16:15:22 +0200 Subject: [PATCH] fix: disable usage by default (still experimental) (#929) Signed-off-by: Ettore Di Giacinto --- api/backend/llm.go | 5 +++-- api/config/config.go | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/api/backend/llm.go b/api/backend/llm.go index e40db21a..01b3eb1b 100644 --- a/api/backend/llm.go +++ b/api/backend/llm.go @@ -74,8 +74,9 @@ func ModelInference(ctx context.Context, s string, loader *model.ModelLoader, c tokenUsage := TokenUsage{} - // check the per-model feature flag for usage, since tokenCallback may have a cost, but default to on. - if !c.FeatureFlag["usage"] { + // check the per-model feature flag for usage, since tokenCallback may have a cost. + // Defaults to off as for now it is still experimental + if c.FeatureFlag.Enabled("usage") { userTokenCallback := tokenCallback if userTokenCallback == nil { userTokenCallback = func(token string, usage TokenUsage) bool { diff --git a/api/config/config.go b/api/config/config.go index 24a6658e..65f08557 100644 --- a/api/config/config.go +++ b/api/config/config.go @@ -29,7 +29,7 @@ type Config struct { FunctionsConfig Functions `yaml:"function"` - FeatureFlag map[string]bool `yaml:"feature_flags"` // Feature Flag registry. We move fast, and features may break on a per model/backend basis. Registry for (usually temporary) flags that indicate aborting something early. + FeatureFlag FeatureFlag `yaml:"feature_flags"` // Feature Flag registry. We move fast, and features may break on a per model/backend basis. Registry for (usually temporary) flags that indicate aborting something early. // LLM configs (GPT4ALL, Llama.cpp, ...) LLMConfig `yaml:",inline"` @@ -45,6 +45,13 @@ type Config struct { GRPC GRPC `yaml:"grpc"` } +type FeatureFlag map[string]*bool + +func (ff FeatureFlag) Enabled(s string) bool { + v, exist := ff[s] + return exist && v != nil && *v +} + type GRPC struct { Attempts int `yaml:"attempts"` AttemptsSleepTime int `yaml:"attempts_sleep_time"`