Skip to content

Commit

Permalink
chore: derive clone and partialeq on builder
Browse files Browse the repository at this point in the history
  • Loading branch information
rellfy committed Aug 27, 2024
1 parent 25897c6 commit 56c2e77
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ pub enum ChatCompletionMessageRole {
}

#[derive(Serialize, Builder, Debug, Clone)]
#[builder(derive(Clone, Debug, PartialEq))]
#[builder(pattern = "owned")]
#[builder(name = "ChatCompletionBuilder")]
#[builder(setter(strip_option, into))]
Expand Down Expand Up @@ -211,7 +212,7 @@ pub struct ChatCompletionRequest {
response_format: Option<ChatCompletionResponseFormat>,
}

#[derive(Serialize, Debug, Clone)]
#[derive(Serialize, Debug, Clone, Eq, PartialEq)]
pub struct ChatCompletionResponseFormat {
/// Must be one of text or json_object (defaults to text)
#[serde(rename = "type")]
Expand Down Expand Up @@ -444,7 +445,6 @@ mod tests {
use super::*;
use crate::set_key;
use dotenvy::dotenv;
use reqwest::Response;
use std::env;

#[tokio::test]
Expand Down Expand Up @@ -663,6 +663,19 @@ mod tests {
);
}

#[test]
fn builder_clone_and_eq() {
let builder_a = ChatCompletion::builder("gpt-4", []).temperature(0.0).seed(65u64);
let builder_b = builder_a.clone();
let builder_c = builder_b.clone().temperature(1.0);
let builder_d = ChatCompletionBuilder::default();
assert_eq!(builder_a, builder_b);
assert_ne!(builder_a, builder_c);
assert_ne!(builder_b, builder_c);
assert_ne!(builder_a, builder_d);
assert_ne!(builder_c, builder_d);
}

async fn stream_to_completion(
mut chat_stream: Receiver<ChatCompletionDelta>,
) -> ChatCompletion {
Expand Down

0 comments on commit 56c2e77

Please sign in to comment.