Skip to content

Commit

Permalink
feat: adding temperature to server mode (#705)
Browse files Browse the repository at this point in the history
Signed-off-by: Aris Boutselis <arisboutselis08@gmail.com>
Co-authored-by: Aris Boutselis <arisboutselis08@gmail.com>
  • Loading branch information
Aris Boutselis and arbreezy committed Oct 12, 2023
1 parent 2a34ff2 commit 539ca3b
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions cmd/serve/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package serve

import (
"os"
"strconv"

"github.com/fatih/color"
"github.com/k8sgpt-ai/k8sgpt/pkg/ai"
Expand All @@ -24,6 +25,10 @@ import (
"go.uber.org/zap"
)

const (
defaultTemperature float32 = 0.7
)

var (
port string
metricsPort string
Expand All @@ -44,6 +49,23 @@ var ServeCmd = &cobra.Command{
}
var aiProvider *ai.AIProvider
if len(configAI.Providers) == 0 {
// we validate and set temperature for our backend
temperature := func() float32 {
env := os.Getenv("K8SGPT_TEMPERATURE")
if env == "" {
return defaultTemperature
}
temperature, err := strconv.ParseFloat(env, 32)
if err != nil {
color.Red("Unable to convert Temperature value: %v", err)
os.Exit(1)
}
if temperature > 1.0 || temperature < 0.0 {
color.Red("Error: temperature ranges from 0 to 1.")
os.Exit(1)
}
return float32(temperature)
}
// Check for env injection
backend = os.Getenv("K8SGPT_BACKEND")
password := os.Getenv("K8SGPT_PASSWORD")
Expand All @@ -55,11 +77,12 @@ 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,
Temperature: temperature(),
}

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

0 comments on commit 539ca3b

Please sign in to comment.