chore(deps): update rig-core requirement from 0.15.1 to 0.28.0 (#616)
* chore(deps): update rig-core requirement from 0.15.1 to 0.28.0 Updates the requirements on [rig-core](https://github.com/0xPlaygrounds/rig) to permit the latest version. - [Release notes](https://github.com/0xPlaygrounds/rig/releases) - [Commits](https://github.com/0xPlaygrounds/rig/compare/rig-core-v0.15.1...rig-core-v0.28.0) --- updated-dependencies: - dependency-name: rig-core dependency-version: 0.28.0 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> * chore(deps): manual fixes required --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Alex Hancock <alexhancock@block.xyz>
This commit is contained in:
parent
ce559f28e0
commit
69dbd5a3ce
4 changed files with 55 additions and 53 deletions
|
|
@ -13,7 +13,7 @@ readme = { workspace = true }
|
|||
publish = false
|
||||
|
||||
[dependencies]
|
||||
rig-core = "0.15.1"
|
||||
rig-core = "0.28.0"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
rmcp = { workspace = true, features = [
|
||||
"client",
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
use futures::StreamExt;
|
||||
use rig::{
|
||||
agent::Agent,
|
||||
completion::{AssistantContent, CompletionModel},
|
||||
message::Message,
|
||||
streaming::StreamingChat,
|
||||
agent::{Agent, MultiTurnStreamItem},
|
||||
completion::CompletionModel,
|
||||
message::{Message, Text},
|
||||
streaming::{StreamedAssistantContent, StreamingChat},
|
||||
};
|
||||
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader, BufWriter};
|
||||
|
||||
pub async fn cli_chatbot<M>(chatbot: Agent<M>) -> anyhow::Result<()>
|
||||
where
|
||||
M: CompletionModel,
|
||||
M: CompletionModel + 'static,
|
||||
M::StreamingResponse: Send,
|
||||
{
|
||||
let mut chat_log = vec![];
|
||||
|
||||
|
|
@ -28,49 +29,52 @@ where
|
|||
if input == ":q" {
|
||||
break;
|
||||
}
|
||||
match chatbot.stream_chat(input, chat_log.clone()).await {
|
||||
Ok(mut response) => {
|
||||
tracing::info!(%input);
|
||||
chat_log.push(Message::user(input));
|
||||
stream_output_agent_start(&mut output).await?;
|
||||
let mut message_buf = String::new();
|
||||
while let Some(message) = response.next().await {
|
||||
match message {
|
||||
Ok(AssistantContent::Text(text)) => {
|
||||
message_buf.push_str(&text.text);
|
||||
output_agent(text.text, &mut output).await?;
|
||||
}
|
||||
Ok(AssistantContent::ToolCall(tool_call)) => {
|
||||
let name = tool_call.function.name;
|
||||
let arguments = tool_call.function.arguments;
|
||||
chat_log.push(Message::assistant(format!(
|
||||
"Calling tool: {name} with args: {arguments}"
|
||||
)));
|
||||
let result = chatbot.tools.call(&name, arguments.to_string()).await;
|
||||
match result {
|
||||
Ok(tool_call_result) => {
|
||||
stream_output_agent_finished(&mut output).await?;
|
||||
stream_output_toolcall(&tool_call_result, &mut output).await?;
|
||||
stream_output_agent_start(&mut output).await?;
|
||||
chat_log.push(Message::user(tool_call_result));
|
||||
}
|
||||
Err(e) => {
|
||||
output_error(e, &mut output).await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(error) => {
|
||||
output_error(error, &mut output).await?;
|
||||
}
|
||||
}
|
||||
|
||||
tracing::info!(%input);
|
||||
chat_log.push(Message::user(input));
|
||||
|
||||
let mut response = chatbot.stream_chat(input, chat_log.clone()).await;
|
||||
stream_output_agent_start(&mut output).await?;
|
||||
let mut message_buf = String::new();
|
||||
|
||||
while let Some(message) = response.next().await {
|
||||
match message {
|
||||
Ok(MultiTurnStreamItem::StreamAssistantItem(StreamedAssistantContent::Text(
|
||||
Text { text },
|
||||
))) => {
|
||||
message_buf.push_str(&text);
|
||||
output_agent(&text, &mut output).await?;
|
||||
}
|
||||
Ok(MultiTurnStreamItem::StreamAssistantItem(
|
||||
StreamedAssistantContent::ToolCall(tool_call),
|
||||
)) => {
|
||||
let name = &tool_call.function.name;
|
||||
let arguments = &tool_call.function.arguments;
|
||||
stream_output_toolcall(
|
||||
format!("Calling tool: {name} with args: {arguments}"),
|
||||
&mut output,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
Ok(MultiTurnStreamItem::StreamUserItem(user_content)) => {
|
||||
// Tool results are streamed back as user items
|
||||
stream_output_toolcall(format!("Tool result: {:?}", user_content), &mut output)
|
||||
.await?;
|
||||
}
|
||||
Ok(MultiTurnStreamItem::FinalResponse(final_response)) => {
|
||||
tracing::info!("Final response received: {:?}", final_response);
|
||||
}
|
||||
Ok(_) => {
|
||||
// Handle other stream items (reasoning, deltas, etc.)
|
||||
}
|
||||
Err(error) => {
|
||||
output_error(error, &mut output).await?;
|
||||
}
|
||||
chat_log.push(Message::assistant(message_buf));
|
||||
stream_output_agent_finished(&mut output).await?;
|
||||
}
|
||||
Err(error) => {
|
||||
output_error(error, &mut output).await?;
|
||||
}
|
||||
}
|
||||
|
||||
chat_log.push(Message::assistant(message_buf));
|
||||
stream_output_agent_finished(&mut output).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -29,14 +29,14 @@ async fn main() -> anyhow::Result<()> {
|
|||
let config = config::Config::retrieve("config.toml").await?;
|
||||
let deepseek_client = {
|
||||
if let Some(key) = config.deepseek_key {
|
||||
deepseek::Client::new(&key)
|
||||
deepseek::Client::new(&key)?
|
||||
} else {
|
||||
deepseek::Client::from_env()
|
||||
}
|
||||
};
|
||||
let cohere_client = {
|
||||
if let Some(key) = config.cohere_key {
|
||||
cohere::Client::new(&key)
|
||||
cohere::Client::new(&key)?
|
||||
} else {
|
||||
cohere::Client::from_env()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,7 @@ impl RigTool for McpToolAdaptor {
|
|||
fn definition(
|
||||
&self,
|
||||
_prompt: String,
|
||||
) -> std::pin::Pin<Box<dyn Future<Output = rig::completion::ToolDefinition> + Send + Sync + '_>>
|
||||
{
|
||||
) -> std::pin::Pin<Box<dyn Future<Output = rig::completion::ToolDefinition> + Send + '_>> {
|
||||
Box::pin(std::future::ready(rig::completion::ToolDefinition {
|
||||
name: self.name(),
|
||||
description: self
|
||||
|
|
@ -37,9 +36,8 @@ impl RigTool for McpToolAdaptor {
|
|||
fn call(
|
||||
&self,
|
||||
args: String,
|
||||
) -> std::pin::Pin<
|
||||
Box<dyn Future<Output = Result<String, rig::tool::ToolError>> + Send + Sync + '_>,
|
||||
> {
|
||||
) -> std::pin::Pin<Box<dyn Future<Output = Result<String, rig::tool::ToolError>> + Send + '_>>
|
||||
{
|
||||
let server = self.server.clone();
|
||||
Box::pin(async move {
|
||||
let call_mcp_tool_result = server
|
||||
|
|
|
|||
Loading…
Reference in a new issue