Show time in assistant messages

This commit is contained in:
Antonio Scandurra 2023-05-29 16:23:16 +02:00
parent 52e8bf2928
commit 890c42a75a
5 changed files with 22 additions and 3 deletions

1
Cargo.lock generated
View File

@ -101,6 +101,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"assets",
"chrono",
"collections",
"editor",
"futures 0.3.28",

View File

@ -19,11 +19,12 @@ theme = { path = "../theme" }
util = { path = "../util" }
workspace = { path = "../workspace" }
serde.workspace = true
serde_json.workspace = true
anyhow.workspace = true
chrono = "0.4"
futures.workspace = true
isahc.workspace = true
serde.workspace = true
serde_json.workspace = true
[dev-dependencies]
editor = { path = "../editor", features = ["test-support"] }

View File

@ -1,5 +1,6 @@
use crate::{OpenAIRequest, OpenAIResponseStreamEvent, RequestMessage, Role};
use anyhow::{anyhow, Result};
use chrono::{DateTime, Local};
use collections::HashMap;
use editor::{Editor, ExcerptId, ExcerptRange, MultiBuffer};
use futures::{io::BufReader, AsyncBufReadExt, AsyncReadExt, Stream, StreamExt};
@ -343,6 +344,7 @@ impl Assistant {
let message = Message {
role,
content: content.clone(),
sent_at: Local::now(),
};
self.messages.push(message.clone());
self.messages_by_id.insert(excerpt_id, message.clone());
@ -394,7 +396,16 @@ impl AssistantEditor {
};
Flex::row()
.with_child(sender)
.with_child(sender.aligned())
.with_child(
Label::new(
message.sent_at.format("%I:%M%P").to_string(),
style.sent_at.text.clone(),
)
.contained()
.with_style(style.sent_at.container)
.aligned(),
)
.aligned()
.left()
.contained()
@ -461,6 +472,7 @@ impl Item for AssistantEditor {
struct Message {
role: Role,
content: ModelHandle<Buffer>,
sent_at: DateTime<Local>,
}
async fn stream_completion(

View File

@ -972,6 +972,7 @@ pub struct TerminalStyle {
pub struct AssistantStyle {
pub container: ContainerStyle,
pub header: ContainerStyle,
pub sent_at: ContainedText,
pub user_sender: ContainedText,
pub assistant_sender: ContainedText,
}

View File

@ -18,6 +18,10 @@ export default function assistant(colorScheme: ColorScheme) {
},
assistant_sender: {
...text(layer, "sans", "accent", { size: "sm", weight: "bold" }),
},
sent_at: {
margin: { top: 2, left: 8 },
...text(layer, "sans", "default", { size: "2xs" }),
}
}
}