Skip to content

Commit

Permalink
feat: set topP from the environment
Browse files Browse the repository at this point in the history
Signed-off-by: “Guido <muscionig@gmail.com>
  • Loading branch information
muscionig committed Apr 16, 2024
1 parent 346ba4b commit 363ea76
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions cmd/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

const (
defaultTemperature float32 = 0.7
defaultTopP float32 = 1.0
)

var (
Expand Down Expand Up @@ -67,6 +68,22 @@ var ServeCmd = &cobra.Command{
}
return float32(temperature)
}
topP := func() float32 {
env := os.Getenv("K8SGPT_TOP_P")
if env == "" {
return defaultTopP
}
topP, err := strconv.ParseFloat(env, 32)
if err != nil {
color.Red("Unable to convert topP value: %v", err)
os.Exit(1)
}
if topP > 1.0 || topP < 0.0 {
color.Red("Error: topP ranges from 0 to 1.")
os.Exit(1)
}
return float32(topP)
}
// Check for env injection
backend = os.Getenv("K8SGPT_BACKEND")
password := os.Getenv("K8SGPT_PASSWORD")
Expand All @@ -79,13 +96,14 @@ var ServeCmd = &cobra.Command{
envIsSet := backend != "" || password != "" || model != ""
if envIsSet {
aiProvider = &ai.AIProvider{
Name: backend,
Password: password,
Model: model,
BaseURL: baseURL,
Engine: engine,
Name: backend,
Password: password,
Model: model,
BaseURL: baseURL,
Engine: engine,
ProxyEndpoint: proxyEndpoint,
Temperature: temperature(),
Temperature: temperature(),
TopP: topP(),
}

configAI.Providers = append(configAI.Providers, *aiProvider)
Expand Down

0 comments on commit 363ea76

Please sign in to comment.