mirror of
https://github.com/sigoden/aichat
synced 2024-11-18 09:28:27 +00:00
chore: improve code quality, omit head 2 newlines in handler but in not client
This commit is contained in:
parent
978d4c54c0
commit
865fb49af9
@ -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)?;
|
||||
}
|
||||
}
|
||||
|
@ -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(())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user