aboutsummaryrefslogtreecommitdiff
path: root/src/app.rs
diff options
context:
space:
mode:
authorOxbian <oxbian@mailbox.org>2025-02-19 23:56:49 -0500
committerOxbian <oxbian@mailbox.org>2025-02-19 23:56:49 -0500
commit0d4bbf7a60012b459be5dfe3077055c8e25bba02 (patch)
tree17c24fd3de9e43dcd7162f26ae9669dfb0b67780 /src/app.rs
parentb6d93c110c8a14f738d897c0012a2a7d61044f67 (diff)
downloadNAI-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.rs30
1 files changed, 18 insertions, 12 deletions
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,
});
ArKa projects. All rights to me, and your next child right arm.