diff options
| author | sigoden <sigoden@gmail.com> | 2024-11-14 08:14:32 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-14 08:14:32 +0800 |
| commit | 80684ec84047bda0299f8fd845b1c97f6fac5c99 (patch) | |
| tree | f37e377accd664d31a2bfe977521cfc2157a9cd1 /src/config/mod.rs | |
| parent | cfa9217422dfa6cf10bed6e6e3fab0722f58588d (diff) | |
| download | aichat-80684ec84047bda0299f8fd845b1c97f6fac5c99.tar.gz | |
refactor: improve tool calls (#995)
- rename MessageContent:ToolResults to MessageContent:ToolCalls
- rename ToolResults to MessageContentToolCalls
- persist tool_calls to messages.md
Diffstat (limited to 'src/config/mod.rs')
| -rw-r--r-- | src/config/mod.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs index 9da8dae..136fee1 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -10,7 +10,7 @@ use self::session::Session; use crate::client::{ create_client_config, list_chat_models, list_client_types, list_reranker_models, ClientConfig, - Model, OPENAI_COMPATIBLE_PLATFORMS, + MessageContentToolCalls, Model, OPENAI_COMPATIBLE_PLATFORMS, }; use crate::function::{FunctionDeclaration, Functions, ToolResult}; use crate::rag::Rag; @@ -1863,8 +1863,22 @@ impl Config { } else { String::new() }; + let tool_calls = match input.tool_calls() { + Some(MessageContentToolCalls { + tool_results, text, .. + }) => { + let mut lines = vec!["<tool_calls>".to_string()]; + if !text.is_empty() { + lines.push(text.clone()); + } + lines.push(serde_json::to_string(&tool_results).unwrap_or_default()); + lines.push("</tool_calls>\n".to_string()); + lines.join("\n") + } + None => String::new(), + }; let output = format!( - "# CHAT: {summary} [{timestamp}]{scope}\n{raw_input}\n--------\n{output}\n--------\n\n", + "# CHAT: {summary} [{timestamp}]{scope}\n{raw_input}\n--------\n{tool_calls}{output}\n--------\n\n", ); file.write_all(output.as_bytes()) .with_context(|| "Failed to save message") |
