Crates.io | chat_messages |
lib.rs | chat_messages |
version | 0.1.0 |
source | src |
created_at | 2024-09-08 19:48:38.857649 |
updated_at | 2024-09-08 19:48:38.857649 |
description | chat_messages is a lightweight Rust library for creating structured messages in chat systems, including HumanMessage, AiMessage, SystemMessage, and more. It supports easy extensibility through macros, Serde-based serialization, and customizable fields, making it ideal for chatbots, AI agents, and messaging platforms. |
homepage | |
repository | https://github.com/kinghuynh/chat_messages.git |
max_upload_size | |
id | 1368492 |
size | 37,826 |
ChatMessages is a Rust library designed to facilitate the creation and management of structured messages for chat-based systems. This library is inspired by and ports the core message functionalities from the LangChain Messages library into Rust, providing an efficient way to build conversational agents, chatbots, and messaging platforms in Rust.
chat_messages
brings core concepts from LangChain's message system to Rust, allowing seamless integration for developers familiar with LangChain.AiMessage
, HumanMessage
, SystemMessage
, ChatMessage
, and ToolMessage
.BaseMessage
derive macro.To start using chat_messages
in your project, add the following to your Cargo.toml
:
[dependencies]
chat_messages = "0.1.0"
Here's a quick guide on how to use the various message types supported by the library.
The HumanMessage
type represents a message sent by a human user.
use chat_messages::{HumanMessage, BaseMessage};
fn main() {
let human_msg = HumanMessage::new("Hello, how can I help you?", false);
// Access the message content
println!("Message content: {}", human_msg.content());
// Check the message type
assert_eq!(human_msg.message_type(), MessageType::Human);
// Access additional metadata
assert_eq!(human_msg.is_example(), false);
}
The AiMessage
type represents a message generated by an AI or system.
use chat_messages::{AiMessage, BaseMessage};
fn main() {
let ai_msg = AiMessage::new("I am here to assist you.", false);
// Access the message content
println!("AI Message content: {}", ai_msg.content());
// Check the message type
assert_eq!(ai_msg.message_type(), MessageType::Ai);
}
The SystemMessage
type represents messages originating from a system or backend process.
use chat_messages::{SystemMessage, BaseMessage};
fn main() {
let system_msg = SystemMessage::new("System is being rebooted.", false);
// Access the message content
println!("System Message content: {}", system_msg.content());
// Check the message type
assert_eq!(system_msg.message_type(), MessageType::System);
}
The ChatMessage
type represents a general chat message, where the role of the speaker can be arbitrary (e.g., a user, bot, or system).
use chat_messages::{ChatMessage, BaseMessage};
fn main() {
let chat_msg = ChatMessage::new("How are you today?", "user".to_string());
// Access the message content
println!("Chat Message content: {}", chat_msg.content());
// Check the message type
assert_eq!(chat_msg.message_type(), MessageType::Chat);
// Access the role
println!("Role: {}", chat_msg.role);
}
The ToolMessage
type represents the result of a tool invocation or external process.
use chat_messages::{ToolMessage, BaseMessage};
fn main() {
let tool_msg = ToolMessage::new("Tool executed successfully.", "tool_123".to_string());
// Access the message content
println!("Tool Message content: {}", tool_msg.content());
// Check the message type
assert_eq!(tool_msg.message_type(), MessageType::Tool);
// Access the tool call ID
println!("Tool Call ID: {}", tool_msg.tool_call_id);
}
We welcome contributions from the community! If you're interested in contributing to chat_messages
, please follow these steps:
git clone https://github.com/yourusername/chat_messages.git
cd chat_messages
git checkout -b feature/your-feature-name
cargo test
This project is licensed under the MIT License. See the LICENSE file for details.
chat_messages
is based on the core messaging concepts from the LangChain Messages library. Special thanks to the LangChain team for providing the original inspiration and structure for this library.
If you have any questions or need further assistance, feel free to open an issue or contact us via GitHub.
chat_messages
!