pub enum Message {
System {
content: String,
metadata: HashMap<String, Value>,
},
User {
content: Content,
name: Option<String>,
metadata: HashMap<String, Value>,
},
Assistant {
content: Option<Content>,
tool_calls: Vec<ToolCall>,
metadata: HashMap<String, Value>,
},
Tool {
tool_call_id: String,
content: String,
metadata: HashMap<String, Value>,
},
}Expand description
Represents a message in a conversation
Variants§
System
Message from the system (instructions)
Fields
User
Message from the user
Fields
Assistant
Message from the assistant
Fields
Tool
Message from a tool
Implementations§
Source§impl Message
impl Message
Sourcepub fn system(content: impl Into<String>) -> Self
pub fn system(content: impl Into<String>) -> Self
Creates a new system message
§Examples
use language_barrier_core::message::Message;
let msg = Message::system("You are a helpful assistant.");Sourcepub fn user(content: impl Into<String>) -> Self
pub fn user(content: impl Into<String>) -> Self
Creates a new user message
§Examples
use language_barrier_core::message::Message;
let msg = Message::user("Hello, can you help me?");Sourcepub fn user_with_name(
name: impl Into<String>,
content: impl Into<String>,
) -> Self
pub fn user_with_name( name: impl Into<String>, content: impl Into<String>, ) -> Self
Creates a new user message with a name
§Examples
use language_barrier_core::message::Message;
let msg = Message::user_with_name("John", "Hello, can you help me?");Sourcepub fn user_with_parts(parts: Vec<ContentPart>) -> Self
pub fn user_with_parts(parts: Vec<ContentPart>) -> Self
Creates a new user message with multimodal content
§Examples
use language_barrier_core::message::{Message, Content, ContentPart};
let parts = vec![
ContentPart::text("Look at this image:"),
ContentPart::image_url("https://example.com/image.jpg"),
];
let msg = Message::user_with_parts(parts);Sourcepub fn assistant(content: impl Into<String>) -> Self
pub fn assistant(content: impl Into<String>) -> Self
Creates a new assistant message
§Examples
use language_barrier_core::message::Message;
let msg = Message::assistant("I'm here to help you.");Sourcepub fn assistant_with_tool_calls(tool_calls: Vec<ToolCall>) -> Self
pub fn assistant_with_tool_calls(tool_calls: Vec<ToolCall>) -> Self
Creates a new assistant message with tool calls
§Examples
use language_barrier_core::message::{Message, ToolCall, Function};
let tool_call = ToolCall {
id: "call_123".to_string(),
tool_type: "function".to_string(),
function: Function {
name: "get_weather".to_string(),
arguments: "{\"location\":\"San Francisco\"}".to_string(),
},
};
let msg = Message::assistant_with_tool_calls(vec![tool_call]);Sourcepub fn tool(tool_call_id: impl Into<String>, content: impl Into<String>) -> Self
pub fn tool(tool_call_id: impl Into<String>, content: impl Into<String>) -> Self
Creates a new tool message
§Examples
use language_barrier_core::message::Message;
let msg = Message::tool("tool123", "The result is 42.");Sourcepub fn tool_from_call(tool_call: &ToolCall, content: impl Into<String>) -> Self
pub fn tool_from_call(tool_call: &ToolCall, content: impl Into<String>) -> Self
Creates a new tool message from the tool call that originated it.
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
impl StructuralPartialEq for Message
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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more