Explorar el Código

【格式】优化交互模式逻辑

- 添加注释以解释代码流程
- 修改结束会话的条件,增加失败情况
- 优化代码结构,提高可读性
PJ568 hace 1 año
padre
commit
6b65d55b0b
Se han modificado 3 ficheros con 9 adiciones y 3 borrados
  1. 1 1
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 7 1
      src/cli/mod.rs

+ 1 - 1
Cargo.lock

@@ -2449,7 +2449,7 @@ checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51"
 
 [[package]]
 name = "yaa"
-version = "2.14.0"
+version = "2.14.1"
 dependencies = [
  "actix-cors",
  "actix-web",

+ 1 - 1
Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "yaa"
-version = "2.14.0"
+version = "2.14.1"
 edition = "2024"
 
 [dependencies]

+ 7 - 1
src/cli/mod.rs

@@ -17,9 +17,11 @@ pub async fn run_interactive(
     let mut session = session_data.clone();
 
     loop {
+        // 输出提示符
         print!("> ");
         io::stdout().flush()?;
 
+        // 读取用户输入
         let mut input = String::new();
         io::stdin().read_line(&mut input)?;
         let input = input.trim();
@@ -28,21 +30,25 @@ pub async fn run_interactive(
             break;
         }
 
+        // 添加用户消息
         session.messages.push(Message {
             role: crate::core::session::Role::User,
             content: input.to_string(),
         });
 
+        // 处理会话
         let response = process_session(session.clone(), tool_registry, client).await?;
 
+        // 输出响应消息
         for msg in &response.messages {
             println!("【{:?}】\n{}", msg.role, msg.content);
             session.add_message(msg.role.clone(), msg.content.clone());
         }
 
+        // 检查会话是否结束
         if matches!(
             response.finish_reason,
-            FinishReason::Completed | FinishReason::Interrupted
+            FinishReason::Completed | FinishReason::Failed
         ) {
             break;
         }