mirror of
https://github.com/sigoden/aichat
synced 2024-11-18 09:28:27 +00:00
chore: no longer ignore any error
This commit is contained in:
parent
4e729db237
commit
2a7a6f5f27
@ -54,11 +54,11 @@ impl ChatGptClient {
|
||||
self.runtime.block_on(async {
|
||||
tokio::select! {
|
||||
ret = self.send_message_streaming_inner(input, prompt, handler) => {
|
||||
handler.done();
|
||||
handler.done()?;
|
||||
ret.with_context(|| "Failed to send message streaming")
|
||||
}
|
||||
_ = watch_abort(abort.clone()) => {
|
||||
handler.done();
|
||||
handler.done()?;
|
||||
Ok(())
|
||||
},
|
||||
_ = tokio::signal::ctrl_c() => {
|
||||
@ -91,7 +91,7 @@ impl ChatGptClient {
|
||||
handler: &mut ReplyStreamHandler,
|
||||
) -> Result<()> {
|
||||
if self.config.borrow().dry_run {
|
||||
handler.text(&combine(content, prompt));
|
||||
handler.text(&combine(content, prompt))?;
|
||||
return Ok(());
|
||||
}
|
||||
let builder = self.request_builder(content, prompt, true)?;
|
||||
@ -115,7 +115,7 @@ impl ChatGptClient {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
handler.text(text);
|
||||
handler.text(text)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ pub use self::markdown::MarkdownRender;
|
||||
use self::repl::repl_render_stream;
|
||||
|
||||
use crate::client::ChatGptClient;
|
||||
use crate::print_now;
|
||||
use crate::repl::{ReplyStreamHandler, SharedAbortSignal};
|
||||
use anyhow::Result;
|
||||
use crossbeam::channel::unbounded;
|
||||
@ -26,11 +27,15 @@ pub fn render_stream(
|
||||
let (tx, rx) = unbounded();
|
||||
let abort_clone = abort.clone();
|
||||
spawn(move || {
|
||||
let _ = if repl {
|
||||
let err = if repl {
|
||||
repl_render_stream(rx, abort)
|
||||
} else {
|
||||
cmd_render_stream(rx, abort)
|
||||
};
|
||||
if let Err(err) = err {
|
||||
let err = format!("{err:?}");
|
||||
print_now!("{}\n\n", err.trim());
|
||||
}
|
||||
drop(wg);
|
||||
});
|
||||
ReplyStreamHandler::new(Some(tx), abort_clone)
|
||||
|
@ -3,7 +3,7 @@ use crate::config::SharedConfig;
|
||||
use crate::print_now;
|
||||
use crate::render::render_stream;
|
||||
|
||||
use anyhow::Result;
|
||||
use anyhow::{Context, Result};
|
||||
use crossbeam::channel::Sender;
|
||||
use crossbeam::sync::WaitGroup;
|
||||
use std::cell::RefCell;
|
||||
@ -110,22 +110,25 @@ impl ReplyStreamHandler {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn text(&mut self, text: &str) {
|
||||
pub fn text(&mut self, text: &str) -> Result<()> {
|
||||
match self.sender.as_ref() {
|
||||
Some(tx) => {
|
||||
let _ = tx.send(ReplyStreamEvent::Text(text.to_string()));
|
||||
tx.send(ReplyStreamEvent::Text(text.to_string()))
|
||||
.with_context(|| "Failed to send StreamEvent:Text")?;
|
||||
}
|
||||
None => {
|
||||
print_now!("{}", text);
|
||||
}
|
||||
}
|
||||
self.buffer.push_str(text);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn done(&mut self) {
|
||||
pub fn done(&mut self) -> Result<()> {
|
||||
match self.sender.as_ref() {
|
||||
Some(tx) => {
|
||||
let _ = tx.send(ReplyStreamEvent::Done);
|
||||
tx.send(ReplyStreamEvent::Done)
|
||||
.with_context(|| "Failed to send StreamEvent:Done")?;
|
||||
}
|
||||
None => {
|
||||
if !self.buffer.ends_with('\n') {
|
||||
@ -133,6 +136,7 @@ impl ReplyStreamHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_buffer(&self) -> &str {
|
||||
|
Loading…
Reference in New Issue
Block a user