Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing From impl for ChatCompletionRequestMessage, replace trivial From impls with derive_more #319

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions async-openai/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ tokio-stream = "0.1.17"
tokio-util = { version = "0.7.13", features = ["codec", "io-util"] }
tracing = "0.1.41"
derive_builder = "0.20.2"
derive_more = { version = "1.0.0", features = ["from"] }
secrecy = { version = "0.10.3", features = ["serde"] }
bytes = "1.9.0"
eventsource-stream = "0.2.3"
Expand Down
3 changes: 2 additions & 1 deletion async-openai/src/types/chat.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{collections::HashMap, pin::Pin};

use derive_builder::Builder;
use derive_more::From;
use futures::Stream;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -376,7 +377,7 @@ pub struct ChatCompletionRequestFunctionMessage {
pub name: String,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, From)]
#[serde(tag = "role")]
#[serde(rename_all = "lowercase")]
pub enum ChatCompletionRequestMessage {
Expand Down
32 changes: 0 additions & 32 deletions async-openai/src/types/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,38 +539,6 @@ impl From<(String, serde_json::Value)> for ChatCompletionFunctions {
}
}

// todo: write macro for bunch of same looking From trait implementations below

impl From<ChatCompletionRequestUserMessage> for ChatCompletionRequestMessage {
fn from(value: ChatCompletionRequestUserMessage) -> Self {
Self::User(value)
}
}

impl From<ChatCompletionRequestSystemMessage> for ChatCompletionRequestMessage {
fn from(value: ChatCompletionRequestSystemMessage) -> Self {
Self::System(value)
}
}

impl From<ChatCompletionRequestAssistantMessage> for ChatCompletionRequestMessage {
fn from(value: ChatCompletionRequestAssistantMessage) -> Self {
Self::Assistant(value)
}
}

impl From<ChatCompletionRequestFunctionMessage> for ChatCompletionRequestMessage {
fn from(value: ChatCompletionRequestFunctionMessage) -> Self {
Self::Function(value)
}
}

impl From<ChatCompletionRequestToolMessage> for ChatCompletionRequestMessage {
fn from(value: ChatCompletionRequestToolMessage) -> Self {
Self::Tool(value)
}
}

impl From<ChatCompletionRequestUserMessageContent> for ChatCompletionRequestUserMessage {
fn from(value: ChatCompletionRequestUserMessageContent) -> Self {
Self {
Expand Down