|
@@ -1,45 +1,52 @@
|
|
|
pub mod commands;
|
|
pub mod commands;
|
|
|
|
|
|
|
|
|
|
+use crate::agent::{api::OpenAIClient, process_session};
|
|
|
use crate::core::session::{FinishReason, Message, SessionData};
|
|
use crate::core::session::{FinishReason, Message, SessionData};
|
|
|
use crate::core::tool::ToolRegistry;
|
|
use crate::core::tool::ToolRegistry;
|
|
|
-use crate::agent::{process_session, api::OpenAIClient};
|
|
|
|
|
use anyhow::Result;
|
|
use anyhow::Result;
|
|
|
use std::io::{self, Write};
|
|
use std::io::{self, Write};
|
|
|
|
|
|
|
|
-pub async fn run_interactive(tool_registry: &ToolRegistry, client: &OpenAIClient, session_data: &SessionData) -> Result<()> {
|
|
|
|
|
|
|
+pub async fn run_interactive(
|
|
|
|
|
+ tool_registry: &ToolRegistry,
|
|
|
|
|
+ client: &OpenAIClient,
|
|
|
|
|
+ session_data: &SessionData,
|
|
|
|
|
+) -> Result<()> {
|
|
|
println!("=== YAA 智能体命令行交互模式 ===");
|
|
println!("=== YAA 智能体命令行交互模式 ===");
|
|
|
println!("输入 '/exit' 退出");
|
|
println!("输入 '/exit' 退出");
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
let mut session = session_data.clone();
|
|
let mut session = session_data.clone();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
loop {
|
|
loop {
|
|
|
print!("> ");
|
|
print!("> ");
|
|
|
io::stdout().flush()?;
|
|
io::stdout().flush()?;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
let mut input = String::new();
|
|
let mut input = String::new();
|
|
|
io::stdin().read_line(&mut input)?;
|
|
io::stdin().read_line(&mut input)?;
|
|
|
let input = input.trim();
|
|
let input = input.trim();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if input.eq_ignore_ascii_case("/exit") {
|
|
if input.eq_ignore_ascii_case("/exit") {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
session.messages.push(Message {
|
|
session.messages.push(Message {
|
|
|
role: crate::core::session::Role::User,
|
|
role: crate::core::session::Role::User,
|
|
|
content: input.to_string(),
|
|
content: input.to_string(),
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
let response = process_session(session.clone(), tool_registry, client).await?;
|
|
let response = process_session(session.clone(), tool_registry, client).await?;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
for msg in &response.messages {
|
|
for msg in &response.messages {
|
|
|
println!("【{:?}】\n{}", msg.role, msg.content);
|
|
println!("【{:?}】\n{}", msg.role, msg.content);
|
|
|
session.add_message(msg.role.clone(), msg.content.clone());
|
|
session.add_message(msg.role.clone(), msg.content.clone());
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- if matches!(response.finish_reason, FinishReason::Completed | FinishReason::Interrupted) {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if matches!(
|
|
|
|
|
+ response.finish_reason,
|
|
|
|
|
+ FinishReason::Completed | FinishReason::Interrupted
|
|
|
|
|
+ ) {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
Ok(())
|
|
Ok(())
|
|
|
-}
|
|
|
|
|
|
|
+}
|