diff options
author | Oxbian <oxbian@mailbox.org> | 2025-02-19 23:56:49 -0500 |
---|---|---|
committer | Oxbian <oxbian@mailbox.org> | 2025-02-19 23:56:49 -0500 |
commit | 0d4bbf7a60012b459be5dfe3077055c8e25bba02 (patch) | |
tree | 17c24fd3de9e43dcd7162f26ae9669dfb0b67780 /src/app.rs | |
parent | b6d93c110c8a14f738d897c0012a2a7d61044f67 (diff) | |
download | NAI-0d4bbf7a60012b459be5dfe3077055c8e25bba02.tar.gz NAI-0d4bbf7a60012b459be5dfe3077055c8e25bba02.zip |
feat: working multiline cursor + message type now showed
Diffstat (limited to 'src/app.rs')
-rw-r--r-- | src/app.rs | 30 |
1 files changed, 18 insertions, 12 deletions
@@ -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, }); |