Compare commits

...

1 Commits

Author SHA1 Message Date
Bennet Bo Fenner
100ad7601d WIP 2025-04-24 15:15:26 +02:00
5 changed files with 73 additions and 0 deletions

View File

@@ -1103,7 +1103,10 @@ impl Thread {
self.tool_use
.attach_tool_uses(message.id, &mut request_message);
// Skip empty messages to avoid sending them to the LLM model
// if !request_message.content.is_empty() {
request.messages.push(request_message);
// }
}
// https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching
@@ -1723,8 +1726,10 @@ impl Thread {
cx: &mut Context<Self>,
) {
if self.all_tools_finished() {
dbg!("All tools finished");
let model_registry = LanguageModelRegistry::read_global(cx);
if let Some(ConfiguredModel { model, .. }) = model_registry.default_model() {
dbg!("Attach tool results");
self.attach_tool_results(cx);
if !canceled {
self.send_to_model(model, window, cx);
@@ -1732,6 +1737,7 @@ impl Thread {
}
}
println!("ToolFinished {}", tool_use_id);
cx.emit(ThreadEvent::ToolFinished {
tool_use_id,
pending_tool_use,

View File

@@ -450,6 +450,7 @@ impl ToolUseState {
message_id: MessageId,
request_message: &mut LanguageModelRequestMessage,
) {
dbg!(&self.tool_uses_by_assistant_message, &message_id);
if let Some(tool_uses) = self.tool_uses_by_assistant_message.get(&message_id) {
for tool_use in tool_uses {
if self.tool_results.contains_key(&tool_use.id) {
@@ -472,6 +473,7 @@ impl ToolUseState {
message_id: MessageId,
request_message: &mut LanguageModelRequestMessage,
) {
dbg!(&self.tool_uses_by_user_message, &message_id);
if let Some(tool_uses) = self.tool_uses_by_user_message.get(&message_id) {
for tool_use_id in tool_uses {
if let Some(tool_result) = self.tool_results.get(tool_use_id) {

View File

@@ -59,6 +59,7 @@ use crate::thinking_tool::ThinkingTool;
pub use create_file_tool::CreateFileToolInput;
pub use edit_file_tool::EditFileToolInput;
pub use find_path_tool::FindPathToolInput;
pub use list_directory_tool::ListDirectoryToolInput;
pub use read_file_tool::ReadFileToolInput;
pub fn init(http_client: Arc<HttpClientWithUrl>, cx: &mut App) {

View File

@@ -13,11 +13,13 @@ use crate::example::{Example, ExampleContext, ExampleMetadata, JudgeAssertion};
mod add_arg_to_trait_method;
mod file_search;
mod no_empty_messages;
pub fn all(examples_dir: &Path) -> Vec<Rc<dyn Example>> {
let mut threads: Vec<Rc<dyn Example>> = vec![
Rc::new(file_search::FileSearchExample),
Rc::new(add_arg_to_trait_method::AddArgToTraitMethod),
Rc::new(no_empty_messages::NoEmptyMessagesExample),
];
for example_path in list_declarative_examples(examples_dir).unwrap() {

View File

@@ -0,0 +1,62 @@
use anyhow::Result;
use assistant_tools::{ListDirectoryToolInput, ReadFileToolInput};
use async_trait::async_trait;
use crate::example::{Example, ExampleContext, ExampleMetadata};
pub struct NoEmptyMessagesExample;
#[async_trait(?Send)]
impl Example for NoEmptyMessagesExample {
fn meta(&self) -> ExampleMetadata {
ExampleMetadata {
name: "no_empty_messages".to_string(),
url: "https://github.com/zed-industries/zed.git".to_string(),
revision: "fcfeea4825c563715bcd1a1af809d88a37d12ccb".to_string(),
language_server: None,
max_assertions: Some(3),
}
}
async fn conversation(&self, cx: &mut ExampleContext) -> Result<()> {
cx.push_user_message(format!(
r#"
Summarize all the files in crates/assistant/src.
Do tool calls only and do NOT include a description of what you are doing.
Just give me an explanation of what you did after you finished all tool calls
"#
));
let response = cx.run_turn().await?;
dbg!(response);
// let tool_use = response.expect_tool("list_directory", cx)?;
// let input = tool_use.parse_input::<ListDirectoryToolInput>()?;
// cx.assert(
// &input.path == "zed/crates/assistant/src",
// "Path matches directory",
// )?;
for file in [
"assistant.rs",
"assistant_configuration.rs",
"assistant_panel.rs",
"inline_assistant.rs",
"slash_command_settings.rs",
"terminal_inline_assistant.rs",
] {
let response = cx.run_turn().await?;
dbg!(response);
// let tool_use = response.expect_tool("read_file", cx)?;
// let input = tool_use.parse_input::<ReadFileToolInput>()?;
// dbg!(&input);
// cx.assert(
// input.path == format!("zed/crates/assistant/src/{file}"),
// format!("Path {} matches file {file}", input.path),
// )?;
}
cx.run_to_end().await?;
Ok(())
}
}