Skip to content

Commit

Permalink
Merge pull request #39 from rellfy/derives
Browse files Browse the repository at this point in the history
add Eq, PartialEq to ChatCompletionMessageRole
  • Loading branch information
rellfy authored Aug 27, 2024
2 parents 09f20ea + e6da0a4 commit 52e572c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub type ChatCompletion = ChatCompletionGeneric<ChatCompletionChoice>;
/// A delta chat completion, which is streamed token by token.
pub type ChatCompletionDelta = ChatCompletionGeneric<ChatCompletionChoiceDelta>;

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Clone, Debug, Eq, PartialEq)]
pub struct ChatCompletionGeneric<C> {
pub id: String,
pub object: String,
Expand All @@ -27,21 +27,21 @@ pub struct ChatCompletionGeneric<C> {
pub usage: Option<Usage>,
}

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Clone, Debug, Eq, PartialEq)]
pub struct ChatCompletionChoice {
pub index: u64,
pub finish_reason: String,
pub message: ChatCompletionMessage,
}

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Clone, Debug, Eq, PartialEq)]
pub struct ChatCompletionChoiceDelta {
pub index: u64,
pub finish_reason: Option<String>,
pub delta: ChatCompletionMessageDelta,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
#[derive(Deserialize, Serialize, Debug, Clone, Eq, PartialEq)]
pub struct ChatCompletionMessage {
/// The role of the author of this message.
pub role: ChatCompletionMessageRole,
Expand All @@ -61,7 +61,7 @@ pub struct ChatCompletionMessage {
}

/// Same as ChatCompletionMessage, but received during a response stream.
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Clone, Debug, Eq, PartialEq)]
pub struct ChatCompletionMessageDelta {
/// The role of the author of this message.
pub role: Option<ChatCompletionMessageRole>,
Expand All @@ -77,7 +77,7 @@ pub struct ChatCompletionMessageDelta {
pub function_call: Option<ChatCompletionFunctionCallDelta>,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
#[derive(Deserialize, Serialize, Debug, Clone, Eq, PartialEq)]
pub struct ChatCompletionFunctionDefinition {
/// The name of the function
pub name: String,
Expand Down Expand Up @@ -110,7 +110,7 @@ pub struct ChatCompletionFunctionCallDelta {
pub arguments: Option<String>,
}

#[derive(Deserialize, Serialize, Debug, Clone, Copy)]
#[derive(Deserialize, Serialize, Debug, Clone, Copy, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum ChatCompletionMessageRole {
System,
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub mod moderations;
static API_KEY: Mutex<String> = Mutex::new(String::new());
static BASE_URL: Mutex<String> = Mutex::new(String::new());

#[derive(Deserialize, Debug, Clone)]
#[derive(Deserialize, Debug, Clone, Eq, PartialEq)]
pub struct OpenAiError {
pub message: String,
#[serde(rename = "type")]
Expand Down Expand Up @@ -51,7 +51,7 @@ pub enum ApiResponse<T> {
Ok(T),
}

#[derive(Deserialize, Clone, Copy, Debug)]
#[derive(Deserialize, Clone, Copy, Debug, Eq, PartialEq)]
pub struct Usage {
pub prompt_tokens: u32,
pub completion_tokens: u32,
Expand Down

0 comments on commit 52e572c

Please sign in to comment.