From c16db22728d3657d84b05ece542c11b5350c92c8 Mon Sep 17 00:00:00 2001 From: MrLetsplay Date: Wed, 7 Feb 2024 22:05:44 +0100 Subject: [PATCH] Fix blocking --- src/api.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/api.rs b/src/api.rs index e174d6c..82673ff 100644 --- a/src/api.rs +++ b/src/api.rs @@ -110,12 +110,16 @@ impl OllamaChat { pub async fn complete( chat: Arc>, ) -> anyhow::Result>> { - let mut chat = chat.write().await; - let body = serde_json::to_string(chat.deref())?; - println!("Sending: {}", body); + { + let mut chat = chat.write().await; + let body = serde_json::to_string(chat.deref())?; + println!("Sending: {}", body); - let msg = Arc::new(RwLock::new(String::from(""))); - chat.current_message = Some(msg.clone()); + let msg = Arc::new(RwLock::new(String::from(""))); + chat.current_message = Some(msg.clone()); + } + + let chat = chat.read().await; let request = chat .client