From 0d4bbf7a60012b459be5dfe3077055c8e25bba02 Mon Sep 17 00:00:00 2001 From: Oxbian Date: Wed, 19 Feb 2025 23:56:49 -0500 Subject: feat: working multiline cursor + message type now showed --- src/app.rs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'src/app.rs') diff --git a/src/app.rs b/src/app.rs index efc90ca..ff9f130 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,7 +1,7 @@ -use reqwest; -use serde_json::{Value}; use color_eyre::Result; -use std::{fmt, collections::HashMap}; +use reqwest; +use serde_json::Value; +use std::{collections::HashMap, fmt}; #[derive(Debug)] pub struct App { @@ -16,7 +16,10 @@ pub struct Message { impl fmt::Display for Message { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.content) + match self.msg_type { + MessageType::Human => return write!(f, "You: {}", self.content), + MessageType::LLM => return write!(f, "Néo AI: {}", self.content), + } } } @@ -35,16 +38,19 @@ impl App { pub fn send_message(&mut self, content: String) -> Result<()> { // POST: http://localhost:8080/completion {"prompt": "lorem ipsum"} - self.messages.push(Message{ - content: content.clone(), - msg_type: MessageType::Human + self.messages.push(Message { + content: content.clone(), + msg_type: MessageType::Human, }); let client = reqwest::blocking::Client::new(); - let response = client.post("http://localhost:8080/completion").json(&serde_json::json!({ - "prompt": &content, - "n_predict": 128, - })).send()?; + let response = client + .post("http://localhost:8080/completion") + .json(&serde_json::json!({ + "prompt": &content, + "n_predict": 128, + })) + .send()?; if response.status().is_success() { // Désérialiser la réponse JSON @@ -52,7 +58,7 @@ impl App { // Accéder à la partie spécifique du JSON if let Some(msg) = json_response["content"].as_str() { - self.messages.push(Message{ + self.messages.push(Message { content: msg.to_string().clone(), msg_type: MessageType::LLM, }); -- cgit v1.2.3