Skip to content
This repository was archived by the owner on Jul 9, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl ChatGPT {
role: Role::User,
content: message.into(),
#[cfg(feature = "functions")]
function_call: None,
function_properties: None,
}],
stream: false,
temperature: self.config.temperature,
Expand Down Expand Up @@ -267,7 +267,7 @@ impl ChatGPT {
role: Role::User,
content: message.into(),
#[cfg(feature = "functions")]
function_call: None,
function_properties: None,
}],
stream: true,
temperature: self.config.temperature,
Expand Down Expand Up @@ -365,7 +365,7 @@ impl ChatGPT {
role: Role::User,
content: message.into(),
#[cfg(feature = "functions")]
function_call: None,
function_properties: None,
}],
stream: false,
temperature: self.config.temperature,
Expand Down
13 changes: 7 additions & 6 deletions src/converse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{
client::ChatGPT,
types::{ChatMessage, CompletionResponse, Role},
};
use crate::types::FunctionCallProperties;

/// Stores a single conversation session, and automatically saves message history
pub struct Conversation {
Expand All @@ -44,7 +45,7 @@ impl Conversation {
role: Role::System,
content: first_message,
#[cfg(feature = "functions")]
function_call: None,
function_properties: None,
}],
#[cfg(feature = "functions")]
functions: HashMap::with_capacity(4),
Expand Down Expand Up @@ -103,7 +104,7 @@ impl Conversation {
role,
content: message.into(),
#[cfg(feature = "functions")]
function_call: None,
function_properties: None,
});

#[cfg(feature = "functions")]
Expand Down Expand Up @@ -149,7 +150,7 @@ impl Conversation {
role: Role::User,
content: message.into(),
#[cfg(feature = "functions")]
function_call: None,
function_properties: None,
});
let resp = self
.client
Expand Down Expand Up @@ -184,7 +185,7 @@ impl Conversation {
role,
content: message.into(),
#[cfg(feature = "functions")]
function_call: None,
function_properties: None,
});
let stream = self.client.send_history_streaming(&self.history).await?;
Ok(stream)
Expand Down Expand Up @@ -244,8 +245,8 @@ impl Conversation {
&mut self,
message: &ChatMessage,
) -> Option<CompletionResponse> {
if let Some(call) = &message.function_call {
if let Some(Ok(result)) = self.process_function(call).await {
if let Some(FunctionCallProperties { function_call, .. }) = &message.function_properties {
if let Some(Ok(result)) = self.process_function(function_call).await {
Some(result)
} else {
None
Expand Down
15 changes: 13 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,19 @@ pub struct ChatMessage {
pub content: String,
/// Function call (if present)
#[cfg(feature = "functions")]
#[serde(skip_serializing_if = "Option::is_none", flatten)]
pub function_properties: Option<FunctionCallProperties>,
}

/// Container for called function info
#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct FunctionCallProperties {
/// The actual function call
pub function_call: FunctionCall,
/// Name of the function called
#[serde(rename = "name")]
#[serde(skip_serializing_if = "Option::is_none")]
pub function_call: Option<FunctionCall>,
pub function_name: Option<String>
}

fn deserialize_maybe_null<'de, D>(deserializer: D) -> Result<String, D::Error>
Expand Down Expand Up @@ -63,7 +74,7 @@ impl ChatMessage {
role,
content: String::new(),
#[cfg(feature = "functions")]
function_call: None,
function_properties: None,
};
result.push(msg);
}
Expand Down