@@ -11,6 +11,7 @@ import (
11
11
"net/http"
12
12
"os"
13
13
"path/filepath"
14
+ "strconv"
14
15
"strings"
15
16
16
17
"golang.org/x/crypto/ssh/terminal"
@@ -23,8 +24,9 @@ const AI = "AI 🤖: "
23
24
var messageHistory []Message
24
25
25
26
type chatRequest struct {
26
- Model string `json:"model"`
27
- Messages []Message `json:"messages"`
27
+ Model string `json:"model"`
28
+ Temperature float32 `json:"temperature"`
29
+ Messages []Message `json:"messages"`
28
30
}
29
31
30
32
type Message struct {
@@ -52,9 +54,10 @@ type completionResponse struct {
52
54
}
53
55
54
56
type Settings struct {
55
- APIKey string `json:"api_key"`
56
- Model string `json:"model"`
57
- Role string `json:"role"`
57
+ APIKey string `json:"api_key"`
58
+ Model string `json:"model"`
59
+ Temperature float32 `json:"temperature"`
60
+ Role string `json:"role"`
58
61
}
59
62
60
63
func main () {
@@ -175,6 +178,26 @@ func modifySettings(filePath string) Settings {
175
178
}
176
179
}
177
180
181
+ if settings .Temperature == 0 {
182
+ fmt .Println ("Please enter the temperature (Default is 0.7):" )
183
+
184
+ scanner := bufio .NewScanner (os .Stdin )
185
+ if scanner .Scan () {
186
+ input := scanner .Text ()
187
+ temp , err := strconv .ParseFloat (input , 32 )
188
+
189
+ if err == nil && temp > 0 && temp <= 1 {
190
+ settings .Temperature = float32 (temp )
191
+ } else {
192
+ settings .Temperature = 0.7
193
+ }
194
+ }
195
+
196
+ if settings .Temperature == 0 {
197
+ settings .Temperature = 0.7
198
+ }
199
+ }
200
+
178
201
contents , _ := json .Marshal (settings )
179
202
os .WriteFile (filePath , contents , 0600 )
180
203
@@ -194,8 +217,9 @@ func askAI(apiKey, model, question string) string {
194
217
messageHistory = append (messageHistory , Message {Role : "user" , Content : question })
195
218
196
219
requestBody := chatRequest {
197
- Model : model ,
198
- Messages : messageHistory ,
220
+ Model : model ,
221
+ Temperature : 0.7 ,
222
+ Messages : messageHistory ,
199
223
}
200
224
201
225
jsonValue , _ := json .Marshal (requestBody )
0 commit comments