summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client.rs7
-rw-r--r--src/repl/handler.rs5
2 files changed, 4 insertions, 8 deletions
diff --git a/src/client.rs b/src/client.rs
index dccea1b..361f897 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -104,7 +104,6 @@ impl ChatGptClient {
bail!("Request failed");
}
let mut stream = res.bytes_stream().eventsource();
- let mut virgin = true;
while let Some(part) = stream.next().await {
let chunk = part?.data;
if chunk == "[DONE]" {
@@ -117,12 +116,6 @@ impl ChatGptClient {
if text.is_empty() {
continue;
}
- if virgin {
- virgin = false;
- if text == "\n\n" {
- continue;
- }
- }
handler.text(text)?;
}
}
diff --git a/src/repl/handler.rs b/src/repl/handler.rs
index a0b1e5c..2263ca2 100644
--- a/src/repl/handler.rs
+++ b/src/repl/handler.rs
@@ -121,6 +121,10 @@ impl ReplyStreamHandler {
}
pub fn text(&mut self, text: &str) -> Result<()> {
+ if self.buffer.is_empty() && text == "\n\n" {
+ return Ok(());
+ }
+ self.buffer.push_str(text);
match self.sender.as_ref() {
Some(tx) => {
let ret = tx
@@ -132,7 +136,6 @@ impl ReplyStreamHandler {
print_now!("{}", text);
}
}
- self.buffer.push_str(text);
Ok(())
}