@@ -3,7 +3,8 @@ mod spinners;
3
3
4
4
use std:: {
5
5
collections:: HashMap ,
6
- io:: { stdout, Write } ,
6
+ fs:: File ,
7
+ io:: { stdout, BufRead , BufReader , Write } ,
7
8
panic,
8
9
path:: { self , Path } ,
9
10
sync:: { Arc , Mutex } ,
@@ -223,7 +224,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
223
224
}
224
225
225
226
println ! ( "To clear the conversation history, type /clear" ) ;
226
-
227
227
loop {
228
228
let readline = rl. readline ( ">> " ) ;
229
229
match readline {
@@ -318,7 +318,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
318
318
319
319
config:: save_config ( & config_dir. display ( ) . to_string ( ) . as_str ( ) , & config) . await ?;
320
320
321
- if config. app . notify_save {
321
+ println ! ( "Saved config!" ) ;
322
+
323
+ if config. app . save_conversation && !messages. is_empty ( ) {
322
324
let logs_dir = data_dir. join ( "logs" ) ;
323
325
if !logs_dir. exists ( ) {
324
326
tokio:: fs:: create_dir_all ( & logs_dir) . await ?;
@@ -333,7 +335,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
333
335
let mut log_file = tokio:: io:: BufWriter :: new ( log_file) ;
334
336
335
337
let messages_json = serde_json:: to_string ( & messages) ?;
338
+
336
339
log_file. write_all ( messages_json. as_bytes ( ) ) . await ?;
340
+ // Ensure the data is written to disk
341
+ log_file. flush ( ) . await ?;
337
342
338
343
let mut log_file_content = String :: new ( ) ;
339
344
for message in messages {
@@ -356,6 +361,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
356
361
let mut log_file = tokio:: io:: BufWriter :: new ( log_file) ;
357
362
358
363
log_file. write_all ( log_file_content. as_bytes ( ) ) . await ?;
364
+ log_file. flush ( ) . await ?;
359
365
}
360
366
361
367
Ok ( ( ) )
@@ -514,14 +520,7 @@ async fn chat_completion(
514
520
) ;
515
521
execute ! ( stdout( ) , Clear ( ClearType :: UntilNewLine ) ) . unwrap ( ) ;
516
522
517
- tokio:: time:: sleep ( std:: time:: Duration :: from_millis (
518
- if u64:: from ( spinner_interval) < rainbow_delay {
519
- rainbow_delay
520
- } else {
521
- spinner_interval. into ( )
522
- } ,
523
- ) )
524
- . await ;
523
+ tokio:: time:: sleep ( std:: time:: Duration :: from_millis ( rainbow_delay) ) . await ;
525
524
526
525
i = i + 1 ;
527
526
}
0 commit comments