summaryrefslogtreecommitdiffstats
path: root/src/repl/mod.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-07-28 08:56:00 +0800
committerGitHub <noreply@github.com>2024-07-28 08:56:00 +0800
commit49b61129c95a3528eaf25dabcb55825b5ed7be72 (patch)
tree18f4e8b46c8f5ca8093f1684a4c1dfa7d9f92a51 /src/repl/mod.rs
parent3441630c6223ebbab55d62c969390edf865d3d34 (diff)
downloadaichat-49b61129c95a3528eaf25dabcb55825b5ed7be72.tar.gz
feat: add `config.stream` and `.set stream` repl command (#759)
Diffstat (limited to 'src/repl/mod.rs')
-rw-r--r--src/repl/mod.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/repl/mod.rs b/src/repl/mod.rs
index 3cfd7de..0711a6d 100644
--- a/src/repl/mod.rs
+++ b/src/repl/mod.rs
@@ -6,7 +6,7 @@ use self::completer::ReplCompleter;
use self::highlighter::ReplHighlighter;
use self::prompt::ReplPrompt;
-use crate::client::chat_completion_streaming;
+use crate::client::{call_chat_completions, call_chat_completions_streaming};
use crate::config::{AssertState, Config, GlobalConfig, Input, StateFlags};
use crate::function::need_send_tool_results;
use crate::render::render_error;
@@ -286,8 +286,7 @@ impl Repl {
}
None => {
let banner = self.config.read().agent_banner()?;
- let output = self.config.read().markdown_render(&banner)?;
- println!("{output}");
+ self.config.read().print_markdown(&banner)?;
}
},
".variable" => match args {
@@ -569,8 +568,12 @@ async fn ask(
let client = input.create_client()?;
config.write().before_chat_completion(&input)?;
- let (output, tool_results) =
- chat_completion_streaming(&input, client.as_ref(), config, abort_signal.clone()).await?;
+ let (output, tool_results) = if config.read().stream {
+ call_chat_completions_streaming(&input, client.as_ref(), config, abort_signal.clone())
+ .await?
+ } else {
+ call_chat_completions(&input, client.as_ref(), config).await?
+ };
config
.write()
.after_chat_completion(&input, &output, &tool_results)?;