mirror of https://github.com/buster-so/buster.git
added in progress on tools
This commit is contained in:
parent
8bd14e0ee7
commit
c849a22b4f
|
@ -4,6 +4,13 @@ use uuid::Uuid;
|
||||||
|
|
||||||
use crate::utils::clients::ai::litellm::Message;
|
use crate::utils::clients::ai::litellm::Message;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
#[serde(untagged)]
|
||||||
|
pub enum BusterThreadMessage {
|
||||||
|
ChatMessage(BusterChatMessage),
|
||||||
|
Thought(BusterThought),
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct BusterChatMessage {
|
pub struct BusterChatMessage {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
@ -13,17 +20,53 @@ pub struct BusterChatMessage {
|
||||||
pub message_chunk: Option<String>,
|
pub message_chunk: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn transform_message(message: Message) -> Result<BusterChatMessage> {
|
#[derive(Debug, Serialize)]
|
||||||
|
pub struct BusterThought {
|
||||||
|
pub id: String,
|
||||||
|
#[serde(rename = "type")]
|
||||||
|
pub thought_type: String,
|
||||||
|
pub thought_title: String,
|
||||||
|
pub thought_secondary_title: String,
|
||||||
|
pub thought_pills: Option<Vec<BusterThoughtPill>>,
|
||||||
|
pub status: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
pub struct BusterThoughtPill {
|
||||||
|
pub id: String,
|
||||||
|
pub text: String,
|
||||||
|
#[serde(rename = "type")]
|
||||||
|
pub thought_file_type: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn transform_message(message: Message) -> Result<BusterThreadMessage> {
|
||||||
match message {
|
match message {
|
||||||
Message::Assistant { id, content, .. } => {
|
Message::Assistant { id, content, .. } => {
|
||||||
let id = id.unwrap_or_else(|| Uuid::new_v4().to_string());
|
let id = id.unwrap_or_else(|| Uuid::new_v4().to_string());
|
||||||
let content = content.ok_or_else(|| anyhow::anyhow!("Missing content"))?;
|
let content = content.ok_or_else(|| anyhow::anyhow!("Missing content"))?;
|
||||||
Ok(BusterChatMessage {
|
Ok(BusterThreadMessage::ChatMessage(BusterChatMessage {
|
||||||
id,
|
id,
|
||||||
message_type: "text".to_string(),
|
message_type: "text".to_string(),
|
||||||
message: None,
|
message: None,
|
||||||
message_chunk: Some(content),
|
message_chunk: Some(content),
|
||||||
})
|
}))
|
||||||
|
}
|
||||||
|
Message::Tool {
|
||||||
|
id,
|
||||||
|
content,
|
||||||
|
tool_call_id,
|
||||||
|
name,
|
||||||
|
progress,
|
||||||
|
} => {
|
||||||
|
tracing::debug!("Tool message: {:?}", message);
|
||||||
|
Ok(BusterThreadMessage::Thought(BusterThought {
|
||||||
|
id,
|
||||||
|
thought_type: "text".to_string(),
|
||||||
|
thought_title: "".to_string(),
|
||||||
|
thought_secondary_title: "".to_string(),
|
||||||
|
thought_pills: None,
|
||||||
|
status: "".to_string(),
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
_ => Err(anyhow::anyhow!("Unsupported message type")),
|
_ => Err(anyhow::anyhow!("Unsupported message type")),
|
||||||
}
|
}
|
||||||
|
@ -57,6 +100,7 @@ mod tests {
|
||||||
content: "content".to_string(),
|
content: "content".to_string(),
|
||||||
tool_call_id: "test".to_string(),
|
tool_call_id: "test".to_string(),
|
||||||
name: None,
|
name: None,
|
||||||
|
progress: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = transform_message(message);
|
let result = transform_message(message);
|
||||||
|
|
|
@ -183,7 +183,7 @@ impl Agent {
|
||||||
if let Some(tool) = self.tools.get(&tool_call.function.name) {
|
if let Some(tool) = self.tools.get(&tool_call.function.name) {
|
||||||
let result = tool.execute(tool_call).await?;
|
let result = tool.execute(tool_call).await?;
|
||||||
let result_str = serde_json::to_string(&result)?;
|
let result_str = serde_json::to_string(&result)?;
|
||||||
results.push(Message::tool(result_str, tool_call.id.clone()));
|
results.push(Message::tool(result_str, tool_call.id.clone(), None));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,6 +375,7 @@ impl Agent {
|
||||||
let tool_result = Message::tool(
|
let tool_result = Message::tool(
|
||||||
result_str,
|
result_str,
|
||||||
tool_call.id.clone(),
|
tool_call.id.clone(),
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
let _ = tx.send(Ok(tool_result.clone())).await;
|
let _ = tx.send(Ok(tool_result.clone())).await;
|
||||||
|
|
||||||
|
@ -388,6 +389,7 @@ impl Agent {
|
||||||
let tool_error = Message::tool(
|
let tool_error = Message::tool(
|
||||||
error_msg,
|
error_msg,
|
||||||
tool_call.id.clone(),
|
tool_call.id.clone(),
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
let _ = tx.send(Ok(tool_error.clone())).await;
|
let _ = tx.send(Ok(tool_error.clone())).await;
|
||||||
|
|
||||||
|
|
|
@ -130,6 +130,8 @@ pub enum Message {
|
||||||
tool_call_id: String,
|
tool_call_id: String,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
name: Option<String>,
|
name: Option<String>,
|
||||||
|
#[serde(skip)]
|
||||||
|
progress: Option<MessageProgress>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,16 +164,21 @@ impl Message {
|
||||||
content,
|
content,
|
||||||
name: None,
|
name: None,
|
||||||
tool_calls,
|
tool_calls,
|
||||||
progress: None,
|
progress,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tool(content: impl Into<String>, tool_call_id: impl Into<String>) -> Self {
|
pub fn tool(
|
||||||
|
content: impl Into<String>,
|
||||||
|
tool_call_id: impl Into<String>,
|
||||||
|
progress: Option<MessageProgress>,
|
||||||
|
) -> Self {
|
||||||
Self::Tool {
|
Self::Tool {
|
||||||
id: None,
|
id: None,
|
||||||
content: content.into(),
|
content: content.into(),
|
||||||
tool_call_id: tool_call_id.into(),
|
tool_call_id: tool_call_id.into(),
|
||||||
name: None,
|
name: None,
|
||||||
|
progress,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue