pub struct Message {
pub role: Role,
pub content: Content,
pub function_call: Option<FunctionCall>,
}Fields§
§role: Role§content: Content§function_call: Option<FunctionCall>Optional function call payload when assistant invokes a tool
Implementations§
Source§impl Message
impl Message
Sourcepub fn new(role: Role, content: impl Into<Content>) -> Self
pub fn new(role: Role, content: impl Into<Content>) -> Self
Create a new message with the specified role and content.
Sourcepub fn user<S: Into<String>>(text: S) -> Self
pub fn user<S: Into<String>>(text: S) -> Self
Create a user message with text content.
§Example
use ai_lib::prelude::*;
let msg = Message::user("Hello, how are you?");
assert!(matches!(msg.role, Role::User));Sourcepub fn assistant<S: Into<String>>(text: S) -> Self
pub fn assistant<S: Into<String>>(text: S) -> Self
Create an assistant message with text content.
§Example
use ai_lib::prelude::*;
let msg = Message::assistant("I'm doing well, thank you!");
assert!(matches!(msg.role, Role::Assistant));Sourcepub fn system<S: Into<String>>(text: S) -> Self
pub fn system<S: Into<String>>(text: S) -> Self
Create a system message with text content.
§Example
use ai_lib::prelude::*;
let msg = Message::system("You are a helpful assistant.");
assert!(matches!(msg.role, Role::System));Sourcepub fn user_with_content(content: Content) -> Self
pub fn user_with_content(content: Content) -> Self
Create a user message with custom content (text, image, audio, etc.).
§Example
use ai_lib::prelude::*;
let msg = Message::user_with_content(Content::from_image_file("photo.jpg"));Sourcepub fn assistant_with_function_call(
text: impl Into<String>,
function_call: FunctionCall,
) -> Self
pub fn assistant_with_function_call( text: impl Into<String>, function_call: FunctionCall, ) -> Self
Create an assistant message with a function call.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnwindSafe for Message
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)