File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ use std:: fs:: File ;
2+ use std:: io:: Write ;
13use std:: sync:: atomic:: { AtomicBool , Ordering } ;
24use std:: sync:: Arc ;
35use tokio:: time:: { sleep, Duration } ;
@@ -123,11 +125,9 @@ impl LLM for ChatGPT {
123125
124126 let answer: Value = serde_json:: from_str ( data_json. as_str ( ) ) ?;
125127
126- let msg = answer[ "choices" ] [ 0 ] [ "delta" ] [ "content" ]
127- . as_str ( )
128- . unwrap_or ( "\n " ) ;
128+ let msg = answer[ "choices" ] [ 0 ] [ "delta" ] [ "content" ] . as_str ( ) ;
129129
130- if msg != "null" {
130+ if let Some ( msg) = msg {
131131 sender. send ( Event :: LLMEvent ( LLMAnswer :: Answer ( msg. to_string ( ) ) ) ) ?;
132132 }
133133
Original file line number Diff line number Diff line change @@ -101,18 +101,17 @@ impl LLM for LLamacpp {
101101 return Ok ( ( ) ) ;
102102 }
103103
104- let answer: Value = serde_json:: from_str ( data_json. as_str ( ) ) ?;
105-
106- if answer[ "choices" ] [ "finish_reason" ] == "stop" {
104+ if data_json. as_str ( ) == "[DONE]" {
107105 sender. send ( Event :: LLMEvent ( LLMAnswer :: EndAnswer ) ) ?;
108106 return Ok ( ( ) ) ;
109107 }
108+ let answer: Value = serde_json:: from_str ( data_json. as_str ( ) ) ?;
110109
111- let msg = answer[ "choices" ] [ 0 ] [ "delta" ] [ "content" ]
112- . as_str ( )
113- . unwrap_or ( "\n " ) ;
110+ let msg = answer[ "choices" ] [ 0 ] [ "delta" ] [ "content" ] . as_str ( ) ;
114111
115- sender. send ( Event :: LLMEvent ( LLMAnswer :: Answer ( msg. to_string ( ) ) ) ) ?;
112+ if let Some ( msg) = msg {
113+ sender. send ( Event :: LLMEvent ( LLMAnswer :: Answer ( msg. to_string ( ) ) ) ) ?;
114+ }
116115 }
117116 }
118117 }
You can’t perform that action at this time.
0 commit comments