diff options
Diffstat (limited to 'src/client/common.rs')
| -rw-r--r-- | src/client/common.rs | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/src/client/common.rs b/src/client/common.rs index d8909ee..5ad27ae 100644 --- a/src/client/common.rs +++ b/src/client/common.rs @@ -14,7 +14,7 @@ use inquire::{required, Text}; use reqwest::{Client as ReqwestClient, RequestBuilder}; use serde::Deserialize; use serde_json::{json, Value}; -use std::{future::Future, time::Duration}; +use std::time::Duration; use tokio::sync::mpsc::unbounded_channel; const MODELS_YAML: &str = include_str!("../../models.yaml"); @@ -378,6 +378,7 @@ pub fn create_openai_compatible_client_config(client: &str) -> Result<Option<(St pub async fn call_chat_completions( input: &Input, + print: bool, extract_code: bool, client: &dyn Client, abort_signal: AbortSignal, @@ -397,10 +398,12 @@ pub async fn call_chat_completions( .. } = ret; if !text.is_empty() { - if extract_code && text.trim_start().starts_with("```") { - text = extract_block(&text); + if extract_code { + text = extract_code_block(&text).to_string(); + } + if print { + client.global_config().read().print_markdown(&text)?; } - client.global_config().read().print_markdown(&text)?; } Ok((text, eval_tool_calls(client.global_config(), tool_calls)?)) } @@ -444,23 +447,6 @@ pub async fn call_chat_completions_streaming( } } -#[allow(unused)] -pub async fn chat_completions_as_streaming<F, Fut>( - builder: RequestBuilder, - handler: &mut SseHandler, - f: F, -) -> Result<()> -where - F: FnOnce(RequestBuilder) -> Fut, - Fut: Future<Output = Result<String>>, -{ - let text = f(builder).await?; - handler.text(&text)?; - handler.done(); - - Ok(()) -} - pub fn noop_prepare_embeddings<T>(_client: &T, _data: &EmbeddingsData) -> Result<RequestData> { bail!("The client doesn't support embeddings api") } |
