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
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rig-core = "0.15.1"
|
rig-core = "0.28.0"
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
rmcp = { workspace = true, features = [
|
rmcp = { workspace = true, features = [
|
||||||
"client",
|
"client",
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use rig::{
|
use rig::{
|
||||||
agent::Agent,
|
agent::{Agent, MultiTurnStreamItem},
|
||||||
completion::{AssistantContent, CompletionModel},
|
completion::CompletionModel,
|
||||||
message::Message,
|
message::{Message, Text},
|
||||||
streaming::StreamingChat,
|
streaming::{StreamedAssistantContent, StreamingChat},
|
||||||
};
|
};
|
||||||
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader, BufWriter};
|
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader, BufWriter};
|
||||||
|
|
||||||
pub async fn cli_chatbot<M>(chatbot: Agent<M>) -> anyhow::Result<()>
|
pub async fn cli_chatbot<M>(chatbot: Agent<M>) -> anyhow::Result<()>
|
||||||
where
|
where
|
||||||
M: CompletionModel,
|
M: CompletionModel + 'static,
|
||||||
|
M::StreamingResponse: Send,
|
||||||
{
|
{
|
||||||
let mut chat_log = vec![];
|
let mut chat_log = vec![];
|
||||||
|
|
||||||
|
|
@ -28,49 +29,52 @@ where
|
||||||
if input == ":q" {
|
if input == ":q" {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
match chatbot.stream_chat(input, chat_log.clone()).await {
|
|
||||||
Ok(mut response) => {
|
tracing::info!(%input);
|
||||||
tracing::info!(%input);
|
chat_log.push(Message::user(input));
|
||||||
chat_log.push(Message::user(input));
|
|
||||||
stream_output_agent_start(&mut output).await?;
|
let mut response = chatbot.stream_chat(input, chat_log.clone()).await;
|
||||||
let mut message_buf = String::new();
|
stream_output_agent_start(&mut output).await?;
|
||||||
while let Some(message) = response.next().await {
|
let mut message_buf = String::new();
|
||||||
match message {
|
|
||||||
Ok(AssistantContent::Text(text)) => {
|
while let Some(message) = response.next().await {
|
||||||
message_buf.push_str(&text.text);
|
match message {
|
||||||
output_agent(text.text, &mut output).await?;
|
Ok(MultiTurnStreamItem::StreamAssistantItem(StreamedAssistantContent::Text(
|
||||||
}
|
Text { text },
|
||||||
Ok(AssistantContent::ToolCall(tool_call)) => {
|
))) => {
|
||||||
let name = tool_call.function.name;
|
message_buf.push_str(&text);
|
||||||
let arguments = tool_call.function.arguments;
|
output_agent(&text, &mut output).await?;
|
||||||
chat_log.push(Message::assistant(format!(
|
}
|
||||||
"Calling tool: {name} with args: {arguments}"
|
Ok(MultiTurnStreamItem::StreamAssistantItem(
|
||||||
)));
|
StreamedAssistantContent::ToolCall(tool_call),
|
||||||
let result = chatbot.tools.call(&name, arguments.to_string()).await;
|
)) => {
|
||||||
match result {
|
let name = &tool_call.function.name;
|
||||||
Ok(tool_call_result) => {
|
let arguments = &tool_call.function.arguments;
|
||||||
stream_output_agent_finished(&mut output).await?;
|
stream_output_toolcall(
|
||||||
stream_output_toolcall(&tool_call_result, &mut output).await?;
|
format!("Calling tool: {name} with args: {arguments}"),
|
||||||
stream_output_agent_start(&mut output).await?;
|
&mut output,
|
||||||
chat_log.push(Message::user(tool_call_result));
|
)
|
||||||
}
|
.await?;
|
||||||
Err(e) => {
|
}
|
||||||
output_error(e, &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?;
|
||||||
Err(error) => {
|
}
|
||||||
output_error(error, &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(())
|
Ok(())
|
||||||
|
|
|
||||||
|
|
@ -29,14 +29,14 @@ async fn main() -> anyhow::Result<()> {
|
||||||
let config = config::Config::retrieve("config.toml").await?;
|
let config = config::Config::retrieve("config.toml").await?;
|
||||||
let deepseek_client = {
|
let deepseek_client = {
|
||||||
if let Some(key) = config.deepseek_key {
|
if let Some(key) = config.deepseek_key {
|
||||||
deepseek::Client::new(&key)
|
deepseek::Client::new(&key)?
|
||||||
} else {
|
} else {
|
||||||
deepseek::Client::from_env()
|
deepseek::Client::from_env()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let cohere_client = {
|
let cohere_client = {
|
||||||
if let Some(key) = config.cohere_key {
|
if let Some(key) = config.cohere_key {
|
||||||
cohere::Client::new(&key)
|
cohere::Client::new(&key)?
|
||||||
} else {
|
} else {
|
||||||
cohere::Client::from_env()
|
cohere::Client::from_env()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,7 @@ impl RigTool for McpToolAdaptor {
|
||||||
fn definition(
|
fn definition(
|
||||||
&self,
|
&self,
|
||||||
_prompt: String,
|
_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 {
|
Box::pin(std::future::ready(rig::completion::ToolDefinition {
|
||||||
name: self.name(),
|
name: self.name(),
|
||||||
description: self
|
description: self
|
||||||
|
|
@ -37,9 +36,8 @@ impl RigTool for McpToolAdaptor {
|
||||||
fn call(
|
fn call(
|
||||||
&self,
|
&self,
|
||||||
args: String,
|
args: String,
|
||||||
) -> std::pin::Pin<
|
) -> std::pin::Pin<Box<dyn Future<Output = Result<String, rig::tool::ToolError>> + Send + '_>>
|
||||||
Box<dyn Future<Output = Result<String, rig::tool::ToolError>> + Send + Sync + '_>,
|
{
|
||||||
> {
|
|
||||||
let server = self.server.clone();
|
let server = self.server.clone();
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let call_mcp_tool_result = server
|
let call_mcp_tool_result = server
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue