Skip to content

Commit a50375c

Browse files
fix: add maxTokens to serve mode (#1280)
Signed-off-by: samir-tahir <[email protected]> Co-authored-by: Alex Jones <[email protected]>
1 parent da266b3 commit a50375c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

cmd/serve/serve.go

+14
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const (
3030
defaultTemperature float32 = 0.7
3131
defaultTopP float32 = 1.0
3232
defaultTopK int32 = 50
33+
defaultMaxTokens int = 2048
3334
)
3435

3536
var (
@@ -102,6 +103,18 @@ var ServeCmd = &cobra.Command{
102103
}
103104
return int32(topK)
104105
}
106+
maxTokens := func() int {
107+
env := os.Getenv("K8SGPT_MAX_TOKENS")
108+
if env == "" {
109+
return defaultMaxTokens
110+
}
111+
maxTokens, err := strconv.ParseInt(env, 10, 32)
112+
if err != nil {
113+
color.Red("Unable to convert maxTokens value: %v", err)
114+
os.Exit(1)
115+
}
116+
return int(maxTokens)
117+
}
105118
// Check for env injection
106119
backend = os.Getenv("K8SGPT_BACKEND")
107120
password := os.Getenv("K8SGPT_PASSWORD")
@@ -125,6 +138,7 @@ var ServeCmd = &cobra.Command{
125138
Temperature: temperature(),
126139
TopP: topP(),
127140
TopK: topK(),
141+
MaxTokens: maxTokens(),
128142
}
129143

130144
configAI.Providers = append(configAI.Providers, *aiProvider)

0 commit comments

Comments
 (0)