diff options
| author | sigoden <sigoden@gmail.com> | 2024-06-17 09:14:54 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-17 09:14:54 +0800 |
| commit | 638bf3276613265da761b4d74f269fa77c8f4bb1 (patch) | |
| tree | 9667711b92bc3664ad72c179cfe1cf4bbf54d322 /src/function.rs | |
| parent | 12872b3d2956a26fb7d1cd464b3672ebe40d94c1 (diff) | |
| download | aichat-638bf3276613265da761b4d74f269fa77c8f4bb1.tar.gz | |
refactor: improve code quatity (#604)
Diffstat (limited to 'src/function.rs')
| -rw-r--r-- | src/function.rs | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/function.rs b/src/function.rs index b2833e8..bab8ca9 100644 --- a/src/function.rs +++ b/src/function.rs @@ -16,13 +16,10 @@ use std::{ }; pub const SELECTED_ALL_FUNCTIONS: &str = ".*"; -pub type ToolResults = (Vec<ToolCallResult>, String); +pub type ToolResults = (Vec<ToolResult>, String); pub type FunctionsFilter = String; -pub fn eval_tool_calls( - config: &GlobalConfig, - mut calls: Vec<ToolCall>, -) -> Result<Vec<ToolCallResult>> { +pub fn eval_tool_calls(config: &GlobalConfig, mut calls: Vec<ToolCall>) -> Result<Vec<ToolResult>> { let mut output = vec![]; if calls.is_empty() { return Ok(output); @@ -33,22 +30,22 @@ pub fn eval_tool_calls( } for call in calls { let result = call.eval(config)?; - output.push(ToolCallResult::new(call, result)); + output.push(ToolResult::new(call, result)); } Ok(output) } -pub fn need_send_call_results(arr: &[ToolCallResult]) -> bool { +pub fn need_send_tool_results(arr: &[ToolResult]) -> bool { arr.iter().any(|v| !v.output.is_null()) } #[derive(Debug, Clone, Deserialize, Serialize)] -pub struct ToolCallResult { +pub struct ToolResult { pub call: ToolCall, pub output: Value, } -impl ToolCallResult { +impl ToolResult { pub fn new(call: ToolCall, output: Value) -> Self { Self { call, output } } |
