feat: simplify initial session splash (#362)

This commit is contained in:
Bradley Axen
2024-11-27 15:52:26 -08:00
committed by GitHub
parent 9f60e310d9
commit 4fa9c2ad3d
8 changed files with 30 additions and 96 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ pub struct MockAgent;
#[async_trait]
impl Agent for MockAgent {
fn add_system(&mut self, _system: Box<dyn System>) {
()
}
async fn reply(&self, _messages: &[Message]) -> Result<BoxStream<'_, Result<Message>>> {
+15 -14
View File
@@ -1,8 +1,8 @@
use console::style;
use rand::{distributions::Alphanumeric, Rng};
use std::path::{Path, PathBuf};
use goose::agent::Agent;
use goose::models::message::Message;
use goose::providers::factory;
use crate::commands::expected_config::get_recommended_models;
@@ -11,7 +11,6 @@ use crate::profile::{
};
use crate::prompt::cliclack::CliclackPrompt;
use crate::prompt::rustyline::RustylinePrompt;
use crate::prompt::thinking::get_random_goose_action;
use crate::prompt::Prompt;
use crate::session::{ensure_session_dir, Session};
@@ -48,7 +47,7 @@ pub fn build_session<'a>(
// TODO: Odd to be prepping the provider rather than having that done in the agent?
let provider = factory::get_provider(provider_config).unwrap();
let agent = Box::new(Agent::new(provider));
let mut prompt = match std::env::var("GOOSE_INPUT") {
let prompt = match std::env::var("GOOSE_INPUT") {
Ok(val) => match val.as_str() {
"cliclack" => Box::new(CliclackPrompt::new()) as Box<dyn Prompt>,
"rustyline" => Box::new(RustylinePrompt::new()) as Box<dyn Prompt>,
@@ -57,17 +56,19 @@ pub fn build_session<'a>(
Err(_) => Box::new(RustylinePrompt::new()),
};
prompt.render(Box::new(Message::assistant().with_text(format!(
r#"{}...
Provider: {}
Model: {}
Session file: {}"#,
get_random_goose_action(),
loaded_profile.provider,
loaded_profile.model,
session_file.display()
))));
println!(
"{} {} {} {} {}",
style("starting session |").dim(),
style("provider:").dim(),
style(loaded_profile.provider).cyan().dim(),
style("model:").dim(),
style(loaded_profile.model).cyan().dim(),
);
println!(
" {} {}",
style("logging to").dim(),
style(session_file.display()).dim().cyan(),
);
Box::new(Session::new(agent, prompt, session_file))
}
+3 -16
View File
@@ -12,22 +12,9 @@ pub trait Prompt {
fn hide_busy(&self);
fn close(&self);
fn goose_ready(&self) {
self.draw_goose();
}
fn draw_goose(&self) {
println!(
r#" __ - - - -
( 0)> < honk! >
|| - - - -
||
__||_
<=/ \=>
\_____/
| |
^ ^
"#
);
println!("\n");
println!("Goose is running! Enter your instructions, or try asking what goose can do.");
println!("\n");
}
}
-52
View File
@@ -1,50 +1,5 @@
use rand::seq::SliceRandom;
/// List of goose-specific actions for noting goose readiness.
pub const GOOSE_ACTIONS: &[&str] = &[
"Spreading wings",
"Honking thoughtfully",
"Waddling to conclusions",
"Flapping wings excitedly",
"Preening code feathers",
"Gathering digital breadcrumbs",
"Paddling through data",
"Migrating thoughts",
"Nesting ideas",
"Squawking calculations",
"Ruffling algorithmic feathers",
"Pecking at problems",
"Stretching webbed feet",
"Foraging for solutions",
"Grooming syntax",
"Building digital nest",
"Patrolling the codebase",
"Gosling about",
"Strutting with purpose",
"Diving for answers",
"Herding bytes",
"Molting old code",
"Swimming through streams",
"Goose-stepping through logic",
"Synchronizing flock algorithms",
"Navigating code marshes",
"Incubating brilliant ideas",
"Arranging feathers recursively",
"Gliding through branches",
"Migrating to better solutions",
"Nesting functions carefully",
"Hatching clever solutions",
"Preening parse trees",
"Flying through functions",
"Gathering syntax seeds",
"Webbing connections",
"Flocking to optimizations",
"Paddling through protocols",
"Honking success signals",
"Waddling through workflows",
"Nesting in neural networks",
];
/// Extended list of playful thinking messages including both goose and general AI actions
pub const THINKING_MESSAGES: &[&str] = &[
"Thinking",
@@ -268,10 +223,3 @@ pub fn get_random_thinking_message() -> &'static str {
.choose(&mut rand::thread_rng())
.unwrap_or(&THINKING_MESSAGES[0])
}
/// Returns a random goose-specific action
pub fn get_random_goose_action() -> &'static str {
GOOSE_ACTIONS
.choose(&mut rand::thread_rng())
.unwrap_or(&GOOSE_ACTIONS[0])
}
+1 -6
View File
@@ -99,6 +99,7 @@ impl<'a> Session<'a> {
pub async fn start(&mut self) -> Result<(), Box<dyn std::error::Error>> {
self.setup_session();
self.prompt.goose_ready();
loop {
let input = self.prompt.get_input().unwrap();
@@ -202,14 +203,8 @@ impl<'a> Session<'a> {
fn setup_session(&mut self) {
let system = Box::new(DeveloperSystem::new());
self.agent.add_system(system);
self.prompt
.render(raw_message("Connected developer system."));
let goosehints_system = Box::new(GooseHintsSystem::new());
self.agent.add_system(goosehints_system);
self.prompt
.render(raw_message("Connected .goosehints system."));
self.prompt.goose_ready();
}
fn close_session(&mut self) {
+2 -3
View File
@@ -139,7 +139,6 @@ fn convert_messages(incoming: Vec<IncomingMessage>) -> Vec<Message> {
struct ProtocolFormatter;
impl ProtocolFormatter {
fn format_text(text: &str) -> String {
let encoded_text = serde_json::to_string(text).unwrap_or_else(|_| String::new());
format!("0:{}\n", encoded_text)
@@ -236,8 +235,8 @@ async fn stream_message(
MessageContent::Text(text) => {
for line in text.text.lines() {
let modified_line = format!("{}\n", line);
tx.send(ProtocolFormatter::format_text(&modified_line)).await?;
tx.send(ProtocolFormatter::format_text(&modified_line))
.await?;
}
}
MessageContent::Image(_) => {
+7 -3
View File
@@ -111,7 +111,6 @@ impl MemoryManager {
if let Some(first_line) = lines.next() {
if first_line.starts_with('#') {
let tags = first_line[1..]
.trim()
.split_whitespace()
.map(String::from)
.collect::<Vec<_>>();
@@ -236,8 +235,7 @@ pub fn execute_tool_call(tool_call: ToolCall) -> Result<String, io::Error> {
.map(|v| v.as_str().unwrap())
.collect();
let is_global = tool_call.arguments["is_global"].as_bool().unwrap();
let _result =
MemoryManager::new()?.remember("context", category, data, &tags, is_global)?;
MemoryManager::new()?.remember("context", category, data, &tags, is_global)?;
Ok(format!("Stored memory in category: {}", category))
}
"retrieve_memories" => {
@@ -274,6 +272,12 @@ pub struct MemorySystem {
instructions: String,
}
impl Default for MemorySystem {
fn default() -> Self {
Self::new()
}
}
impl MemorySystem {
pub fn new() -> Self {
let memory_manager = MemoryManager::new().expect("Failed to create MemoryManager");
+1 -1
View File
@@ -40,7 +40,7 @@ impl TokenCache {
let hash = format!("{:x}", hasher.finalize());
fs::create_dir_all(get_base_path()).unwrap();
let cache_path = PathBuf::from(get_base_path()).join(format!("{}.json", hash));
let cache_path = get_base_path().join(format!("{}.json", hash));
Self { cache_path }
}