mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-08-01 23:49:14 +00:00
feat: adding temperature to server mode (#705)
Signed-off-by: Aris Boutselis <arisboutselis08@gmail.com> Co-authored-by: Aris Boutselis <arisboutselis08@gmail.com>
This commit is contained in:
parent
2a34ff24d1
commit
539ca3b78f
@ -15,6 +15,7 @@ package serve
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/k8sgpt-ai/k8sgpt/pkg/ai"
|
"github.com/k8sgpt-ai/k8sgpt/pkg/ai"
|
||||||
@ -24,6 +25,10 @@ import (
|
|||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
defaultTemperature float32 = 0.7
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
port string
|
port string
|
||||||
metricsPort string
|
metricsPort string
|
||||||
@ -44,6 +49,23 @@ var ServeCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
var aiProvider *ai.AIProvider
|
var aiProvider *ai.AIProvider
|
||||||
if len(configAI.Providers) == 0 {
|
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
|
// Check for env injection
|
||||||
backend = os.Getenv("K8SGPT_BACKEND")
|
backend = os.Getenv("K8SGPT_BACKEND")
|
||||||
password := os.Getenv("K8SGPT_PASSWORD")
|
password := os.Getenv("K8SGPT_PASSWORD")
|
||||||
@ -60,6 +82,7 @@ var ServeCmd = &cobra.Command{
|
|||||||
Model: model,
|
Model: model,
|
||||||
BaseURL: baseURL,
|
BaseURL: baseURL,
|
||||||
Engine: engine,
|
Engine: engine,
|
||||||
|
Temperature: temperature(),
|
||||||
}
|
}
|
||||||
|
|
||||||
configAI.Providers = append(configAI.Providers, *aiProvider)
|
configAI.Providers = append(configAI.Providers, *aiProvider)
|
||||||
|
Loading…
Reference in New Issue
Block a user