diff options
| author | sigoden <sigoden@gmail.com> | 2024-05-18 19:06:21 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-18 19:06:21 +0800 |
| commit | b4a40e3fedb438570770a224b890ea24f6e660a9 (patch) | |
| tree | 344b96102da7cbedf1034d023aa82599940388b1 /src/client/message.rs | |
| parent | 1348a62e5f8bc140a7218fbfe1b73f990ab16101 (diff) | |
| download | aichat-b4a40e3fedb438570770a224b890ea24f6e660a9.tar.gz | |
feat: support function calling (#514)
* feat: support function calling
* fix on Windows OS
* implement multi-steps function calling
* fix on Windows OS
* add error for client not support function calling
* refactor message data structure and make claude client supporting function calling
* support reuse previous call results
* improve error handling for function calling
* use prefix `may_` as indicator for `execute` type fucntions
Diffstat (limited to 'src/client/message.rs')
| -rw-r--r-- | src/client/message.rs | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/client/message.rs b/src/client/message.rs index 9621811..d7ba698 100644 --- a/src/client/message.rs +++ b/src/client/message.rs @@ -1,4 +1,4 @@ -use crate::config::Input; +use super::ToolResults; use serde::{Deserialize, Serialize}; @@ -8,15 +8,21 @@ pub struct Message { pub content: MessageContent, } -impl Message { - pub fn new(input: &Input) -> Self { +impl Default for Message { + fn default() -> Self { Self { role: MessageRole::User, - content: input.to_message_content(), + content: MessageContent::Text(String::new()), } } } +impl Message { + pub fn new(role: MessageRole, content: MessageContent) -> Self { + Self { role, content } + } +} + #[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize)] #[serde(rename_all = "snake_case")] pub enum MessageRole { @@ -34,10 +40,6 @@ impl MessageRole { pub fn is_user(&self) -> bool { matches!(self, MessageRole::User) } - - pub fn is_assistant(&self) -> bool { - matches!(self, MessageRole::Assistant) - } } #[derive(Debug, Clone, Deserialize, Serialize)] @@ -45,6 +47,8 @@ impl MessageRole { pub enum MessageContent { Text(String), Array(Vec<MessageContentPart>), + // Note: This type is primarily for convenience and does not exist in OpenAI's API. + ToolResults(ToolResults), } impl MessageContent { @@ -68,6 +72,7 @@ impl MessageContent { } format!(".file {}{}", files.join(" "), concated_text) } + MessageContent::ToolResults(_) => String::new(), } } @@ -83,6 +88,7 @@ impl MessageContent { *text = replace_fn(text) } } + MessageContent::ToolResults(_) => {} } } @@ -98,6 +104,7 @@ impl MessageContent { } parts.join("\n\n") } + MessageContent::ToolResults(_) => String::new(), } } } |
