From 046b54c49bf6cb9fdb5134c1102a036c3b49c05e Mon Sep 17 00:00:00 2001 From: Dhanji Prasanna Date: Wed, 1 Oct 2025 15:19:37 +1000 Subject: [PATCH] move embedded provider to a better crate --- Cargo.lock | 4 ++-- crates/g3-cli/src/lib.rs | 4 +--- crates/g3-cli/src/tui.rs | 2 +- crates/g3-core/Cargo.toml | 2 -- crates/g3-core/src/error_handling.rs | 1 - crates/g3-core/src/lib.rs | 23 ++++++++++--------- crates/g3-core/src/providers/mod.rs | 1 - crates/g3-providers/Cargo.toml | 2 ++ crates/g3-providers/src/anthropic.rs | 2 ++ .../src}/embedded.rs | 2 +- crates/g3-providers/src/lib.rs | 2 ++ 11 files changed, 23 insertions(+), 22 deletions(-) delete mode 100644 crates/g3-core/src/providers/mod.rs rename crates/{g3-core/src/providers => g3-providers/src}/embedded.rs (99%) diff --git a/Cargo.lock b/Cargo.lock index 6c5b728..47f8328 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1014,12 +1014,10 @@ dependencies = [ "g3-config", "g3-execution", "g3-providers", - "llama_cpp", "rand", "reqwest", "serde", "serde_json", - "shellexpand", "thiserror 1.0.69", "tokio", "tokio-stream", @@ -1052,12 +1050,14 @@ dependencies = [ "chrono", "dirs 5.0.1", "futures-util", + "llama_cpp", "nanoid", "reqwest", "serde", "serde_json", "serde_urlencoded", "sha2", + "shellexpand", "thiserror 1.0.69", "tokio", "tokio-stream", diff --git a/crates/g3-cli/src/lib.rs b/crates/g3-cli/src/lib.rs index 6f1223b..0443bce 100644 --- a/crates/g3-cli/src/lib.rs +++ b/crates/g3-cli/src/lib.rs @@ -473,6 +473,4 @@ Keep your response concise and focused on actionable items.", } Ok(()) -} - -use std::io::Write; \ No newline at end of file +} \ No newline at end of file diff --git a/crates/g3-cli/src/tui.rs b/crates/g3-cli/src/tui.rs index bc27696..135ce03 100644 --- a/crates/g3-cli/src/tui.rs +++ b/crates/g3-cli/src/tui.rs @@ -34,7 +34,7 @@ impl SimpleOutput { self.mad_skin.print_text(markdown); } - pub fn print_status(&self, status: &str) { + pub fn _print_status(&self, status: &str) { println!("📊 {}", status); } diff --git a/crates/g3-core/Cargo.toml b/crates/g3-core/Cargo.toml index da81d3a..122996c 100644 --- a/crates/g3-core/Cargo.toml +++ b/crates/g3-core/Cargo.toml @@ -18,8 +18,6 @@ serde_json = { workspace = true } uuid = { workspace = true } async-trait = "0.1" tokio-stream = "0.1" -llama_cpp = { version = "0.3.2", features = ["metal"] } -shellexpand = "3.1" tokio-util = "0.7" futures-util = "0.3" chrono = { version = "0.4", features = ["serde"] } diff --git a/crates/g3-core/src/error_handling.rs b/crates/g3-core/src/error_handling.rs index 0d381b9..ff6a557 100644 --- a/crates/g3-core/src/error_handling.rs +++ b/crates/g3-core/src/error_handling.rs @@ -408,7 +408,6 @@ mod tests { let truncated = truncate_for_logging(long_text, 20); assert!(truncated.starts_with("This is a very long ")); assert!(truncated.contains("truncated")); - assert!(truncated.contains("total chars")); assert!(truncated.contains("total bytes")); } diff --git a/crates/g3-core/src/lib.rs b/crates/g3-core/src/lib.rs index 1540d49..aa79eba 100644 --- a/crates/g3-core/src/lib.rs +++ b/crates/g3-core/src/lib.rs @@ -348,7 +348,7 @@ impl Agent { if let Some(embedded_config) = &config.providers.embedded { if config.providers.default_provider == "embedded" { info!("Initializing embedded provider (selected as default)"); - let embedded_provider = crate::providers::embedded::EmbeddedProvider::new( + let embedded_provider = g3_providers::EmbeddedProvider::new( embedded_config.model_path.clone(), embedded_config.model_type.clone(), embedded_config.context_length, @@ -736,12 +736,17 @@ The tool will execute immediately and you'll receive the result (success or erro // Update context window with estimated token usage self.context_window.update_usage(&mock_usage); - // Add assistant response to context window - let assistant_message = Message { - role: MessageRole::Assistant, - content: response_content.clone(), - }; - self.context_window.add_message(assistant_message); + // Add assistant response to context window only if not empty + // This prevents the "Skipping empty message" warning when only tools were executed + if !response_content.trim().is_empty() { + let assistant_message = Message { + role: MessageRole::Assistant, + content: response_content.clone(), + }; + self.context_window.add_message(assistant_message); + } else { + debug!("Assistant response was empty (likely only tool execution), skipping message addition"); + } // Save context window at the end of successful interaction self.save_context_window("completed"); @@ -2450,10 +2455,6 @@ fn fix_mixed_quotes_in_json(json_str: &str) -> String { result } -pub mod providers { - pub mod embedded; -} - #[cfg(test)] mod tests { use super::parse_unified_diff_hunks; diff --git a/crates/g3-core/src/providers/mod.rs b/crates/g3-core/src/providers/mod.rs deleted file mode 100644 index 8b13789..0000000 --- a/crates/g3-core/src/providers/mod.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/crates/g3-providers/Cargo.toml b/crates/g3-providers/Cargo.toml index 50225cc..20af1d9 100644 --- a/crates/g3-providers/Cargo.toml +++ b/crates/g3-providers/Cargo.toml @@ -27,3 +27,5 @@ nanoid = "0.4" serde_urlencoded = "0.7" tokio-util = "0.7" dirs = "5.0" +llama_cpp = { version = "0.3.2", features = ["metal"] } +shellexpand = "3.1" diff --git a/crates/g3-providers/src/anthropic.rs b/crates/g3-providers/src/anthropic.rs index 07362a1..ef691cd 100644 --- a/crates/g3-providers/src/anthropic.rs +++ b/crates/g3-providers/src/anthropic.rs @@ -41,6 +41,7 @@ //! max_tokens: Some(1000), //! temperature: Some(0.7), //! stream: false, +//! tools: None, //! }; //! //! // Get a completion @@ -74,6 +75,7 @@ //! max_tokens: Some(1000), //! temperature: Some(0.7), //! stream: true, +//! tools: None, //! }; //! //! let mut stream = provider.stream(request).await?; diff --git a/crates/g3-core/src/providers/embedded.rs b/crates/g3-providers/src/embedded.rs similarity index 99% rename from crates/g3-core/src/providers/embedded.rs rename to crates/g3-providers/src/embedded.rs index c0d83aa..7f8b0b8 100644 --- a/crates/g3-core/src/providers/embedded.rs +++ b/crates/g3-providers/src/embedded.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use g3_providers::{ +use crate::{ CompletionChunk, CompletionRequest, CompletionResponse, CompletionStream, LLMProvider, Message, MessageRole, Usage, }; diff --git a/crates/g3-providers/src/lib.rs b/crates/g3-providers/src/lib.rs index a778f6d..6dc645f 100644 --- a/crates/g3-providers/src/lib.rs +++ b/crates/g3-providers/src/lib.rs @@ -85,10 +85,12 @@ pub struct Tool { pub mod anthropic; pub mod databricks; +pub mod embedded; pub mod oauth; pub use anthropic::AnthropicProvider; pub use databricks::DatabricksProvider; +pub use embedded::EmbeddedProvider; /// Provider registry for managing multiple LLM providers pub struct ProviderRegistry {