[cli] Splits profile.rs into interface and cliclack implementation files (#277)

This commit is contained in:
Jarrod Sibbison
2024-11-19 22:06:51 +11:00
committed by GitHub
parent 00ed82d1ad
commit fa77b1bb1d
5 changed files with 59 additions and 56 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ use crate::session::Session;
use goose::agent::Agent;
use goose::providers::factory;
use crate::prompt::CliclackPrompt;
use crate::prompt::cliclack::CliclackPrompt;
use rand::{distributions::Alphanumeric, Rng};
use crate::commands::expected_config::get_recommended_models;
@@ -5,47 +5,7 @@ use bat::WrappingMode;
use cliclack::{input, spinner};
use goose::models::message::{Message, MessageContent};
pub trait Prompt {
fn render(&mut self, message: Box<Message>);
fn get_input(&mut self) -> Result<Input>;
fn show_busy(&self);
fn hide_busy(&self);
fn close(&self);
fn goose_ready(&self) {
self.draw_goose();
}
fn draw_goose(&self) {
println!(
r#"
__
( 0)>
||
||
__||_
<=/ \=>
\_____/
| |
^ ^
"#
);
}
}
pub struct Input {
pub input_type: InputType,
pub content: Option<String>, // Optional content as sometimes the user may be issuing a command eg. (Exit)
}
pub enum InputType {
Message, // User sent a message
Exit, // User wants to exit the session
}
pub enum Theme {
Light,
Dark,
}
use super::prompt::{Input, InputType, Prompt, Theme};
pub struct CliclackPrompt {
spinner: cliclack::ProgressBar,
@@ -136,18 +96,16 @@ impl Prompt for CliclackPrompt {
for message_content in &message.content {
match message_content {
MessageContent::Text(text) => print(&text.text, theme),
MessageContent::ToolRequest(tool_request) => {
match &tool_request.tool_call {
Ok(call) => {
print_tool_request(
&serde_json::to_string_pretty(&call.arguments).unwrap(),
theme,
&call.name,
);
}
Err(e) => print(&e.to_string(), theme),
MessageContent::ToolRequest(tool_request) => match &tool_request.tool_call {
Ok(call) => {
print_tool_request(
&serde_json::to_string_pretty(&call.arguments).unwrap(),
theme,
&call.name,
);
}
}
Err(e) => print(&e.to_string(), theme),
},
MessageContent::ToolResponse(tool_response) => {
match &tool_response.tool_result {
Ok(output) => {
@@ -166,7 +124,7 @@ impl Prompt for CliclackPrompt {
}
Err(e) => print(&e.to_string(), theme),
}
},
}
MessageContent::Image(image) => {
println!("Image: [data: {}, type: {}]", image.data, image.mime_type);
}
+2
View File
@@ -0,0 +1,2 @@
pub mod cliclack;
pub mod prompt;
+44
View File
@@ -0,0 +1,44 @@
use anyhow::Result;
use goose::models::message::Message;
pub trait Prompt {
fn render(&mut self, message: Box<Message>);
fn get_input(&mut self) -> Result<Input>;
fn show_busy(&self);
fn hide_busy(&self);
fn close(&self);
fn goose_ready(&self) {
self.draw_goose();
}
fn draw_goose(&self) {
println!(
r#"
__
( 0)>
||
||
__||_
<=/ \=>
\_____/
| |
^ ^
"#
);
}
}
pub struct Input {
pub input_type: InputType,
pub content: Option<String>, // Optional content as sometimes the user may be issuing a command eg. (Exit)
}
pub enum InputType {
Message, // User sent a message
Exit, // User wants to exit the session
}
pub enum Theme {
Light,
Dark,
}
+1 -2
View File
@@ -1,8 +1,7 @@
use anyhow::Result;
use futures::StreamExt;
use crate::prompt::InputType;
use crate::prompt::Prompt;
use crate::prompt::prompt::{InputType, Prompt};
use goose::agent::Agent;
use goose::developer::DeveloperSystem;