Explorar el Código

【修复】命令行交互模式默认配置被覆盖

- 更新 CONTRIBUTING.md,添加环境配置、测试和编译说明
- 修改 Cargo.lock 和 Cargo.toml,更新项目版本号
- 更新 README 文件,添加贡献指南链接
- 重构 API 错误处理,增加 InvalidFormat 错误类型
- 优化 CLI 交互模式,支持从主函数传递 SessionData
PJ568 hace 1 año
padre
commit
cc17197779
Se han modificado 8 ficheros con 36 adiciones y 9 borrados
  1. 18 1
      CONTRIBUTING.md
  2. 1 1
      Cargo.lock
  3. 1 1
      Cargo.toml
  4. 4 0
      README.en.md
  5. 4 0
      README.md
  6. 4 2
      src/agent/api.rs
  7. 3 3
      src/cli/mod.rs
  8. 1 1
      src/main.rs

+ 18 - 1
CONTRIBUTING.md

@@ -16,9 +16,26 @@
 - `智能体(agent)`:智能体核心实现
 - `核心(core)`:基础数据结构与框架
 - `命令行(cli)`:命令行接口
-- `web`:Web接口
+- `web`:Web 接口
 - `工具(agent/tools)`:智能体工具实现
 
+## 环境配置
+
+1. 安装 cargo 和 Rust。
+2. 配置 cargo 镜像源(可选)。
+3. VSCode 配置:
+
+   - 安装 rust-analyzer 扩展。
+
+## 测试
+
+运行 `cargo test` 命令,确保所有测试通过。
+
+## 编译
+
+- 运行 `cargo build` 命令以编译 Debug 版本的二进制文件。
+- 运行 `cargo build --release` 命令以编译更小更快的发行版本的二进制文件。
+
 ## 提交更改
 
 1. Fork 此仓库,在您的仓库新建一个基于此仓库默认分支(branch)的分支。

+ 1 - 1
Cargo.lock

@@ -2433,7 +2433,7 @@ checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51"
 
 [[package]]
 name = "yaa"
-version = "2.0.0"
+version = "2.0.1"
 dependencies = [
  "actix-web",
  "anyhow",

+ 1 - 1
Cargo.toml

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

+ 4 - 0
README.en.md

@@ -48,6 +48,10 @@ cargo run --release
 * Working on it...
 ```
 
+## Contribute
+
+See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
+
 ## Project Implementation
 
 See [yaa documentation](docs/README.md) for details.

+ 4 - 0
README.md

@@ -48,6 +48,10 @@ cargo run --release
 * 好的……
 ```
 
+## 贡献
+
+详见 [CONTRIBUTING.md](CONTRIBUTING.md)。
+
 ## 项目实现
 
 详见 [yaa 文档](docs/README.md)。

+ 4 - 2
src/agent/api.rs

@@ -8,6 +8,8 @@ pub enum ApiError {
     RequestFailed(String),
     #[error("API response parsing failed: {0}")]
     ParseFailed(String),
+    #[error("Invalid API response format: {0}\nRaw response: {1}")]
+    InvalidFormat(String, String),
 }
 
 #[derive(Debug, Serialize, Deserialize)]
@@ -92,11 +94,11 @@ impl OpenAIApi for &OpenAIClient {
             .map_err(|e| ApiError::ParseFailed(e.to_string()))?;
 
         let json: serde_json::Value = serde_json::from_str(&response_text)
-            .map_err(|e| ApiError::ParseFailed(format!("{} - Response: {}", e, response_text)))?;
+            .map_err(|e| ApiError::InvalidFormat(e.to_string(), response_text.clone()))?;
 
         json["choices"][0]["message"]["content"]
             .as_str()
             .map(|s| s.to_string())
-            .ok_or_else(|| ApiError::ParseFailed(format!("Invalid response format - Response: {}", response_text)))
+            .ok_or_else(|| ApiError::InvalidFormat("Missing required fields".to_string(), response_text))
     }
 }

+ 3 - 3
src/cli/mod.rs

@@ -1,16 +1,16 @@
 pub mod commands;
 
-use crate::core::session::{SessionData, Message, FinishReason};
+use crate::core::session::{FinishReason, Message, SessionData};
 use crate::core::tool::ToolRegistry;
 use crate::agent::{process_session, api::OpenAIClient};
 use anyhow::Result;
 use std::io::{self, Write};
 
-pub async fn run_interactive(tool_registry: &ToolRegistry, client: &OpenAIClient) -> Result<()> {
+pub async fn run_interactive(tool_registry: &ToolRegistry, client: &OpenAIClient, session_data: &SessionData) -> Result<()> {
     println!("=== YAA 智能体命令行交互模式 ===");
     println!("输入 '/exit' 退出");
     
-    let mut session = SessionData::default();
+    let mut session = session_data.clone();
     
     loop {
         print!("> ");

+ 1 - 1
src/main.rs

@@ -133,7 +133,7 @@ async fn main() -> std::io::Result<()> {
         if let Some(cmd) = args.command {
             handle_command(cmd).map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
         } else {
-            cli::run_interactive(&tool_registry, &client).await.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
+            cli::run_interactive(&tool_registry, &client, &session_data).await.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
         }
         Ok(())
     }