ui: split out the app struct into a new ui mod
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use async_openai::types::chat::{ChatCompletionRequestAssistantMessage, ChatCompletionRequestAssistantMessageContent, ChatCompletionRequestMessage, ChatCompletionRequestSystemMessage, ChatCompletionRequestSystemMessageContent, ChatCompletionRequestUserMessage, ChatCompletionRequestUserMessageContent};
|
||||
use ratatui::style::{self, Style};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@@ -11,6 +12,47 @@ pub enum ConversationEntry {
|
||||
SystemMessage(String)
|
||||
}
|
||||
|
||||
impl ConversationEntry {
|
||||
pub fn prefix(&self) -> Option<&str> {
|
||||
match self {
|
||||
ConversationEntry::Eva(_) => Some("Eva: "),
|
||||
ConversationEntry::User(_) => Some("Argee: "),
|
||||
ConversationEntry::ShipComputer(_) => Some("Ship Computer: "),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prefix_style(&self) -> Style {
|
||||
match self {
|
||||
ConversationEntry::Eva(_) => Style::new().fg(style::Color::Cyan),
|
||||
ConversationEntry::User(_) => Style::new().fg(style::Color::Magenta),
|
||||
ConversationEntry::ShipComputer(_) => Style::new().fg(style::Color::Green),
|
||||
ConversationEntry::StageDirection(_) => Style::new().fg(style::Color::Yellow),
|
||||
ConversationEntry::SystemMessage(_) => Style::new().fg(style::Color::DarkGray),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn text_style(&self) -> Style {
|
||||
match self {
|
||||
ConversationEntry::StageDirection(_) => Style::new().fg(style::Color::Yellow),
|
||||
ConversationEntry::SystemMessage(_) => Style::new().fg(style::Color::DarkGray),
|
||||
_ => Style::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToString for ConversationEntry {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
ConversationEntry::Eva(text) => text,
|
||||
ConversationEntry::ShipComputer(text) => text,
|
||||
ConversationEntry::StageDirection(text) => text,
|
||||
ConversationEntry::SystemMessage(text) => text,
|
||||
ConversationEntry::User(text) => text
|
||||
}.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryInto<ChatCompletionRequestMessage> for ConversationEntry {
|
||||
fn try_into(self) -> Result<ChatCompletionRequestMessage, Self::Error> {
|
||||
match self {
|
||||
|
||||
+5
-1
@@ -39,7 +39,7 @@ pub struct Scenery {
|
||||
pub struct Scene {
|
||||
reply_options: GeneratedResponses,
|
||||
conversation: Vec<ConversationEntry>,
|
||||
pub direction: StageDirection,
|
||||
direction: StageDirection,
|
||||
pub tokens_consumed: usize,
|
||||
scenery: Scenery
|
||||
}
|
||||
@@ -55,6 +55,10 @@ impl Scene {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn direction(&self) -> &StageDirection {
|
||||
&self.direction
|
||||
}
|
||||
|
||||
pub fn scenery(&self) -> &Scenery {
|
||||
&self.scenery
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user