aboutsummaryrefslogtreecommitdiff
path: root/src/app.rs
diff options
context:
space:
mode:
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.