notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit c3bdde59a96121532c6b800716144c4750e2f0a6
parent d3d6a0c805867adea2ae6c6614d1deeb277ee63f
Author: William Casarin <jb55@jb55.com>
Date:   Tue, 25 Mar 2025 08:15:41 -0700

dave: fix prompt and token concat

Diffstat:
Mcrates/notedeck_dave/src/lib.rs | 29++++++++++++++++++++---------
1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/crates/notedeck_dave/src/lib.rs b/crates/notedeck_dave/src/lib.rs @@ -2,7 +2,8 @@ use async_openai::{ config::OpenAIConfig, types::{ ChatCompletionRequestAssistantMessage, ChatCompletionRequestAssistantMessageContent, - ChatCompletionRequestMessage, ChatCompletionRequestUserMessage, + ChatCompletionRequestMessage, ChatCompletionRequestSystemMessage, + ChatCompletionRequestSystemMessageContent, ChatCompletionRequestUserMessage, ChatCompletionRequestUserMessageContent, CreateChatCompletionRequest, }, Client, @@ -21,6 +22,7 @@ mod avatar; pub enum Message { User(String), Assistant(String), + System(String), } impl Message { @@ -41,6 +43,13 @@ impl Message { ..Default::default() }) } + + Message::System(msg) => { + ChatCompletionRequestMessage::System(ChatCompletionRequestSystemMessage { + content: ChatCompletionRequestSystemMessageContent::Text(msg.clone()), + ..Default::default() + }) + } } } } @@ -74,9 +83,7 @@ impl Dave { incoming_tokens: None, input, chat: vec![ - Message::User("how do I computer".to_string()), - Message::Assistant("Seriously?".to_string()), - Message::User("ye".to_string()), + Message::System("You are an ai agent for the nostr protocol. You have access to tools that can query the network, so you can help find content for users".to_string()), ], } } @@ -85,7 +92,7 @@ impl Dave { if let Some(recvr) = &self.incoming_tokens { if let Ok(token) = recvr.try_recv() { match self.chat.last_mut() { - Some(Message::Assistant(msg)) => *msg = msg.clone() + " " + &token, + Some(Message::Assistant(msg)) => *msg = msg.clone() + &token, Some(_) => self.chat.push(Message::Assistant(token)), None => {} } @@ -118,7 +125,11 @@ impl Dave { for message in &self.chat { match message { Message::User(msg) => self.user_chat(msg, ui), - Message::Assistant(msg) => self.system_chat(msg, ui), + Message::Assistant(msg) => self.assistant_chat(msg, ui), + Message::System(_msg) => { + // system prompt is not rendered. Maybe we could + // have a debug option to show this + } } } } @@ -127,6 +138,7 @@ impl Dave { ui.horizontal(|ui| { ui.add(egui::TextEdit::multiline(&mut self.input)); if ui.button("Sned").clicked() { + self.chat.push(Message::User(self.input.clone())); self.send_user_message(ui.ctx()); self.input.clear(); } @@ -139,8 +151,8 @@ impl Dave { }); } - fn system_chat(&self, msg: &str, ui: &mut egui::Ui) { - ui.with_layout(egui::Layout::left_to_right(egui::Align::TOP), |ui| { + fn assistant_chat(&self, msg: &str, ui: &mut egui::Ui) { + ui.horizontal_wrapped(|ui| { ui.label(msg); }); } @@ -188,7 +200,6 @@ impl Dave { let Some(content) = &choice.delta.content else { return; }; - tracing::debug!("got token: {content}"); tx.send(content.to_owned()).unwrap(); ctx.request_repaint();